Skip to content

Add DbDataSource Multiplexing support, add MySql DbDataSource support - #286

Merged
madelson merged 3 commits into
madelson:238-implementfrom
Hawxy:dbdatasource
Nov 21, 2026
Merged

madelson merged 3 commits into
madelson:238-implementfrom
Hawxy:dbdatasource

Conversation

@Hawxy

@Hawxy Hawxy commented Aug 25, 2026 •

Copy link
Copy Markdown

We'd find this useful for some scenarios in MartenDb as we can end up with a lot of monitored locks.

I ended up making the pooling logic generic and using separate pools as it seemed more elegant than just making an object puddle.

Also added DbDataSource to the MySQL constructor, no other vendors have DbDataSource support yet sadly.

Closes #238

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change has unresolved API-baseline, target-framework/documentation, and dependency-lock issues that can break release tracking or restore verification.

3 open issues
What changed in this PR

This PR adds DbDataSource support to connection multiplexing. Lock pools are now generic and can be keyed by a DbDataSource instance (by reference) as well as by connection string. It also adds DbDataSource constructors for MySQL, and the Postgres DbDataSource path now multiplexes instead of throwing. This addresses issue #238.

Changes:

  • Make MultiplexedConnectionLockPool and OptimisticConnectionMultiplexingDbDistributedLock generic over the connection source, so they work with a connection string or a DbDataSource.
  • Pool Postgres and MySQL DbDataSource connections by reference, using a separate pool instance per source type.
  • Add MySQL DbDataSource constructors for the lock and the synchronization provider, and add a net8.0 target with public API baselines.
  • Update the Postgres and MySQL docs and tests to cover the new behavior.
File Description
src/​DistributedLock.Tests/​Tests/​Postgres/​PostgresDistributedLockTest.cs Replaces the old "not supported" test with tests for shared multiplexing, reference keying, and handle-lost behavior.
src/​DistributedLock.Tests/​Tests/​MySql/​MySqlDistributedSynchronizationProviderTest.cs Adds a null-argument check for the new DbDataSource provider constructor.
src/​DistributedLock.Tests/​Tests/​MySql/​MySqlDistributedLockTest.cs Adds tests for the MySQL DbDataSource lock: shared connection, reference keying, and basic behavior.
src/​DistributedLock.SqlServer/​SqlMultiplexedConnectionLockPool.cs Updates the pool to the generic type with a string key.
src/​DistributedLock.SqlServer/​SqlDistributedLock.cs Uses the generic multiplexing lock with a string key.
src/​DistributedLock.Postgres/​PostgresMultiplexedConnectionLockPool.cs Adds a separate reference-keyed pool for DbDataSource connections.
src/​DistributedLock.Postgres/​PostgresDistributedSynchronizationProvider.cs Removes the "not compatible with multiplexing" note from the DbDataSource constructor docs.
src/​DistributedLock.Postgres/​PostgresDistributedReaderWriterLock.cs Removes the "not compatible with multiplexing" note from the DbDataSource constructor docs.
src/​DistributedLock.Postgres/​PostgresDistributedLock.cs Enables multiplexing for DbDataSource and removes the forced opt-out.
src/​DistributedLock.Oracle/​OracleMultiplexedConnectionLockPool.cs Updates the pool to the generic type with a string key.
src/​DistributedLock.Oracle/​OracleDistributedLock.cs Uses the generic multiplexing lock with a string key.
src/​DistributedLock.MySql/​PublicAPI/​net8.0/​PublicAPI.Unshipped.txt Added as an empty placeholder for unreleased public API entries.
src/​DistributedLock.MySql/​PublicAPI/​net8.0/​PublicAPI.Shipped.txt Lists the two new DbDataSource constructors (should be in Unshipped; see review comment).
src/​DistributedLock.MySql/​MySqlMultiplexedConnectionLockPool.cs Adds a reference-keyed pool for MySQL DbDataSource connections.
src/​DistributedLock.MySql/​MySqlDistributedSynchronizationProvider.cs Adds a DbDataSource constructor for the MySQL provider.
src/​DistributedLock.MySql/​MySqlDistributedLock.cs Adds a DbDataSource constructor and a lock-creation path that supports multiplexing.
src/​DistributedLock.MySql/​MySqlDatabaseConnection.cs Adds a connection constructor that creates the connection from a DbDataSource.
src/​DistributedLock.MySql/​DistributedLock.MySql.csproj Adds a net8.0 target and its public API files.
src/​DistributedLock.Core/​Internal/​Data/​OptimisticConnectionMultiplexingDbDistributedLock.cs Makes the multiplexing lock generic over the connection source.
src/​DistributedLock.Core/​Internal/​Data/​MultiplexedConnectionLockPool.cs Makes the pool generic and adds an optional equality comparer for keys.
docs/​DistributedLock.Postgres.md Notes that connections are multiplexed per DbDataSource instance.
docs/​DistributedLock.MySql.md Documents the new DbDataSource option (marked as .NET 7+; see review comment).

Review effort: Lite

@madelson madelson added this to the 2.9 milestone Nov 11, 2026
@madelson
madelson changed the base branch from master to 238-implement November 21, 2026 14:37
@madelson
madelson merged commit 54b1ce9 into madelson:238-implement Nov 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for connection multiplexing with DbDataSource

3 participants