|
19 | 19 |
|
20 | 20 | namespace Microsoft.Data.SqlClient.ConnectionPool
|
21 | 21 | {
|
| 22 | + /// <summary> |
| 23 | + /// A concrete implementation of <see cref="IDbConnectionPool"/> used by <c>Microsoft.Data.SqlClient</c> |
| 24 | + /// to efficiently manage a pool of reusable <see cref="DbConnectionInternal"/> objects backing ADO.NET <c>SqlConnection</c> instances. |
| 25 | + /// |
| 26 | + /// <para><b>Primary Responsibilities:</b></para> |
| 27 | + /// <list type="bullet"> |
| 28 | + /// <item><description><b>Connection Reuse and Pooling:</b> Uses two stacks (<c>_stackNew</c> and <c>_stackOld</c>) to manage idle connections. Ensures efficient reuse and limits new connection creation.</description></item> |
| 29 | + /// <item><description><b>Transaction-Aware Pooling:</b> Tracks connections enlisted in <see cref="System.Transactions.Transaction"/> using <c>TransactedConnectionPool</c> and <c>TransactedConnectionList</c>, ensuring proper context reuse.</description></item> |
| 30 | + /// <item><description><b>Concurrency and Synchronization:</b> Uses wait handles and semaphores via <c>PoolWaitHandles</c> to coordinate safe multi-threaded access.</description></item> |
| 31 | + /// <item><description><b>Connection Lifecycle Management:</b> Manages creation (<c>CreateObject</c>), deactivation (<c>DeactivateObject</c>), destruction (<c>DestroyObject</c>), and reclamation (<c>ReclaimEmancipatedObjects</c>) of internal connections.</description></item> |
| 32 | + /// <item><description><b>Error Handling and Resilience:</b> Implements retry and exponential backoff in <c>TryGetConnection</c> and handles transient errors using <c>_errorWait</c>.</description></item> |
| 33 | + /// <item><description><b>Minimum Pool Size Enforcement:</b> Maintains the <c>MinPoolSize</c> by spawning background tasks to create new connections when needed.</description></item> |
| 34 | + /// <item><description><b>Load Balancing Support:</b> Honors <c>LoadBalanceTimeout</c> to clean up idle connections and distribute load evenly.</description></item> |
| 35 | + /// <item><description><b>Telemetry and Tracing:</b> Uses <c>SqlClientEventSource</c> for extensive diagnostic tracing of connection lifecycle events.</description></item> |
| 36 | + /// <item><description><b>Pending Request Queue:</b> Queues unresolved connection requests in <c>_pendingOpens</c> and processes them using background threads.</description></item> |
| 37 | + /// <item><description><b>Identity and Authentication Context:</b> Manages identity-based reuse via a dictionary of <c>DbConnectionPoolAuthenticationContext</c> keyed by user identity.</description></item> |
| 38 | + /// </list> |
| 39 | + /// |
| 40 | + /// <para><b>Key Concepts in Design:</b></para> |
| 41 | + /// <list type="bullet"> |
| 42 | + /// <item><description>Stacks and queues for free and pending connections</description></item> |
| 43 | + /// <item><description>Synchronization via <c>WaitHandle</c>, <c>Semaphore</c>, and <c>ManualResetEvent</c></description></item> |
| 44 | + /// <item><description>Support for transaction enlistment and affinity</description></item> |
| 45 | + /// <item><description>Timer-based cleanup to prune idle or expired connections</description></item> |
| 46 | + /// <item><description>Background thread spawning for servicing deferred requests and replenishing the pool</description></item> |
| 47 | + /// </list> |
| 48 | + /// </summary> |
22 | 49 | internal sealed class WaitHandleDbConnectionPool : IDbConnectionPool
|
23 | 50 | {
|
24 | 51 |
|
|
0 commit comments