ChannelDbConnectionPool replace connection#4429
Draft
mdaigle wants to merge 12 commits into
Draft
Conversation
…cit method parameters.
Contributor
There was a problem hiding this comment.
Pull request overview
Implements connection replacement support for the channel-based connection pool, including a new slot-level atomic replace operation and expanded unit test coverage around replacement behavior.
Changes:
- Implement
ChannelDbConnectionPool.ReplaceConnection(...)and introduce internal replacement acquisition logic (idle-preferred, otherwise create new). - Add
ConnectionPoolSlots.TryReplace(...)to atomically swap a connection within an existing reserved slot. - Update/extend unit tests, including a new dedicated
ChannelDbConnectionPoolReplaceConnectionTestsuite and an updated existing replacement test.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/ConnectionPoolSlotsTest.cs | Adds new tests validating ConnectionPoolSlots.TryReplace behaviors. |
| src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/ChannelDbConnectionPoolTest.cs | Updates the existing replace-connection test to exercise the new implementation. |
| src/Microsoft.Data.SqlClient/tests/UnitTests/ConnectionPool/ChannelDbConnectionPoolReplaceConnectionTest.cs | Adds a new test file covering replacement scenarios (idle preference, capacity behavior, failure propagation). |
| src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/IDbConnectionPool.cs | Changes ReplaceConnection return type to nullable. |
| src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/ConnectionPoolSlots.cs | Adds TryReplace helper to atomically swap a connection in-place. |
| src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/ChannelDbConnectionPool.cs | Implements ReplaceConnection, adds replacement acquisition logic, and updates PrepareConnection to accept an optional transaction. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4429 +/- ##
==========================================
- Coverage 65.83% 64.07% -1.77%
==========================================
Files 287 282 -5
Lines 43763 66706 +22943
==========================================
+ Hits 28812 42741 +13929
- Misses 14951 23965 +9014
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Comment on lines
+276
to
+282
| if (!replaced) | ||
| { | ||
| // This should never happen because oldConnection is checked out and its slot is stable. | ||
| // Still, we need to check or we could vend a connection that is not tracked by the pool. | ||
| // TODO: error types and localization | ||
| throw new InvalidOperationException("Connection is no longer in the pool and cannot be replaced."); | ||
| } |
Comment on lines
+316
to
+321
| /// <summary> | ||
| /// Verifies that when activating the replacement connection fails, the newly created | ||
| /// connection is returned to the pool rather than leaked, keeping the pool count stable. | ||
| /// </summary> | ||
| [Fact] | ||
| public void ReplaceConnection_ActivationFails_NewConnectionReturnedToPool() |
Comment on lines
+354
to
+357
| // Assert — the new connection was returned to pool (not leaked). | ||
| // Pool count stays same because the new connection replaced the old one's slot | ||
| // and was then returned to idle. | ||
| Assert.Equal(countBefore, pool.Count); |
Comment on lines
+364
to
+365
| // NOTE: Preferring an idle connection over a new physical one is being added in a follow-up PR | ||
| // (branch dev/automation/replace-conn-idle-path), along with its ReplaceConnection_PrefersIdleOverNewConnection test. |
Comment on lines
704
to
706
| [Fact] | ||
| public void TestReplaceConnection() | ||
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Provide a summary of the changes being introduced. Important topics to cover
include:
High quality descriptions will lead to a smoother review experience.
Issues
Link to any relevant issues, bugs, or discussions (e.g.,
Closes #123,Fixes issue #456).Testing
Describe the automated tests (unit, integration) you created or modified.
Provide justification for any gap in automated testing. List any manual testing
steps that were performed to ensure the changes work.
Guidelines
Please review the contribution guidelines before submitting a pull request: