From eb423fd4b816891135ac41f85279957cda022385 Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Tue, 4 Mar 2025 11:49:17 -0800 Subject: [PATCH 1/9] Add abstract class to define pool interface. --- .../src/Microsoft.Data.SqlClient.csproj | 3 + .../netfx/src/Microsoft.Data.SqlClient.csproj | 3 + .../Data/ProviderBase/DbConnectionPool.cs | 57 ++++----- .../Data/ProviderBase/IDbConnectionPool.cs | 110 ++++++++++++++++++ 4 files changed, 139 insertions(+), 34 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index d2bdc92c05..ac4e16afb0 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -77,6 +77,9 @@ Microsoft\Data\ProviderBase\DbConnectionFactory.cs + + Microsoft\Data\ProviderBase\IDbConnectionPool.cs + Microsoft\Data\ProviderBase\DbConnectionPool.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 10fb3ae21c..0d3eaa4b2e 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -265,6 +265,9 @@ Microsoft\Data\ProviderBase\DbConnectionInternal.cs + + Microsoft\Data\ProviderBase\IDbConnectionPool.cs + Microsoft\Data\ProviderBase\DbConnectionPool.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs index 8a41b3d428..810a0ad385 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs @@ -20,7 +20,7 @@ namespace Microsoft.Data.ProviderBase { - internal sealed class DbConnectionPool + internal sealed class DbConnectionPool : IDbConnectionPool { private enum State { @@ -418,9 +418,6 @@ internal WaitHandle[] GetHandles(bool withCreate) private readonly List _objectList; private int _totalObjects; - private static int _objectTypeCount; // EventSource counter - internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); - // only created by DbConnectionPoolGroup.GetConnectionPool internal DbConnectionPool( DbConnectionFactory connectionFactory, @@ -474,17 +471,17 @@ private int CreationTimeout get { return PoolGroupOptions.CreationTimeout; } } - internal int Count + internal override int Count { get { return _totalObjects; } } - internal DbConnectionFactory ConnectionFactory + internal override DbConnectionFactory ConnectionFactory { get { return _connectionFactory; } } - internal bool ErrorOccurred + internal override bool ErrorOccurred { get { return _errorOccurred; } } @@ -494,7 +491,7 @@ private bool HasTransactionAffinity get { return PoolGroupOptions.HasTransactionAffinity; } } - internal TimeSpan LoadBalanceTimeout + internal override TimeSpan LoadBalanceTimeout { get { return PoolGroupOptions.LoadBalanceTimeout; } } @@ -522,12 +519,12 @@ private bool NeedToReplenish } } - internal DbConnectionPoolIdentity Identity + internal override DbConnectionPoolIdentity Identity { get { return _identity; } } - internal bool IsRunning + internal override bool IsRunning { get { return State.Running == _state; } } @@ -542,32 +539,24 @@ private int MinPoolSize get { return PoolGroupOptions.MinPoolSize; } } - internal int ObjectID - { - get - { - return _objectID; - } - } - #if NETFRAMEWORK - internal DbConnectionPoolCounters PerformanceCounters + internal override DbConnectionPoolCounters PerformanceCounters { get { return _connectionFactory.PerformanceCounters; } } #endif - internal DbConnectionPoolGroup PoolGroup + internal override DbConnectionPoolGroup PoolGroup { get { return _connectionPoolGroup; } } - internal DbConnectionPoolGroupOptions PoolGroupOptions + internal override DbConnectionPoolGroupOptions PoolGroupOptions { get { return _connectionPoolGroupOptions; } } - internal DbConnectionPoolProviderInfo ProviderInfo + internal override DbConnectionPoolProviderInfo ProviderInfo { get { return _connectionPoolProviderInfo; } } @@ -575,7 +564,7 @@ internal DbConnectionPoolProviderInfo ProviderInfo /// /// Return the pooled authentication contexts. /// - internal ConcurrentDictionary AuthenticationContexts + internal override ConcurrentDictionary AuthenticationContexts { get { @@ -583,7 +572,7 @@ internal ConcurrentDictionary {0}, Clearing.", ObjectID); DbConnectionInternal obj; @@ -1039,7 +1028,7 @@ private void DeactivateObject(DbConnectionInternal obj) Debug.Assert(rootTxn == true || returnToGeneralPool == true || destroyObject == true); } - internal void DestroyObject(DbConnectionInternal obj) + internal override void DestroyObject(DbConnectionInternal obj) { // A connection with a delegated transaction cannot be disposed of // until the delegated transaction has actually completed. Instead, @@ -1234,7 +1223,7 @@ private void WaitForPendingOpen() } while (_pendingOpens.TryPeek(out next)); } - internal bool TryGetConnection(DbConnection owningObject, TaskCompletionSource retry, DbConnectionOptions userOptions, out DbConnectionInternal connection) + internal override bool TryGetConnection(DbConnection owningObject, TaskCompletionSource retry, DbConnectionOptions userOptions, out DbConnectionInternal connection) { uint waitForMultipleObjectsTimeout = 0; bool allowCreate = false; @@ -1516,7 +1505,7 @@ private void PrepareConnection(DbConnection owningObject, DbConnectionInternal o /// Options used to create the new connection /// Inner connection that will be replaced /// A new inner connection that is attached to the - internal DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) + internal override DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) { #if NETFRAMEWORK PerformanceCounters.SoftConnectsPerSecond.Increment(); @@ -1752,7 +1741,7 @@ private void PoolCreateRequest(object state) } } - internal void PutNewObject(DbConnectionInternal obj) + internal override void PutNewObject(DbConnectionInternal obj) { Debug.Assert(obj != null, "why are we adding a null object to the pool?"); @@ -1768,7 +1757,7 @@ internal void PutNewObject(DbConnectionInternal obj) } - internal void PutObject(DbConnectionInternal obj, object owningObject) + internal override void PutObject(DbConnectionInternal obj, object owningObject) { Debug.Assert(obj != null, "null obj?"); @@ -1800,7 +1789,7 @@ internal void PutObject(DbConnectionInternal obj, object owningObject) DeactivateObject(obj); } - internal void PutObjectFromTransactedPool(DbConnectionInternal obj) + internal override void PutObjectFromTransactedPool(DbConnectionInternal obj) { Debug.Assert(obj != null, "null pooledObject?"); Debug.Assert(obj.EnlistedTransaction == null, "pooledObject is still enlisted?"); @@ -1907,7 +1896,7 @@ private bool ReclaimEmancipatedObjects() return emancipatedObjectFound; } - internal void Startup() + internal override void Startup() { SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, CleanupWait={1}", ObjectID, _cleanupWait); _cleanupTimer = CreateCleanupTimer(); @@ -1918,7 +1907,7 @@ internal void Startup() } } - internal void Shutdown() + internal override void Shutdown() { SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}", ObjectID); _state = State.ShuttingDown; @@ -1936,7 +1925,7 @@ internal void Shutdown() // that is implemented inside DbConnectionPool. This method's counterpart (PutTransactedObject) should // only be called from DbConnectionPool.DeactivateObject and thus the plumbing to provide access to // other objects is unnecessary (hence the asymmetry of Ended but no Begin) - internal void TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject) + internal override void TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject) { Debug.Assert(transaction != null, "null transaction?"); Debug.Assert(transactedObject != null, "null transactedObject?"); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs new file mode 100644 index 0000000000..e5002f949d --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs @@ -0,0 +1,110 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Collections.Concurrent; +using System.Data.Common; +using System.Threading.Tasks; +using System.Transactions; +using Microsoft.Data.Common; + +namespace Microsoft.Data.ProviderBase +{ + internal abstract class IDbConnectionPool + { + private static int _objectTypeCount; // EventSource counter + internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); + + internal int ObjectID + { + get + { + return _objectID; + } + } + + internal abstract int Count + { + get; + } + + internal abstract DbConnectionFactory ConnectionFactory + { + get; + } + + internal abstract bool ErrorOccurred + { + get; + } + + internal abstract TimeSpan LoadBalanceTimeout + { + get; + } + + internal abstract DbConnectionPoolIdentity Identity + { + get; + } + + internal abstract bool IsRunning + { + get; + } + +#if NETFRAMEWORK + internal abstract DbConnectionPoolCounters PerformanceCounters + { + get; + } +#endif + internal abstract DbConnectionPoolGroup PoolGroup + { + get; + } + + internal abstract DbConnectionPoolGroupOptions PoolGroupOptions + { + get; + } + + internal abstract DbConnectionPoolProviderInfo ProviderInfo + { + get; + } + + internal abstract ConcurrentDictionary AuthenticationContexts + { + get; + } + + internal abstract bool UseLoadBalancing + { + get; + } + + internal abstract void Clear(); + + internal abstract void DestroyObject(DbConnectionInternal obj); + + internal abstract bool TryGetConnection(DbConnection owningObject, TaskCompletionSource retry, DbConnectionOptions userOptions, out DbConnectionInternal connection); + + internal abstract DbConnectionInternal ReplaceConnection(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection); + + internal abstract void PutNewObject(DbConnectionInternal obj); + + internal abstract void PutObject(DbConnectionInternal obj, object owningObject); + + internal abstract void PutObjectFromTransactedPool(DbConnectionInternal obj); + + internal abstract void Startup(); + + internal abstract void Shutdown(); + + internal abstract void TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject); + + + } +} From 306efa56fac111e8e6ce0be644c6d54fc3e78706 Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Tue, 4 Mar 2025 13:32:47 -0800 Subject: [PATCH 2/9] Code cleanup --- .../Data/ProviderBase/DbConnectionPool.cs | 26 +++++++++---------- .../Data/ProviderBase/IDbConnectionPool.cs | 6 +++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs index 810a0ad385..1f8e61e7cc 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs @@ -9,8 +9,6 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -using System.Runtime.ConstrainedExecution; -using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -362,17 +360,17 @@ internal WaitHandle[] GetHandles(bool withCreate) } } - private const int MAX_Q_SIZE = (int)0x00100000; + private const int MAX_Q_SIZE = 0x00100000; // The order of these is important; we want the WaitAny call to be signaled // for a free object before a creation signal. Only the index first signaled // object is returned from the WaitAny call. - private const int SEMAPHORE_HANDLE = (int)0x0; - private const int ERROR_HANDLE = (int)0x1; - private const int CREATION_HANDLE = (int)0x2; - private const int BOGUS_HANDLE = (int)0x3; + private const int SEMAPHORE_HANDLE = 0x0; + private const int ERROR_HANDLE = 0x1; + private const int CREATION_HANDLE = 0x2; + private const int BOGUS_HANDLE = 0x3; - private const int WAIT_ABANDONED = (int)0x80; + private const int WAIT_ABANDONED = 0x80; private const int ERROR_WAIT_DEFAULT = 5 * 1000; // 5 seconds @@ -511,7 +509,7 @@ private bool NeedToReplenish if (totalObjects < MinPoolSize) return true; - int freeObjects = (_stackNew.Count + _stackOld.Count); + int freeObjects = _stackNew.Count + _stackOld.Count; int waitingRequests = _waitCount; bool needToReplenish = (freeObjects < waitingRequests) || ((freeObjects == waitingRequests) && (totalObjects > 1)); @@ -606,7 +604,7 @@ private void CleanupCallback(object state) // Destroy free objects that put us above MinPoolSize from old stack. while (Count > MinPoolSize) - { + { // While above MinPoolSize... if (_waitHandles.PoolSemaphore.WaitOne(0, false)) { @@ -1429,17 +1427,17 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj } break; - case (WAIT_ABANDONED + SEMAPHORE_HANDLE): + case WAIT_ABANDONED + SEMAPHORE_HANDLE: SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Semaphore handle abandonded.", ObjectID); Interlocked.Decrement(ref _waitCount); throw new AbandonedMutexException(SEMAPHORE_HANDLE, _waitHandles.PoolSemaphore); - case (WAIT_ABANDONED + ERROR_HANDLE): + case WAIT_ABANDONED + ERROR_HANDLE: SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Error handle abandonded.", ObjectID); Interlocked.Decrement(ref _waitCount); throw new AbandonedMutexException(ERROR_HANDLE, _waitHandles.ErrorEvent); - case (WAIT_ABANDONED + CREATION_HANDLE): + case WAIT_ABANDONED + CREATION_HANDLE: SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Creation handle abandoned.", ObjectID); Interlocked.Decrement(ref _waitCount); throw new AbandonedMutexException(CREATION_HANDLE, _waitHandles.CreationSemaphore); @@ -1561,7 +1559,7 @@ private DbConnectionInternal GetFromGeneralPool() PerformanceCounters.NumberOfFreeConnections.Decrement(); #endif } - return (obj); + return obj; } private DbConnectionInternal GetFromTransactedPool(out Transaction transaction) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs index e5002f949d..d335b92689 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs @@ -24,6 +24,7 @@ internal int ObjectID } } + #region Abstract Properties internal abstract int Count { get; @@ -84,7 +85,9 @@ internal abstract bool UseLoadBalancing { get; } + #endregion + #region Abstract Methods internal abstract void Clear(); internal abstract void DestroyObject(DbConnectionInternal obj); @@ -104,7 +107,6 @@ internal abstract bool UseLoadBalancing internal abstract void Shutdown(); internal abstract void TransactionEnded(Transaction transaction, DbConnectionInternal transactedObject); - - + #endregion } } From e2b96155d1cb2867dc55ec7e32c49051e03e5948 Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Tue, 4 Mar 2025 14:59:01 -0800 Subject: [PATCH 3/9] Refactoring pool state and cross-instance access. --- .../src/Microsoft.Data.SqlClient.csproj | 3 ++ .../netfx/src/Microsoft.Data.SqlClient.csproj | 3 ++ .../Data/ProviderBase/DbConnectionPool.cs | 50 ++++++------------- .../ProviderBase/DbConnectionPoolGroup.cs | 2 +- .../ProviderBase/DbConnectionPoolState.cs | 13 +++++ .../Data/ProviderBase/IDbConnectionPool.cs | 9 +++- 6 files changed, 42 insertions(+), 38 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolState.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index ac4e16afb0..7438ee903e 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -83,6 +83,9 @@ Microsoft\Data\ProviderBase\DbConnectionPool.cs + + Microsoft\Data\ProviderBase\DbConnectionPoolState.cs + Microsoft\Data\ProviderBase\DbConnectionInternal.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 0d3eaa4b2e..2d0f4fe50a 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -271,6 +271,9 @@ Microsoft\Data\ProviderBase\DbConnectionPool.cs + + Microsoft\Data\ProviderBase\DbConnectionPoolState.cs + Microsoft\Data\ProviderBase\DbConnectionPoolAuthenticationContext.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs index 1f8e61e7cc..fe78d13ea7 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs @@ -15,18 +15,12 @@ using System.Transactions; using Microsoft.Data.Common; using Microsoft.Data.SqlClient; +using static Microsoft.Data.ProviderBase.DbConnectionPoolState; namespace Microsoft.Data.ProviderBase { - internal sealed class DbConnectionPool : IDbConnectionPool + internal sealed class WaitHandleDbConnectionPool : DbConnectionPool { - private enum State - { - Initializing, - Running, - ShuttingDown, - } - // This class is a way to stash our cloned Tx key for later disposal when it's no longer needed. // We can't get at the key in the dictionary without enumerating entries, so we stash an extra // copy as part of the value. @@ -390,8 +384,6 @@ internal WaitHandle[] GetHandles(bool withCreate) /// private readonly ConcurrentDictionary _pooledDbAuthenticationContexts; - private State _state; - private readonly ConcurrentStack _stackOld = new ConcurrentStack(); private readonly ConcurrentStack _stackNew = new ConcurrentStack(); @@ -417,7 +409,7 @@ internal WaitHandle[] GetHandles(bool withCreate) private int _totalObjects; // only created by DbConnectionPoolGroup.GetConnectionPool - internal DbConnectionPool( + internal WaitHandleDbConnectionPool( DbConnectionFactory connectionFactory, DbConnectionPoolGroup connectionPoolGroup, DbConnectionPoolIdentity identity, @@ -430,7 +422,7 @@ internal DbConnectionPool( throw ADP.InternalError(ADP.InternalErrorCode.AttemptingToPoolOnRestrictedToken); } - _state = State.Initializing; + State = Initializing; lock (s_random) { @@ -457,7 +449,7 @@ internal DbConnectionPool( _transactedConnectionPool = new TransactedConnectionPool(this); _poolCreateRequest = new WaitCallback(PoolCreateRequest); // used by CleanupCallback - _state = State.Running; + State = Running; SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Constructed.", ObjectID); //_cleanupTimer & QueuePoolCreateRequest is delayed until DbConnectionPoolGroup calls @@ -498,7 +490,7 @@ private bool NeedToReplenish { get { - if (State.Running != _state) // Don't allow connection create when not running. + if (State != Running) // Don't allow connection create when not running. return false; int totalObjects = Count; @@ -524,7 +516,7 @@ internal override DbConnectionPoolIdentity Identity internal override bool IsRunning { - get { return State.Running == _state; } + get { return State == Running; } } private int MaxPoolSize @@ -812,20 +804,6 @@ private DbConnectionInternal CreateObject(DbConnection owningObject, DbConnectio #endif } - // If the old connection belonged to another pool, we need to remove it from that - if (oldConnection != null) - { - var oldConnectionPool = oldConnection.Pool; - if (oldConnectionPool != null && oldConnectionPool != this) - { - Debug.Assert(oldConnectionPool._state == State.ShuttingDown, "Old connections pool should be shutting down"); - lock (oldConnectionPool._objectList) - { - oldConnectionPool._objectList.Remove(oldConnection); - oldConnectionPool._totalObjects = oldConnectionPool._objectList.Count; - } - } - } SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Added to pool.", ObjectID, newObj?.ObjectID); // Reset the error wait: @@ -913,7 +891,7 @@ private void DeactivateObject(DbConnectionInternal obj) { // NOTE: constructor should ensure that current state cannot be State.Initializing, so it can only // be State.Running or State.ShuttingDown - Debug.Assert(_state == State.Running || _state == State.ShuttingDown); + Debug.Assert(State == Running || State == ShuttingDown); lock (obj) { @@ -923,7 +901,7 @@ private void DeactivateObject(DbConnectionInternal obj) // transaction object will ensure that it is owned (not lost), // and it will be certain to put it back into the pool. - if (_state == State.ShuttingDown) + if (State == ShuttingDown) { if (obj.IsTransactionRoot) { @@ -1237,7 +1215,7 @@ internal override bool TryGetConnection(DbConnection owningObject, TaskCompletio allowCreate = true; } - if (_state != State.Running) + if (State != Running) { SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, DbConnectionInternal State != Running.", ObjectID); connection = null; @@ -1615,7 +1593,7 @@ private void PoolCreateRequest(object state) long scopeID = SqlClientEventSource.Log.TryPoolerScopeEnterEvent(" {0}", ObjectID); try { - if (State.Running == _state) + if (State == Running) { // in case WaitForPendingOpen ever failed with no subsequent OpenAsync calls, // start it back up again @@ -1804,7 +1782,7 @@ internal override void PutObjectFromTransactedPool(DbConnectionInternal obj) // done and all transactions are ended. SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Transaction has ended.", ObjectID, obj.ObjectID); - if (_state == State.Running && obj.CanBePooled) + if (State == Running && obj.CanBePooled) { PutNewObject(obj); } @@ -1817,7 +1795,7 @@ internal override void PutObjectFromTransactedPool(DbConnectionInternal obj) private void QueuePoolCreateRequest() { - if (State.Running == _state) + if (State == Running) { // Make sure we're at quota by posting a callback to the threadpool. ThreadPool.QueueUserWorkItem(_poolCreateRequest); @@ -1908,7 +1886,7 @@ internal override void Startup() internal override void Shutdown() { SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}", ObjectID); - _state = State.ShuttingDown; + State = ShuttingDown; // deactivate timer callbacks Timer t = _cleanupTimer; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs index 687ee095f3..86fce6b005 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs @@ -187,7 +187,7 @@ internal DbConnectionPool GetConnectionPool(DbConnectionFactory connectionFactor if (!_poolCollection.TryGetValue(currentIdentity, out pool)) { DbConnectionPoolProviderInfo connectionPoolProviderInfo = connectionFactory.CreateConnectionPoolProviderInfo(ConnectionOptions); - DbConnectionPool newPool = new(connectionFactory, this, currentIdentity, connectionPoolProviderInfo); + DbConnectionPool newPool = new WaitHandleDbConnectionPool(connectionFactory, this, currentIdentity, connectionPoolProviderInfo); if (MarkPoolGroupAsActive()) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolState.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolState.cs new file mode 100644 index 0000000000..9ce3f8faea --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolState.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.Data.ProviderBase +{ + internal enum DbConnectionPoolState + { + Initializing, + Running, + ShuttingDown, + } +} diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs index d335b92689..2f4a93abc4 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs @@ -11,7 +11,7 @@ namespace Microsoft.Data.ProviderBase { - internal abstract class IDbConnectionPool + internal abstract class DbConnectionPool { private static int _objectTypeCount; // EventSource counter internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); @@ -24,6 +24,13 @@ internal int ObjectID } } + private DbConnectionPoolState _state; + internal DbConnectionPoolState State + { + get => _state; + set => _state = value; + } + #region Abstract Properties internal abstract int Count { From ad1fa75dc2a9db3e813e5e4ee1ff7c764cbbc5b1 Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Tue, 4 Mar 2025 15:09:58 -0800 Subject: [PATCH 4/9] Rename files --- .../src/Microsoft.Data.SqlClient.csproj | 4 ++-- .../Data/SqlClient/SqlConnectionFactory.cs | 4 ++-- .../SqlClient/SqlInternalConnectionTds.cs | 4 ++-- .../netfx/src/Microsoft.Data.SqlClient.csproj | 4 ++-- .../Data/SqlClient/SqlConnectionFactory.cs | 4 ++-- .../SqlClient/SqlInternalConnectionTds.cs | 4 ++-- .../Data/ProviderBase/DbConnectionFactory.cs | 24 +++++++++---------- .../Data/ProviderBase/DbConnectionInternal.cs | 10 ++++---- .../ProviderBase/DbConnectionPoolGroup.cs | 24 +++++++++---------- .../Data/ProviderBase/IDbConnectionPool.cs | 2 +- ...nPool.cs => WaitHandleDbConnectionPool.cs} | 8 +++---- 11 files changed, 46 insertions(+), 46 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/{DbConnectionPool.cs => WaitHandleDbConnectionPool.cs} (99%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 7438ee903e..478a594d2a 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -80,8 +80,8 @@ Microsoft\Data\ProviderBase\IDbConnectionPool.cs - - Microsoft\Data\ProviderBase\DbConnectionPool.cs + + Microsoft\Data\ProviderBase\WaitHandleDbConnectionPool.cs Microsoft\Data\ProviderBase\DbConnectionPoolState.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs index dfa10c3b07..a88b8c7742 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs @@ -31,12 +31,12 @@ override public DbProviderFactory ProviderFactory } } - override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) + override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection) { return CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningConnection, userOptions: null); } - override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) + override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) { SqlConnectionString opt = (SqlConnectionString)options; SqlConnectionPoolKey key = (SqlConnectionPoolKey)poolKey; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index 9b65f20d6f..0fb9e8d361 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -211,7 +211,7 @@ internal bool IsDNSCachingBeforeRedirectSupported internal byte _tceVersionSupported; // The pool that this connection is associated with, if at all it is. - private DbConnectionPool _dbConnectionPool; + private IDbConnectionPool _dbConnectionPool; // This is used to preserve the authentication context object if we decide to cache it for subsequent connections in the same pool. // This will finally end up in _dbConnectionPool.AuthenticationContexts, but only after 1 successful login to SQL Server using this context. @@ -452,7 +452,7 @@ internal SqlInternalConnectionTds( SessionData reconnectSessionData = null, bool applyTransientFaultHandling = false, string accessToken = null, - DbConnectionPool pool = null, + IDbConnectionPool pool = null, Func> accessTokenCallback = null) : base(connectionOptions) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 2d0f4fe50a..5e1319aeb9 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -268,8 +268,8 @@ Microsoft\Data\ProviderBase\IDbConnectionPool.cs - - Microsoft\Data\ProviderBase\DbConnectionPool.cs + + Microsoft\Data\ProviderBase\WaitHandleDbConnectionPool.cs Microsoft\Data\ProviderBase\DbConnectionPoolState.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs index 755e2dd747..9bcc2e01bc 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs @@ -32,12 +32,12 @@ override public DbProviderFactory ProviderFactory } } - override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) + override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection) { return CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningConnection, userOptions: null); } - override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) + override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) { SqlConnectionString opt = (SqlConnectionString)options; SqlConnectionPoolKey key = (SqlConnectionPoolKey)poolKey; diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index 5152e1ff50..2a4fffee83 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -213,7 +213,7 @@ internal bool IsDNSCachingBeforeRedirectSupported internal byte _tceVersionSupported; // The pool that this connection is associated with, if at all it is. - private DbConnectionPool _dbConnectionPool; + private IDbConnectionPool _dbConnectionPool; // This is used to preserve the authentication context object if we decide to cache it for subsequent connections in the same pool. // This will finally end up in _dbConnectionPool.AuthenticationContexts, but only after 1 successful login to SQL Server using this context. @@ -425,7 +425,7 @@ internal SqlInternalConnectionTds( bool redirectedUserInstance, SqlConnectionString userConnectionOptions = null, // NOTE: userConnectionOptions may be different to connectionOptions if the connection string has been expanded (see SqlConnectionString.Expand) SessionData reconnectSessionData = null, - DbConnectionPool pool = null, + IDbConnectionPool pool = null, string accessToken = null, bool applyTransientFaultHandling = false, Func _connectionPoolGroups; - private readonly List _poolsToRelease; + private readonly List _poolsToRelease; private readonly List _poolGroupsToRelease; private readonly Timer _pruningTimer; @@ -42,7 +42,7 @@ protected DbConnectionFactory(DbConnectionPoolCounters performanceCounters) { _performanceCounters = performanceCounters; _connectionPoolGroups = new Dictionary(); - _poolsToRelease = new List(); + _poolsToRelease = new List(); _poolGroupsToRelease = new List(); _pruningTimer = CreatePruningTimer(); } @@ -55,7 +55,7 @@ internal DbConnectionPoolCounters PerformanceCounters protected DbConnectionFactory() { _connectionPoolGroups = new Dictionary(); - _poolsToRelease = new List(); + _poolsToRelease = new List(); _poolGroupsToRelease = new List(); _pruningTimer = CreatePruningTimer(); } @@ -146,7 +146,7 @@ internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConne return newConnection; } - internal DbConnectionInternal CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) + internal DbConnectionInternal CreatePooledConnection(IDbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) { Debug.Assert(pool != null, "null pool?"); DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = pool.PoolGroup.ProviderInfo; @@ -203,7 +203,7 @@ internal bool TryGetConnection(DbConnection owningConnection, TaskCompletionSour Debug.Assert(owningConnection != null, "null owningConnection?"); DbConnectionPoolGroup poolGroup; - DbConnectionPool connectionPool; + IDbConnectionPool connectionPool; connection = null; // Work around race condition with clearing the pool between GetConnectionPool obtaining pool @@ -405,7 +405,7 @@ private void TryGetConnectionCompletedContinuation(Task ta } } - private DbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup) + private IDbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup) { // if poolgroup is disabled, it will be replaced with a new entry @@ -436,7 +436,7 @@ private DbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnecti Debug.Assert(connectionPoolGroup != null, "null connectionPoolGroup?"); SetConnectionPoolGroup(owningObject, connectionPoolGroup); } - DbConnectionPool connectionPool = connectionPoolGroup.GetConnectionPool(this); + IDbConnectionPool connectionPool = connectionPoolGroup.GetConnectionPool(this); return connectionPool; } @@ -567,8 +567,8 @@ private void PruneConnectionPoolGroups(object state) { if (0 != _poolsToRelease.Count) { - DbConnectionPool[] poolsToRelease = _poolsToRelease.ToArray(); - foreach (DbConnectionPool pool in poolsToRelease) + IDbConnectionPool[] poolsToRelease = _poolsToRelease.ToArray(); + foreach (IDbConnectionPool pool in poolsToRelease) { if (pool != null) { @@ -653,7 +653,7 @@ private void PruneConnectionPoolGroups(object state) } } - internal void QueuePoolForRelease(DbConnectionPool pool, bool clearing) + internal void QueuePoolForRelease(IDbConnectionPool pool, bool clearing) { // Queue the pool up for release -- we'll clear it out and dispose // of it as the last part of the pruning timer callback so we don't @@ -698,12 +698,12 @@ internal void QueuePoolGroupForRelease(DbConnectionPoolGroup poolGroup) #endif } - virtual protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) + virtual protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) { return CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningConnection); } - abstract protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection); + abstract protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection); abstract protected DbConnectionOptions CreateConnectionOptions(string connectionString, DbConnectionOptions previous); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs index 9744b8db9b..235c869cb6 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs @@ -156,7 +156,7 @@ internal bool IsInPool /// /// The pooler that the connection came from (Pooled connections only) /// - internal DbConnectionPool Pool { get; private set; } + internal IDbConnectionPool Pool { get; private set; } public abstract string ServerVersion { get; } @@ -400,7 +400,7 @@ internal void CleanupConnectionOnTransactionCompletion(Transaction transaction) { DetachTransaction(transaction, false); - DbConnectionPool pool = Pool; + IDbConnectionPool pool = Pool; pool?.TransactionEnded(transaction, this); } @@ -461,7 +461,7 @@ internal virtual void CloseConnection(DbConnection owningObject, DbConnectionFac { PrepareForCloseConnection(); - DbConnectionPool connectionPool = Pool; + IDbConnectionPool connectionPool = Pool; // Detach from enlisted transactions that are no longer active on close DetachCurrentTransactionIfEnded(); @@ -585,7 +585,7 @@ internal virtual void DelegatedTransactionEnded() Deactivate(); // call it one more time just in case - DbConnectionPool pool = Pool; + IDbConnectionPool pool = Pool; if (pool == null) { @@ -741,7 +741,7 @@ internal void MakeNonPooledObject(DbConnection owningObject) /// Used by DbConnectionFactory to indicate that this object IS part of a connection pool. /// /// - internal void MakePooledConnection(DbConnectionPool connectionPool) + internal void MakePooledConnection(IDbConnectionPool connectionPool) { _createTime = DateTime.UtcNow; Pool = connectionPool; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs index 86fce6b005..b50095d294 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs @@ -34,7 +34,7 @@ sealed internal class DbConnectionPoolGroup private readonly DbConnectionOptions _connectionOptions; private readonly DbConnectionPoolKey _poolKey; private readonly DbConnectionPoolGroupOptions _poolGroupOptions; - private ConcurrentDictionary _poolCollection; + private ConcurrentDictionary _poolCollection; private int _state; // see PoolGroupState* below @@ -64,7 +64,7 @@ internal DbConnectionPoolGroup(DbConnectionOptions connectionOptions, DbConnecti // HybridDictionary does not create any sub-objects until add // so it is safe to use for non-pooled connection as long as // we check _poolGroupOptions first - _poolCollection = new ConcurrentDictionary(); + _poolCollection = new ConcurrentDictionary(); _state = PoolGroupStateActive; } @@ -113,22 +113,22 @@ internal int Clear() // will return the number of connections in the group after clearing has finished // First, note the old collection and create a new collection to be used - ConcurrentDictionary oldPoolCollection = null; + ConcurrentDictionary oldPoolCollection = null; lock (this) { if (_poolCollection.Count > 0) { oldPoolCollection = _poolCollection; - _poolCollection = new ConcurrentDictionary(); + _poolCollection = new ConcurrentDictionary(); } } // Then, if a new collection was created, release the pools from the old collection if (oldPoolCollection != null) { - foreach (KeyValuePair entry in oldPoolCollection) + foreach (KeyValuePair entry in oldPoolCollection) { - DbConnectionPool pool = entry.Value; + IDbConnectionPool pool = entry.Value; if (pool != null) { DbConnectionFactory connectionFactory = pool.ConnectionFactory; @@ -144,7 +144,7 @@ internal int Clear() return _poolCollection.Count; } - internal DbConnectionPool GetConnectionPool(DbConnectionFactory connectionFactory) + internal IDbConnectionPool GetConnectionPool(DbConnectionFactory connectionFactory) { // When this method returns null it indicates that the connection // factory should not use pooling. @@ -152,7 +152,7 @@ internal DbConnectionPool GetConnectionPool(DbConnectionFactory connectionFactor // We don't support connection pooling on Win9x; // PoolGroupOptions will only be null when we're not supposed to pool // connections. - DbConnectionPool pool = null; + IDbConnectionPool pool = null; if (_poolGroupOptions != null) { #if NETFRAMEWORK @@ -187,7 +187,7 @@ internal DbConnectionPool GetConnectionPool(DbConnectionFactory connectionFactor if (!_poolCollection.TryGetValue(currentIdentity, out pool)) { DbConnectionPoolProviderInfo connectionPoolProviderInfo = connectionFactory.CreateConnectionPoolProviderInfo(ConnectionOptions); - DbConnectionPool newPool = new WaitHandleDbConnectionPool(connectionFactory, this, currentIdentity, connectionPoolProviderInfo); + IDbConnectionPool newPool = new WaitHandleDbConnectionPool(connectionFactory, this, currentIdentity, connectionPoolProviderInfo); if (MarkPoolGroupAsActive()) { @@ -257,11 +257,11 @@ internal bool Prune() { if (_poolCollection.Count > 0) { - var newPoolCollection = new ConcurrentDictionary(); + var newPoolCollection = new ConcurrentDictionary(); - foreach (KeyValuePair entry in _poolCollection) + foreach (KeyValuePair entry in _poolCollection) { - DbConnectionPool pool = entry.Value; + IDbConnectionPool pool = entry.Value; if (pool != null) { // Actually prune the pool if there are no connections in the pool and no errors occurred. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs index 2f4a93abc4..5db709341e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs @@ -11,7 +11,7 @@ namespace Microsoft.Data.ProviderBase { - internal abstract class DbConnectionPool + internal abstract class IDbConnectionPool { private static int _objectTypeCount; // EventSource counter internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/WaitHandleDbConnectionPool.cs similarity index 99% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/WaitHandleDbConnectionPool.cs index fe78d13ea7..e2fc35d20f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/WaitHandleDbConnectionPool.cs @@ -19,7 +19,7 @@ namespace Microsoft.Data.ProviderBase { - internal sealed class WaitHandleDbConnectionPool : DbConnectionPool + internal sealed class WaitHandleDbConnectionPool : IDbConnectionPool { // This class is a way to stash our cloned Tx key for later disposal when it's no longer needed. // We can't get at the key in the dictionary without enumerating entries, so we stash an extra @@ -60,12 +60,12 @@ private sealed class TransactedConnectionPool { Dictionary _transactedCxns; - DbConnectionPool _pool; + IDbConnectionPool _pool; private static int _objectTypeCount; // EventSource Counter internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); - internal TransactedConnectionPool(DbConnectionPool pool) + internal TransactedConnectionPool(IDbConnectionPool pool) { Debug.Assert(pool != null, "null pool?"); @@ -82,7 +82,7 @@ internal int ObjectID } } - internal DbConnectionPool Pool + internal IDbConnectionPool Pool { get { From 2cd3a581e7403e0b3c151484ecc59040c74fd01d Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Tue, 4 Mar 2025 15:15:38 -0800 Subject: [PATCH 5/9] Rename abstract base back to DbConnectionPool --- .../src/Microsoft.Data.SqlClient.csproj | 4 ++-- .../Data/SqlClient/SqlConnectionFactory.cs | 4 ++-- .../SqlClient/SqlInternalConnectionTds.cs | 4 ++-- .../netfx/src/Microsoft.Data.SqlClient.csproj | 4 ++-- .../Data/SqlClient/SqlConnectionFactory.cs | 4 ++-- .../SqlClient/SqlInternalConnectionTds.cs | 4 ++-- .../Data/ProviderBase/DbConnectionFactory.cs | 24 +++++++++---------- .../Data/ProviderBase/DbConnectionInternal.cs | 10 ++++---- ...bConnectionPool.cs => DbConnectionPool.cs} | 2 +- .../ProviderBase/DbConnectionPoolGroup.cs | 24 +++++++++---------- .../WaitHandleDbConnectionPool.cs | 8 +++---- 11 files changed, 46 insertions(+), 46 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/{IDbConnectionPool.cs => DbConnectionPool.cs} (98%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 478a594d2a..dda4ec2afe 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -77,8 +77,8 @@ Microsoft\Data\ProviderBase\DbConnectionFactory.cs - - Microsoft\Data\ProviderBase\IDbConnectionPool.cs + + Microsoft\Data\ProviderBase\DbConnectionPool.cs Microsoft\Data\ProviderBase\WaitHandleDbConnectionPool.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs index a88b8c7742..dfa10c3b07 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs @@ -31,12 +31,12 @@ override public DbProviderFactory ProviderFactory } } - override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection) + override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) { return CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningConnection, userOptions: null); } - override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) + override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) { SqlConnectionString opt = (SqlConnectionString)options; SqlConnectionPoolKey key = (SqlConnectionPoolKey)poolKey; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index 0fb9e8d361..9b65f20d6f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -211,7 +211,7 @@ internal bool IsDNSCachingBeforeRedirectSupported internal byte _tceVersionSupported; // The pool that this connection is associated with, if at all it is. - private IDbConnectionPool _dbConnectionPool; + private DbConnectionPool _dbConnectionPool; // This is used to preserve the authentication context object if we decide to cache it for subsequent connections in the same pool. // This will finally end up in _dbConnectionPool.AuthenticationContexts, but only after 1 successful login to SQL Server using this context. @@ -452,7 +452,7 @@ internal SqlInternalConnectionTds( SessionData reconnectSessionData = null, bool applyTransientFaultHandling = false, string accessToken = null, - IDbConnectionPool pool = null, + DbConnectionPool pool = null, Func> accessTokenCallback = null) : base(connectionOptions) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 5e1319aeb9..907c154497 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -265,8 +265,8 @@ Microsoft\Data\ProviderBase\DbConnectionInternal.cs - - Microsoft\Data\ProviderBase\IDbConnectionPool.cs + + Microsoft\Data\ProviderBase\DbConnectionPool.cs Microsoft\Data\ProviderBase\WaitHandleDbConnectionPool.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs index 9bcc2e01bc..755e2dd747 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs @@ -32,12 +32,12 @@ override public DbProviderFactory ProviderFactory } } - override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection) + override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) { return CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningConnection, userOptions: null); } - override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) + override protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) { SqlConnectionString opt = (SqlConnectionString)options; SqlConnectionPoolKey key = (SqlConnectionPoolKey)poolKey; diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index 2a4fffee83..5152e1ff50 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -213,7 +213,7 @@ internal bool IsDNSCachingBeforeRedirectSupported internal byte _tceVersionSupported; // The pool that this connection is associated with, if at all it is. - private IDbConnectionPool _dbConnectionPool; + private DbConnectionPool _dbConnectionPool; // This is used to preserve the authentication context object if we decide to cache it for subsequent connections in the same pool. // This will finally end up in _dbConnectionPool.AuthenticationContexts, but only after 1 successful login to SQL Server using this context. @@ -425,7 +425,7 @@ internal SqlInternalConnectionTds( bool redirectedUserInstance, SqlConnectionString userConnectionOptions = null, // NOTE: userConnectionOptions may be different to connectionOptions if the connection string has been expanded (see SqlConnectionString.Expand) SessionData reconnectSessionData = null, - IDbConnectionPool pool = null, + DbConnectionPool pool = null, string accessToken = null, bool applyTransientFaultHandling = false, Func _connectionPoolGroups; - private readonly List _poolsToRelease; + private readonly List _poolsToRelease; private readonly List _poolGroupsToRelease; private readonly Timer _pruningTimer; @@ -42,7 +42,7 @@ protected DbConnectionFactory(DbConnectionPoolCounters performanceCounters) { _performanceCounters = performanceCounters; _connectionPoolGroups = new Dictionary(); - _poolsToRelease = new List(); + _poolsToRelease = new List(); _poolGroupsToRelease = new List(); _pruningTimer = CreatePruningTimer(); } @@ -55,7 +55,7 @@ internal DbConnectionPoolCounters PerformanceCounters protected DbConnectionFactory() { _connectionPoolGroups = new Dictionary(); - _poolsToRelease = new List(); + _poolsToRelease = new List(); _poolGroupsToRelease = new List(); _pruningTimer = CreatePruningTimer(); } @@ -146,7 +146,7 @@ internal DbConnectionInternal CreateNonPooledConnection(DbConnection owningConne return newConnection; } - internal DbConnectionInternal CreatePooledConnection(IDbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) + internal DbConnectionInternal CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) { Debug.Assert(pool != null, "null pool?"); DbConnectionPoolGroupProviderInfo poolGroupProviderInfo = pool.PoolGroup.ProviderInfo; @@ -203,7 +203,7 @@ internal bool TryGetConnection(DbConnection owningConnection, TaskCompletionSour Debug.Assert(owningConnection != null, "null owningConnection?"); DbConnectionPoolGroup poolGroup; - IDbConnectionPool connectionPool; + DbConnectionPool connectionPool; connection = null; // Work around race condition with clearing the pool between GetConnectionPool obtaining pool @@ -405,7 +405,7 @@ private void TryGetConnectionCompletedContinuation(Task ta } } - private IDbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup) + private DbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup) { // if poolgroup is disabled, it will be replaced with a new entry @@ -436,7 +436,7 @@ private IDbConnectionPool GetConnectionPool(DbConnection owningObject, DbConnect Debug.Assert(connectionPoolGroup != null, "null connectionPoolGroup?"); SetConnectionPoolGroup(owningObject, connectionPoolGroup); } - IDbConnectionPool connectionPool = connectionPoolGroup.GetConnectionPool(this); + DbConnectionPool connectionPool = connectionPoolGroup.GetConnectionPool(this); return connectionPool; } @@ -567,8 +567,8 @@ private void PruneConnectionPoolGroups(object state) { if (0 != _poolsToRelease.Count) { - IDbConnectionPool[] poolsToRelease = _poolsToRelease.ToArray(); - foreach (IDbConnectionPool pool in poolsToRelease) + DbConnectionPool[] poolsToRelease = _poolsToRelease.ToArray(); + foreach (DbConnectionPool pool in poolsToRelease) { if (pool != null) { @@ -653,7 +653,7 @@ private void PruneConnectionPoolGroups(object state) } } - internal void QueuePoolForRelease(IDbConnectionPool pool, bool clearing) + internal void QueuePoolForRelease(DbConnectionPool pool, bool clearing) { // Queue the pool up for release -- we'll clear it out and dispose // of it as the last part of the pruning timer callback so we don't @@ -698,12 +698,12 @@ internal void QueuePoolGroupForRelease(DbConnectionPoolGroup poolGroup) #endif } - virtual protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) + virtual protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) { return CreateConnection(options, poolKey, poolGroupProviderInfo, pool, owningConnection); } - abstract protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, IDbConnectionPool pool, DbConnection owningConnection); + abstract protected DbConnectionInternal CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection); abstract protected DbConnectionOptions CreateConnectionOptions(string connectionString, DbConnectionOptions previous); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs index 235c869cb6..9744b8db9b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs @@ -156,7 +156,7 @@ internal bool IsInPool /// /// The pooler that the connection came from (Pooled connections only) /// - internal IDbConnectionPool Pool { get; private set; } + internal DbConnectionPool Pool { get; private set; } public abstract string ServerVersion { get; } @@ -400,7 +400,7 @@ internal void CleanupConnectionOnTransactionCompletion(Transaction transaction) { DetachTransaction(transaction, false); - IDbConnectionPool pool = Pool; + DbConnectionPool pool = Pool; pool?.TransactionEnded(transaction, this); } @@ -461,7 +461,7 @@ internal virtual void CloseConnection(DbConnection owningObject, DbConnectionFac { PrepareForCloseConnection(); - IDbConnectionPool connectionPool = Pool; + DbConnectionPool connectionPool = Pool; // Detach from enlisted transactions that are no longer active on close DetachCurrentTransactionIfEnded(); @@ -585,7 +585,7 @@ internal virtual void DelegatedTransactionEnded() Deactivate(); // call it one more time just in case - IDbConnectionPool pool = Pool; + DbConnectionPool pool = Pool; if (pool == null) { @@ -741,7 +741,7 @@ internal void MakeNonPooledObject(DbConnection owningObject) /// Used by DbConnectionFactory to indicate that this object IS part of a connection pool. /// /// - internal void MakePooledConnection(IDbConnectionPool connectionPool) + internal void MakePooledConnection(DbConnectionPool connectionPool) { _createTime = DateTime.UtcNow; Pool = connectionPool; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs similarity index 98% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs index 5db709341e..2f4a93abc4 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/IDbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs @@ -11,7 +11,7 @@ namespace Microsoft.Data.ProviderBase { - internal abstract class IDbConnectionPool + internal abstract class DbConnectionPool { private static int _objectTypeCount; // EventSource counter internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs index b50095d294..86fce6b005 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs @@ -34,7 +34,7 @@ sealed internal class DbConnectionPoolGroup private readonly DbConnectionOptions _connectionOptions; private readonly DbConnectionPoolKey _poolKey; private readonly DbConnectionPoolGroupOptions _poolGroupOptions; - private ConcurrentDictionary _poolCollection; + private ConcurrentDictionary _poolCollection; private int _state; // see PoolGroupState* below @@ -64,7 +64,7 @@ internal DbConnectionPoolGroup(DbConnectionOptions connectionOptions, DbConnecti // HybridDictionary does not create any sub-objects until add // so it is safe to use for non-pooled connection as long as // we check _poolGroupOptions first - _poolCollection = new ConcurrentDictionary(); + _poolCollection = new ConcurrentDictionary(); _state = PoolGroupStateActive; } @@ -113,22 +113,22 @@ internal int Clear() // will return the number of connections in the group after clearing has finished // First, note the old collection and create a new collection to be used - ConcurrentDictionary oldPoolCollection = null; + ConcurrentDictionary oldPoolCollection = null; lock (this) { if (_poolCollection.Count > 0) { oldPoolCollection = _poolCollection; - _poolCollection = new ConcurrentDictionary(); + _poolCollection = new ConcurrentDictionary(); } } // Then, if a new collection was created, release the pools from the old collection if (oldPoolCollection != null) { - foreach (KeyValuePair entry in oldPoolCollection) + foreach (KeyValuePair entry in oldPoolCollection) { - IDbConnectionPool pool = entry.Value; + DbConnectionPool pool = entry.Value; if (pool != null) { DbConnectionFactory connectionFactory = pool.ConnectionFactory; @@ -144,7 +144,7 @@ internal int Clear() return _poolCollection.Count; } - internal IDbConnectionPool GetConnectionPool(DbConnectionFactory connectionFactory) + internal DbConnectionPool GetConnectionPool(DbConnectionFactory connectionFactory) { // When this method returns null it indicates that the connection // factory should not use pooling. @@ -152,7 +152,7 @@ internal IDbConnectionPool GetConnectionPool(DbConnectionFactory connectionFacto // We don't support connection pooling on Win9x; // PoolGroupOptions will only be null when we're not supposed to pool // connections. - IDbConnectionPool pool = null; + DbConnectionPool pool = null; if (_poolGroupOptions != null) { #if NETFRAMEWORK @@ -187,7 +187,7 @@ internal IDbConnectionPool GetConnectionPool(DbConnectionFactory connectionFacto if (!_poolCollection.TryGetValue(currentIdentity, out pool)) { DbConnectionPoolProviderInfo connectionPoolProviderInfo = connectionFactory.CreateConnectionPoolProviderInfo(ConnectionOptions); - IDbConnectionPool newPool = new WaitHandleDbConnectionPool(connectionFactory, this, currentIdentity, connectionPoolProviderInfo); + DbConnectionPool newPool = new WaitHandleDbConnectionPool(connectionFactory, this, currentIdentity, connectionPoolProviderInfo); if (MarkPoolGroupAsActive()) { @@ -257,11 +257,11 @@ internal bool Prune() { if (_poolCollection.Count > 0) { - var newPoolCollection = new ConcurrentDictionary(); + var newPoolCollection = new ConcurrentDictionary(); - foreach (KeyValuePair entry in _poolCollection) + foreach (KeyValuePair entry in _poolCollection) { - IDbConnectionPool pool = entry.Value; + DbConnectionPool pool = entry.Value; if (pool != null) { // Actually prune the pool if there are no connections in the pool and no errors occurred. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/WaitHandleDbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/WaitHandleDbConnectionPool.cs index e2fc35d20f..fe78d13ea7 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/WaitHandleDbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/WaitHandleDbConnectionPool.cs @@ -19,7 +19,7 @@ namespace Microsoft.Data.ProviderBase { - internal sealed class WaitHandleDbConnectionPool : IDbConnectionPool + internal sealed class WaitHandleDbConnectionPool : DbConnectionPool { // This class is a way to stash our cloned Tx key for later disposal when it's no longer needed. // We can't get at the key in the dictionary without enumerating entries, so we stash an extra @@ -60,12 +60,12 @@ private sealed class TransactedConnectionPool { Dictionary _transactedCxns; - IDbConnectionPool _pool; + DbConnectionPool _pool; private static int _objectTypeCount; // EventSource Counter internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); - internal TransactedConnectionPool(IDbConnectionPool pool) + internal TransactedConnectionPool(DbConnectionPool pool) { Debug.Assert(pool != null, "null pool?"); @@ -82,7 +82,7 @@ internal int ObjectID } } - internal IDbConnectionPool Pool + internal DbConnectionPool Pool { get { From a99ca387a3852520a4d49b099c5b4223438dda1f Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Tue, 4 Mar 2025 16:24:29 -0800 Subject: [PATCH 6/9] Reorganize pool files. --- .../src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs | 1 + .../src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs | 1 + .../src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs | 1 + .../ConnectionPool}/DbConnectionPool.cs | 3 ++- .../DbConnectionPoolAuthenticationContext.cs | 2 +- .../DbConnectionPoolAuthenticationContextKey.cs | 2 +- .../ConnectionPool}/DbConnectionPoolCounters.netfx.cs | 2 +- .../ConnectionPool}/DbConnectionPoolGroup.cs | 4 ++-- .../ConnectionPool}/DbConnectionPoolGroupProviderInfo.cs | 2 +- .../ConnectionPool}/DbConnectionPoolIdentity.Unix.cs | 2 +- .../ConnectionPool}/DbConnectionPoolIdentity.Windows.cs | 2 +- .../ConnectionPool}/DbConnectionPoolIdentity.cs | 2 +- .../ConnectionPool}/DbConnectionPoolKey.cs | 2 +- .../ConnectionPool}/DbConnectionPoolOptions.cs | 2 +- .../ConnectionPool}/DbConnectionPoolProviderInfo.cs | 2 +- .../ConnectionPool}/DbConnectionPoolState.cs | 2 +- .../SqlConnectionPoolGroupProviderInfo.cs | 3 +-- .../SqlClient/{ => ConnectionPool}/SqlConnectionPoolKey.cs | 2 +- .../{ => ConnectionPool}/SqlConnectionPoolProviderInfo.cs | 3 +-- .../ConnectionPool}/WaitHandleDbConnectionPool.cs | 6 +++--- .../src/Microsoft/Data/SqlClient/SqlDependency.cs | 2 +- .../src/Microsoft/Data/SqlClient/SqlDependencyListener.cs | 2 +- 22 files changed, 26 insertions(+), 24 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPool.cs (97%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolAuthenticationContext.cs (98%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolAuthenticationContextKey.cs (98%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolCounters.netfx.cs (99%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolGroup.cs (99%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolGroupProviderInfo.cs (91%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolIdentity.Unix.cs (88%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolIdentity.Windows.cs (97%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolIdentity.cs (98%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{Common => SqlClient/ConnectionPool}/DbConnectionPoolKey.cs (96%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolOptions.cs (97%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolProviderInfo.cs (84%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/DbConnectionPoolState.cs (86%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/{ => ConnectionPool}/SqlConnectionPoolGroupProviderInfo.cs (98%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/{ => ConnectionPool}/SqlConnectionPoolKey.cs (98%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/{ => ConnectionPool}/SqlConnectionPoolProviderInfo.cs (89%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/{ProviderBase => SqlClient/ConnectionPool}/WaitHandleDbConnectionPool.cs (99%) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs index b25f9a2d3b..b8ada9b1bc 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionClosed.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using Microsoft.Data.Common; +using Microsoft.Data.SqlClient.ConnectionPool; using System.Data; using System.Data.Common; using System.Diagnostics; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs index 0fdd85c4bf..0e60dd2138 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using Microsoft.Data.Common; using Microsoft.Data.SqlClient; +using Microsoft.Data.SqlClient.ConnectionPool; namespace Microsoft.Data.ProviderBase { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs index 9744b8db9b..7268f00eea 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs @@ -11,6 +11,7 @@ using System.Transactions; using Microsoft.Data.Common; using Microsoft.Data.SqlClient; +using Microsoft.Data.SqlClient.ConnectionPool; #if NETFRAMEWORK using System.Runtime.ConstrainedExecution; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPool.cs similarity index 97% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPool.cs index 2f4a93abc4..1c9475d8f0 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPool.cs @@ -8,8 +8,9 @@ using System.Threading.Tasks; using System.Transactions; using Microsoft.Data.Common; +using Microsoft.Data.ProviderBase; -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { internal abstract class DbConnectionPool { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolAuthenticationContext.cs similarity index 98% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolAuthenticationContext.cs index 29ac7fee31..71dbc3c714 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolAuthenticationContext.cs @@ -7,7 +7,7 @@ using System.Runtime.ConstrainedExecution; using System.Threading; -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { /// /// Represents the context of an authentication attempt when using the new active directory based authentication mechanisms. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContextKey.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolAuthenticationContextKey.cs similarity index 98% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContextKey.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolAuthenticationContextKey.cs index a6f15ca999..e12648b3d0 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContextKey.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolAuthenticationContextKey.cs @@ -5,7 +5,7 @@ using System; using System.Diagnostics; -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { /// /// Represents the key of dbConnectionPoolAuthenticationContext. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolCounters.netfx.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolCounters.netfx.cs similarity index 99% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolCounters.netfx.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolCounters.netfx.cs index 04b9e37a61..0eadb7f42c 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolCounters.netfx.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolCounters.netfx.cs @@ -6,7 +6,7 @@ #if NETFRAMEWORK -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { using System; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolGroup.cs similarity index 99% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolGroup.cs index 86fce6b005..5aaa4fdcd7 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroup.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolGroup.cs @@ -4,13 +4,13 @@ using Microsoft.Data.Common; -using Microsoft.Data.SqlClient; +using Microsoft.Data.ProviderBase; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Threading; -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { // set_ConnectionString calls DbConnectionFactory.GetConnectionPoolGroup // when not found a new pool entry is created and potentially added diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroupProviderInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolGroupProviderInfo.cs similarity index 91% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroupProviderInfo.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolGroupProviderInfo.cs index 3eceb6d3e3..9ee83357bd 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolGroupProviderInfo.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolGroupProviderInfo.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { internal class DbConnectionPoolGroupProviderInfo { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.Unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.Unix.cs similarity index 88% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.Unix.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.Unix.cs index 95769c3e6c..3eadc8761a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.Unix.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.Unix.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { partial class DbConnectionPoolIdentity { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.Windows.cs similarity index 97% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.Windows.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.Windows.cs index 62fbc34aed..175d4c8595 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.Windows.cs @@ -8,7 +8,7 @@ using System.Security.Principal; using Microsoft.Data.SqlClient; -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { partial class DbConnectionPoolIdentity { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs similarity index 98% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs index e97f55a7ad..5716146a6b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolIdentity.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { sealed internal partial class DbConnectionPoolIdentity { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/DbConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolKey.cs similarity index 96% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/DbConnectionPoolKey.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolKey.cs index 7d2799289f..bfcd4cd2ef 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/DbConnectionPoolKey.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolKey.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.Data.Common +namespace Microsoft.Data.SqlClient.ConnectionPool { // DbConnectionPoolKey: Base class implementation of a key to connection pool groups // Only connection string is used as a key diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolOptions.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolOptions.cs similarity index 97% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolOptions.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolOptions.cs index 866453432c..7adf8abdc2 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolOptions.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolOptions.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { internal sealed class DbConnectionPoolGroupOptions { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolProviderInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolProviderInfo.cs similarity index 84% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolProviderInfo.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolProviderInfo.cs index 5392795dff..1afeb473be 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolProviderInfo.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolProviderInfo.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { internal class DbConnectionPoolProviderInfo { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolState.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolState.cs similarity index 86% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolState.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolState.cs index 9ce3f8faea..1790e38a57 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolState.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolState.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { internal enum DbConnectionPoolState { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/SqlConnectionPoolGroupProviderInfo.cs similarity index 98% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/SqlConnectionPoolGroupProviderInfo.cs index 47de649bbd..1fe1768c0a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/SqlConnectionPoolGroupProviderInfo.cs @@ -3,9 +3,8 @@ // See the LICENSE file in the project root for more information. using System.Security; -using Microsoft.Data.ProviderBase; -namespace Microsoft.Data.SqlClient +namespace Microsoft.Data.SqlClient.ConnectionPool { internal sealed class SqlConnectionPoolGroupProviderInfo : DbConnectionPoolGroupProviderInfo { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/SqlConnectionPoolKey.cs similarity index 98% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/SqlConnectionPoolKey.cs index 04a0d32281..207c0a8e1a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolKey.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/SqlConnectionPoolKey.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using Microsoft.Data.Common; -namespace Microsoft.Data.SqlClient +namespace Microsoft.Data.SqlClient.ConnectionPool { // SqlConnectionPoolKey: Implementation of a key to connection pool groups for specifically to be used for SqlConnection // Connection string and SqlCredential are used as a key diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolProviderInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/SqlConnectionPoolProviderInfo.cs similarity index 89% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolProviderInfo.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/SqlConnectionPoolProviderInfo.cs index eee7550f5e..9c6df4d245 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolProviderInfo.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/SqlConnectionPoolProviderInfo.cs @@ -2,9 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Data.ProviderBase; -namespace Microsoft.Data.SqlClient +namespace Microsoft.Data.SqlClient.ConnectionPool { internal sealed class SqlConnectionPoolProviderInfo : DbConnectionPoolProviderInfo { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/WaitHandleDbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/WaitHandleDbConnectionPool.cs similarity index 99% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/WaitHandleDbConnectionPool.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/WaitHandleDbConnectionPool.cs index fe78d13ea7..ef45fcfdc2 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/WaitHandleDbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/WaitHandleDbConnectionPool.cs @@ -14,10 +14,10 @@ using System.Threading.Tasks; using System.Transactions; using Microsoft.Data.Common; -using Microsoft.Data.SqlClient; -using static Microsoft.Data.ProviderBase.DbConnectionPoolState; +using Microsoft.Data.ProviderBase; +using static Microsoft.Data.SqlClient.ConnectionPool.DbConnectionPoolState; -namespace Microsoft.Data.ProviderBase +namespace Microsoft.Data.SqlClient.ConnectionPool { internal sealed class WaitHandleDbConnectionPool : DbConnectionPool { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependency.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependency.cs index 534d42f866..ea29930b24 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependency.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependency.cs @@ -18,8 +18,8 @@ using System.Threading; using System.Xml; using Microsoft.Data.Common; -using Microsoft.Data.ProviderBase; using Microsoft.Data.Sql; +using Microsoft.Data.SqlClient.ConnectionPool; namespace Microsoft.Data.SqlClient { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyListener.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyListener.cs index 9e3644a94c..0c2d4a005e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyListener.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyListener.cs @@ -17,8 +17,8 @@ using System.Threading; using System.Xml; using Microsoft.Data.Common; -using Microsoft.Data.ProviderBase; using Microsoft.Data.SqlClient; +using Microsoft.Data.SqlClient.ConnectionPool; // This class is the process wide dependency dispatcher. It contains all connection listeners for the entire process and // receives notifications on those connections to dispatch to the corresponding AppDomain dispatcher to notify the From 7cbb50678051dfbb4f56bd9cbfe5fac18e823b00 Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Tue, 4 Mar 2025 16:25:17 -0800 Subject: [PATCH 7/9] Fix imports --- .../src/Microsoft.Data.SqlClient.csproj | 76 +++++++++---------- .../Microsoft/Data/SqlClient/SqlConnection.cs | 1 + .../Data/SqlClient/SqlConnectionFactory.cs | 1 + .../Data/SqlClient/SqlConnectionHelper.cs | 1 + .../SqlClient/SqlInternalConnectionTds.cs | 1 + .../netfx/src/Microsoft.Data.SqlClient.csproj | 72 +++++++++--------- .../Microsoft/Data/SqlClient/SqlConnection.cs | 1 + .../Data/SqlClient/SqlConnectionFactory.cs | 1 + .../Data/SqlClient/SqlConnectionHelper.cs | 9 ++- .../SqlClient/SqlInternalConnectionTds.cs | 1 + 10 files changed, 86 insertions(+), 78 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index dda4ec2afe..b2763754c1 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -53,9 +53,6 @@ Microsoft\Data\Common\DbConnectionOptions.Common.cs - - Microsoft\Data\Common\DbConnectionPoolKey.cs - Microsoft\Data\Common\DbConnectionStringCommon.cs @@ -71,44 +68,56 @@ Microsoft\Data\OperationAbortedException.cs + + Microsoft\Data\ProviderBase\DbConnectionInternal.cs + Microsoft\Data\ProviderBase\DbConnectionClosed.cs Microsoft\Data\ProviderBase\DbConnectionFactory.cs - - Microsoft\Data\ProviderBase\DbConnectionPool.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPool.cs - - Microsoft\Data\ProviderBase\WaitHandleDbConnectionPool.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolAuthenticationContext.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolState.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolAuthenticationContextKey.cs - - Microsoft\Data\ProviderBase\DbConnectionInternal.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolGroup.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolAuthenticationContext.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolGroupProviderInfo.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolAuthenticationContextKey.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolIdentity.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolGroup.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolKey.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolGroupProviderInfo.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolOptions.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolProviderInfo.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolOptions.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolState.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolProviderInfo.cs + + Microsoft\Data\SqlClient\ConnectionPool\WaitHandleDbConnectionPool.cs + + + Microsoft\Data\SqlClient\ConnectionPool\SqlConnectionPoolGroupProviderInfo.cs + + + Microsoft\Data\SqlClient\ConnectionPool\SqlConnectionPoolKey.cs + + + Microsoft\Data\SqlClient\ConnectionPool\SqlConnectionPoolProviderInfo.cs Microsoft\Data\ProviderBase\DbMetaDataFactory.cs @@ -422,15 +431,6 @@ Microsoft\Data\SqlClient\SqlConnectionEncryptOptionConverter.cs - - Microsoft\Data\SqlClient\SqlConnectionPoolGroupProviderInfo.cs - - - Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs - - - Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs - Microsoft\Data\SqlClient\SqlConnectionString.cs @@ -784,8 +784,8 @@ Microsoft\Data\Common\AdapterUtil.Windows.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Windows.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolIdentity.Windows.cs Microsoft\Data\Sql\SqlDataSourceEnumeratorNativeHelper.cs @@ -827,8 +827,8 @@ Microsoft\Data\Common\AdapterUtil.Unix.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Unix.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolIdentity.Unix.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs index 863996629e..059f18c596 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -19,6 +19,7 @@ using System.Threading.Tasks; using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; +using Microsoft.Data.SqlClient.ConnectionPool; using Microsoft.Data.SqlClient.Diagnostics; using Microsoft.SqlServer.Server; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs index dfa10c3b07..ca9bcc2cd9 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs @@ -8,6 +8,7 @@ using System.IO; using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; +using Microsoft.Data.SqlClient.ConnectionPool; namespace Microsoft.Data.SqlClient { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs index aa8420d8bb..c8e782c0b3 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs @@ -10,6 +10,7 @@ using System.Transactions; using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; +using Microsoft.Data.SqlClient.ConnectionPool; namespace Microsoft.Data.SqlClient diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index 9b65f20d6f..d128268185 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -17,6 +17,7 @@ using System.Transactions; using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; +using Microsoft.Data.SqlClient.ConnectionPool; using Microsoft.Identity.Client; namespace Microsoft.Data.SqlClient diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 907c154497..fe5c8234db 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -241,9 +241,6 @@ Microsoft\Data\Common\DbConnectionOptions.Common.cs - - Microsoft\Data\Common\DbConnectionPoolKey.cs - Microsoft\Data\Common\MultipartIdentifier.cs @@ -265,41 +262,53 @@ Microsoft\Data\ProviderBase\DbConnectionInternal.cs - - Microsoft\Data\ProviderBase\DbConnectionPool.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPool.cs + + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolAuthenticationContext.cs + + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolAuthenticationContextKey.cs + + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolCounters.netfx.cs + + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolGroup.cs - - Microsoft\Data\ProviderBase\WaitHandleDbConnectionPool.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolGroupProviderInfo.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolState.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolIdentity.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolAuthenticationContext.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolIdentity.Windows.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolAuthenticationContextKey.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolKey.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolCounters.netfx.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolOptions.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolGroup.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolProviderInfo.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolGroupProviderInfo.cs + + Microsoft\Data\SqlClient\ConnectionPool\DbConnectionPoolState.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.cs + + Microsoft\Data\SqlClient\ConnectionPool\WaitHandleDbConnectionPool.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Windows.cs + + Microsoft\Data\SqlClient\ConnectionPool\SqlConnectionPoolGroupProviderInfo.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolOptions.cs + + Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs - - Microsoft\Data\ProviderBase\DbConnectionPoolProviderInfo.cs + + Microsoft\Data\SqlClient\ConnectionPool\SqlConnectionPoolProviderInfo.cs Microsoft\Data\ProviderBase\DbMetaDataFactory.cs @@ -634,15 +643,6 @@ Microsoft\Data\SqlClient\SqlConnectionEncryptOptionConverter.cs - - Microsoft\Data\SqlClient\SqlConnectionPoolGroupProviderInfo.cs - - - Microsoft\Data\SqlClient\SqlConnectionPoolKey.cs - - - Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs - Microsoft\Data\SqlClient\SqlConnectionString.cs diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs index 931fb96640..1e56defff9 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -25,6 +25,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Data.ProviderBase; +using Microsoft.Data.SqlClient.ConnectionPool; using Microsoft.SqlServer.Server; [assembly: InternalsVisibleTo("System.Data.DataSetExtensions, PublicKey=" + Microsoft.Data.SqlClient.AssemblyRef.EcmaPublicKeyFull)] // DevDiv Bugs 92166 diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs index 755e2dd747..9383b8e6af 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs @@ -12,6 +12,7 @@ using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; using Microsoft.Data.SqlClient.Server; +using Microsoft.Data.SqlClient.ConnectionPool; namespace Microsoft.Data.SqlClient { diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs index 54d31d5301..40a12d4976 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs @@ -12,6 +12,7 @@ namespace Microsoft.Data.SqlClient using System.Threading; using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; + using Microsoft.Data.SqlClient.ConnectionPool; using System.Transactions; public sealed partial class SqlConnection : DbConnection @@ -79,7 +80,7 @@ internal DbConnectionOptions ConnectionOptions { get { - Microsoft.Data.ProviderBase.DbConnectionPoolGroup poolGroup = PoolGroup; + DbConnectionPoolGroup poolGroup = PoolGroup; return poolGroup != null ? poolGroup.ConnectionOptions : null; } } @@ -102,7 +103,7 @@ private void ConnectionString_Set(string value) private void ConnectionString_Set(DbConnectionPoolKey key) { DbConnectionOptions connectionOptions = null; - Microsoft.Data.ProviderBase.DbConnectionPoolGroup poolGroup = ConnectionFactory.GetConnectionPoolGroup(key, null, ref connectionOptions); + DbConnectionPoolGroup poolGroup = ConnectionFactory.GetConnectionPoolGroup(key, null, ref connectionOptions); DbConnectionInternal connectionInternal = InnerConnection; bool flag = connectionInternal.AllowSetConnectionString; if (flag) @@ -144,7 +145,7 @@ internal DbConnectionInternal InnerConnection } } - internal Microsoft.Data.ProviderBase.DbConnectionPoolGroup PoolGroup + internal DbConnectionPoolGroup PoolGroup { get { @@ -341,7 +342,7 @@ internal void PermissionDemand() { Debug.Assert(DbConnectionClosedConnecting.SingletonInstance == _innerConnection, "not connecting"); - Microsoft.Data.ProviderBase.DbConnectionPoolGroup poolGroup = PoolGroup; + DbConnectionPoolGroup poolGroup = PoolGroup; DbConnectionOptions connectionOptions = poolGroup != null ? poolGroup.ConnectionOptions : null; if (connectionOptions == null || connectionOptions.IsEmpty) { diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index 5152e1ff50..7ad09dd3d5 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -17,6 +17,7 @@ using System.Threading.Tasks; using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; +using Microsoft.Data.SqlClient.ConnectionPool; using Microsoft.Identity.Client; using System.Transactions; From 3f434bfbabc472219e2ba47227fcd91478743fa3 Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Wed, 5 Mar 2025 12:41:13 -0800 Subject: [PATCH 8/9] Fix pooling test reflection --- .../SystemDataInternals/ConnectionPoolHelper.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/ConnectionPoolHelper.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/ConnectionPoolHelper.cs index d7c5471427..e930f437e9 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/ConnectionPoolHelper.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/ConnectionPoolHelper.cs @@ -14,23 +14,24 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.SystemDataInternals internal static class ConnectionPoolHelper { private static Assembly s_MicrosoftDotData = Assembly.Load(new AssemblyName(typeof(SqlConnection).GetTypeInfo().Assembly.FullName)); - private static Type s_dbConnectionPool = s_MicrosoftDotData.GetType("Microsoft.Data.ProviderBase.DbConnectionPool"); - private static Type s_dbConnectionPoolGroup = s_MicrosoftDotData.GetType("Microsoft.Data.ProviderBase.DbConnectionPoolGroup"); - private static Type s_dbConnectionPoolIdentity = s_MicrosoftDotData.GetType("Microsoft.Data.ProviderBase.DbConnectionPoolIdentity"); + private static Type s_dbConnectionPool = s_MicrosoftDotData.GetType("Microsoft.Data.SqlClient.ConnectionPool.DbConnectionPool"); + private static Type s_waitHandleDbConnectionPool = s_MicrosoftDotData.GetType("Microsoft.Data.SqlClient.ConnectionPool.WaitHandleDbConnectionPool"); + private static Type s_dbConnectionPoolGroup = s_MicrosoftDotData.GetType("Microsoft.Data.SqlClient.ConnectionPool.DbConnectionPoolGroup"); + private static Type s_dbConnectionPoolIdentity = s_MicrosoftDotData.GetType("Microsoft.Data.SqlClient.ConnectionPool.DbConnectionPoolIdentity"); private static Type s_dbConnectionFactory = s_MicrosoftDotData.GetType("Microsoft.Data.ProviderBase.DbConnectionFactory"); private static Type s_sqlConnectionFactory = s_MicrosoftDotData.GetType("Microsoft.Data.SqlClient.SqlConnectionFactory"); - private static Type s_dbConnectionPoolKey = s_MicrosoftDotData.GetType("Microsoft.Data.Common.DbConnectionPoolKey"); + private static Type s_dbConnectionPoolKey = s_MicrosoftDotData.GetType("Microsoft.Data.SqlClient.ConnectionPool.DbConnectionPoolKey"); private static Type s_dictStringPoolGroup = typeof(Dictionary<,>).MakeGenericType(s_dbConnectionPoolKey, s_dbConnectionPoolGroup); private static Type s_dictPoolIdentityPool = typeof(ConcurrentDictionary<,>).MakeGenericType(s_dbConnectionPoolIdentity, s_dbConnectionPool); - private static PropertyInfo s_dbConnectionPoolCount = s_dbConnectionPool.GetProperty("Count", BindingFlags.Instance | BindingFlags.NonPublic); + private static PropertyInfo s_dbConnectionPoolCount = s_waitHandleDbConnectionPool.GetProperty("Count", BindingFlags.Instance | BindingFlags.NonPublic); private static PropertyInfo s_dictStringPoolGroupGetKeys = s_dictStringPoolGroup.GetProperty("Keys"); private static PropertyInfo s_dictPoolIdentityPoolValues = s_dictPoolIdentityPool.GetProperty("Values"); private static FieldInfo s_dbConnectionFactoryPoolGroupList = s_dbConnectionFactory.GetField("_connectionPoolGroups", BindingFlags.Instance | BindingFlags.NonPublic); private static FieldInfo s_dbConnectionPoolGroupPoolCollection = s_dbConnectionPoolGroup.GetField("_poolCollection", BindingFlags.Instance | BindingFlags.NonPublic); private static FieldInfo s_sqlConnectionFactorySingleton = s_sqlConnectionFactory.GetField("SingletonInstance", BindingFlags.Static | BindingFlags.Public); - private static FieldInfo s_dbConnectionPoolStackOld = s_dbConnectionPool.GetField("_stackOld", BindingFlags.Instance | BindingFlags.NonPublic); - private static FieldInfo s_dbConnectionPoolStackNew = s_dbConnectionPool.GetField("_stackNew", BindingFlags.Instance | BindingFlags.NonPublic); - private static MethodInfo s_dbConnectionPoolCleanup = s_dbConnectionPool.GetMethod("CleanupCallback", BindingFlags.Instance | BindingFlags.NonPublic); + private static FieldInfo s_dbConnectionPoolStackOld = s_waitHandleDbConnectionPool.GetField("_stackOld", BindingFlags.Instance | BindingFlags.NonPublic); + private static FieldInfo s_dbConnectionPoolStackNew = s_waitHandleDbConnectionPool.GetField("_stackNew", BindingFlags.Instance | BindingFlags.NonPublic); + private static MethodInfo s_dbConnectionPoolCleanup = s_waitHandleDbConnectionPool.GetMethod("CleanupCallback", BindingFlags.Instance | BindingFlags.NonPublic); private static MethodInfo s_dictStringPoolGroupTryGetValue = s_dictStringPoolGroup.GetMethod("TryGetValue"); public static int CountFreeConnections(object pool) From b7a321e10e04f756c36683718eea3e65fec82212 Mon Sep 17 00:00:00 2001 From: Malcolm Daigle Date: Thu, 6 Mar 2025 14:38:55 -0800 Subject: [PATCH 9/9] Address review comments --- .../Data/SqlClient/SqlConnectionFactory.cs | 2 +- .../Data/SqlClient/SqlConnectionHelper.cs | 2 +- .../Data/ProviderBase/DbConnectionFactory.cs | 2 +- .../ConnectionPool/DbConnectionPool.cs | 100 +++------- .../WaitHandleDbConnectionPool.cs | 174 +++++++----------- 5 files changed, 92 insertions(+), 188 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs index 9383b8e6af..d9bf71b663 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs @@ -11,8 +11,8 @@ using System.Runtime.Versioning; using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; -using Microsoft.Data.SqlClient.Server; using Microsoft.Data.SqlClient.ConnectionPool; +using Microsoft.Data.SqlClient.Server; namespace Microsoft.Data.SqlClient { diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs index 40a12d4976..9f8ddb7930 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionHelper.cs @@ -10,10 +10,10 @@ namespace Microsoft.Data.SqlClient using System.Diagnostics; using System.Runtime.ConstrainedExecution; using System.Threading; + using System.Transactions; using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; using Microsoft.Data.SqlClient.ConnectionPool; - using System.Transactions; public sealed partial class SqlConnection : DbConnection { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs index 0e60dd2138..f357e6109b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs @@ -578,7 +578,7 @@ private void PruneConnectionPoolGroups(object state) if (0 == pool.Count) { _poolsToRelease.Remove(pool); - SqlClientEventSource.Log.TryAdvancedTraceEvent(" {0}, ReleasePool={1}", ObjectID, pool.ObjectID); + SqlClientEventSource.Log.TryAdvancedTraceEvent(" {0}, ReleasePool={1}", ObjectID, pool.ObjectId); #if NETFRAMEWORK PerformanceCounters.NumberOfInactiveConnectionPools.Decrement(); #else diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPool.cs index 1c9475d8f0..a4efd25d2c 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPool.cs @@ -14,85 +14,37 @@ namespace Microsoft.Data.SqlClient.ConnectionPool { internal abstract class DbConnectionPool { - private static int _objectTypeCount; // EventSource counter - internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); - - internal int ObjectID - { - get - { - return _objectID; - } - } - - private DbConnectionPoolState _state; - internal DbConnectionPoolState State - { - get => _state; - set => _state = value; - } + private static int _objectTypeCount; + + internal int ObjectId { get; } = System.Threading.Interlocked.Increment(ref _objectTypeCount); + + internal DbConnectionPoolState State { get; set; } #region Abstract Properties - internal abstract int Count - { - get; - } - - internal abstract DbConnectionFactory ConnectionFactory - { - get; - } - - internal abstract bool ErrorOccurred - { - get; - } - - internal abstract TimeSpan LoadBalanceTimeout - { - get; - } - - internal abstract DbConnectionPoolIdentity Identity - { - get; - } - - internal abstract bool IsRunning - { - get; - } + internal abstract int Count { get; } + + internal abstract DbConnectionFactory ConnectionFactory { get; } + + internal abstract bool ErrorOccurred { get; } + + internal abstract TimeSpan LoadBalanceTimeout { get; } + + internal abstract DbConnectionPoolIdentity Identity { get; } + + internal abstract bool IsRunning { get; } #if NETFRAMEWORK - internal abstract DbConnectionPoolCounters PerformanceCounters - { - get; - } + internal abstract DbConnectionPoolCounters PerformanceCounters { get; } #endif - internal abstract DbConnectionPoolGroup PoolGroup - { - get; - } - - internal abstract DbConnectionPoolGroupOptions PoolGroupOptions - { - get; - } - - internal abstract DbConnectionPoolProviderInfo ProviderInfo - { - get; - } - - internal abstract ConcurrentDictionary AuthenticationContexts - { - get; - } - - internal abstract bool UseLoadBalancing - { - get; - } + internal abstract DbConnectionPoolGroup PoolGroup { get; } + + internal abstract DbConnectionPoolGroupOptions PoolGroupOptions { get; } + + internal abstract DbConnectionPoolProviderInfo ProviderInfo { get; } + + internal abstract ConcurrentDictionary AuthenticationContexts { get; } + + internal abstract bool UseLoadBalancing { get; } #endregion #region Abstract Methods diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/WaitHandleDbConnectionPool.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/WaitHandleDbConnectionPool.cs index a278fce5de..8dd1a7d745 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/WaitHandleDbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/WaitHandleDbConnectionPool.cs @@ -71,7 +71,7 @@ internal TransactedConnectionPool(DbConnectionPool pool) _pool = pool; _transactedCxns = new Dictionary(); - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Constructed for connection pool {1}", ObjectID, _pool.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Constructed for connection pool {1}", ObjectID, _pool.ObjectId); } internal int ObjectID @@ -450,7 +450,7 @@ internal WaitHandleDbConnectionPool( _poolCreateRequest = new WaitCallback(PoolCreateRequest); // used by CleanupCallback State = Running; - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Constructed.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Constructed.", ObjectId); //_cleanupTimer & QueuePoolCreateRequest is delayed until DbConnectionPoolGroup calls // StartBackgroundCallbacks after pool is actually in the collection @@ -461,36 +461,21 @@ private int CreationTimeout get { return PoolGroupOptions.CreationTimeout; } } - internal override int Count - { - get { return _totalObjects; } - } + internal override int Count => _totalObjects; - internal override DbConnectionFactory ConnectionFactory - { - get { return _connectionFactory; } - } + internal override DbConnectionFactory ConnectionFactory => _connectionFactory; - internal override bool ErrorOccurred - { - get { return _errorOccurred; } - } + internal override bool ErrorOccurred => _errorOccurred; - private bool HasTransactionAffinity - { - get { return PoolGroupOptions.HasTransactionAffinity; } - } + private bool HasTransactionAffinity => PoolGroupOptions.HasTransactionAffinity; - internal override TimeSpan LoadBalanceTimeout - { - get { return PoolGroupOptions.LoadBalanceTimeout; } - } + internal override TimeSpan LoadBalanceTimeout => PoolGroupOptions.LoadBalanceTimeout; private bool NeedToReplenish { get { - if (State != Running) // Don't allow connection create when not running. + if (State is not Running) // Don't allow connection create when not running. return false; int totalObjects = Count; @@ -509,68 +494,35 @@ private bool NeedToReplenish } } - internal override DbConnectionPoolIdentity Identity - { - get { return _identity; } - } + internal override DbConnectionPoolIdentity Identity => _identity; internal override bool IsRunning { - get { return State == Running; } + get { return State is Running; } } - private int MaxPoolSize - { - get { return PoolGroupOptions.MaxPoolSize; } - } + private int MaxPoolSize => PoolGroupOptions.MaxPoolSize; - private int MinPoolSize - { - get { return PoolGroupOptions.MinPoolSize; } - } + private int MinPoolSize => PoolGroupOptions.MinPoolSize; #if NETFRAMEWORK - internal override DbConnectionPoolCounters PerformanceCounters - { - get { return _connectionFactory.PerformanceCounters; } - } + internal override DbConnectionPoolCounters PerformanceCounters => _connectionFactory.PerformanceCounters; #endif - internal override DbConnectionPoolGroup PoolGroup - { - get { return _connectionPoolGroup; } - } + internal override DbConnectionPoolGroup PoolGroup => _connectionPoolGroup; - internal override DbConnectionPoolGroupOptions PoolGroupOptions - { - get { return _connectionPoolGroupOptions; } - } + internal override DbConnectionPoolGroupOptions PoolGroupOptions => _connectionPoolGroupOptions; - internal override DbConnectionPoolProviderInfo ProviderInfo - { - get { return _connectionPoolProviderInfo; } - } + internal override DbConnectionPoolProviderInfo ProviderInfo => _connectionPoolProviderInfo; /// /// Return the pooled authentication contexts. /// - internal override ConcurrentDictionary AuthenticationContexts - { - get - { - return _pooledDbAuthenticationContexts; - } - } + internal override ConcurrentDictionary AuthenticationContexts => _pooledDbAuthenticationContexts; - internal override bool UseLoadBalancing - { - get { return PoolGroupOptions.UseLoadBalancing; } - } + internal override bool UseLoadBalancing => PoolGroupOptions.UseLoadBalancing; - private bool UsingIntegrateSecurity - { - get { return _identity != null && DbConnectionPoolIdentity.NoIdentity != _identity; } - } + private bool UsingIntegrateSecurity => _identity != null && DbConnectionPoolIdentity.NoIdentity != _identity; private void CleanupCallback(object state) { @@ -592,7 +544,7 @@ private void CleanupCallback(object state) // // With this logic, objects are pruned from the pool if unused for // at least one period but not more than two periods. - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}", ObjectId); // Destroy free objects that put us above MinPoolSize from old stack. while (Count > MinPoolSize) @@ -670,7 +622,7 @@ private void CleanupCallback(object state) break; Debug.Assert(obj != null, "null connection is not expected"); - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, ChangeStacks={1}", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, ChangeStacks={1}", ObjectId, obj.ObjectID); Debug.Assert(!obj.IsEmancipated, "pooled object not in pool"); Debug.Assert(obj.CanBePooled, "pooled object is not poolable"); @@ -685,7 +637,7 @@ private void CleanupCallback(object state) internal override void Clear() { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Clearing.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Clearing.", ObjectId); DbConnectionInternal obj; // First, quickly doom everything. @@ -729,7 +681,7 @@ internal override void Clear() // Finally, reclaim everything that's emancipated (which, because // it's been doomed, will cause it to be disposed of as well) ReclaimEmancipatedObjects(); - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Cleared.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Cleared.", ObjectId); } private Timer CreateCleanupTimer() => @@ -804,7 +756,7 @@ private DbConnectionInternal CreateObject(DbConnection owningObject, DbConnectio #endif } - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Added to pool.", ObjectID, newObj?.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Added to pool.", ObjectId, newObj?.ObjectID); // Reset the error wait: _errorWait = ERROR_WAIT_DEFAULT; @@ -875,7 +827,7 @@ private DbConnectionInternal CreateObject(DbConnection owningObject, DbConnectio private void DeactivateObject(DbConnectionInternal obj) { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Deactivating.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Deactivating.", ObjectId, obj.ObjectID); obj.DeactivateConnection(); bool returnToGeneralPool = false; @@ -891,7 +843,7 @@ private void DeactivateObject(DbConnectionInternal obj) { // NOTE: constructor should ensure that current state cannot be State.Initializing, so it can only // be State.Running or State.ShuttingDown - Debug.Assert(State == Running || State == ShuttingDown); + Debug.Assert(State is Running or ShuttingDown); lock (obj) { @@ -901,7 +853,7 @@ private void DeactivateObject(DbConnectionInternal obj) // transaction object will ensure that it is owned (not lost), // and it will be certain to put it back into the pool. - if (State == ShuttingDown) + if (State is ShuttingDown) { if (obj.IsTransactionRoot) { @@ -1013,11 +965,11 @@ internal override void DestroyObject(DbConnectionInternal obj) // again. if (obj.IsTxRootWaitingForTxEnd) { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Has Delegated Transaction, waiting to Dispose.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Has Delegated Transaction, waiting to Dispose.", ObjectId, obj.ObjectID); } else { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Removing from pool.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Removing from pool.", ObjectId, obj.ObjectID); bool removed = false; lock (_objectList) { @@ -1028,7 +980,7 @@ internal override void DestroyObject(DbConnectionInternal obj) if (removed) { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Removed from pool.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Removed from pool.", ObjectId, obj.ObjectID); #if NET SqlClientEventSource.Log.ExitPooledConnection(); #else @@ -1036,7 +988,7 @@ internal override void DestroyObject(DbConnectionInternal obj) #endif } obj.Dispose(); - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Disposed.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Disposed.", ObjectId, obj.ObjectID); #if NET SqlClientEventSource.Log.HardDisconnectRequest(); #else @@ -1047,7 +999,7 @@ internal override void DestroyObject(DbConnectionInternal obj) private void ErrorCallback(object state) { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Resetting Error handling.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Resetting Error handling.", ObjectId); _errorOccurred = false; _waitHandles.ErrorEvent.Reset(); @@ -1200,9 +1152,9 @@ internal override bool TryGetConnection(DbConnection owningObject, TaskCompletio allowCreate = true; } - if (State != Running) + if (State is not Running) { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, DbConnectionInternal State != Running.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, DbConnectionInternal State != Running.", ObjectId); connection = null; return true; } @@ -1250,7 +1202,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj #if NETFRAMEWORK PerformanceCounters.SoftConnectsPerSecond.Increment(); #endif - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Getting connection.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Getting connection.", ObjectId); // If automatic transaction enlistment is required, then we try to // get the connection from the transacted connection pool first. @@ -1293,19 +1245,19 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj switch (waitResult) { case WaitHandle.WaitTimeout: - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Wait timed out.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Wait timed out.", ObjectId); Interlocked.Decrement(ref _waitCount); connection = null; return false; case ERROR_HANDLE: // Throw the error that PoolCreateRequest stashed. - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Errors are set.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Errors are set.", ObjectId); Interlocked.Decrement(ref _waitCount); throw TryCloneCachedException(); case CREATION_HANDLE: - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Creating new connection.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Creating new connection.", ObjectId); try { obj = UserCreateRequest(owningObject, userOptions); @@ -1358,7 +1310,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj if ((obj != null) && (!obj.IsConnectionAlive())) { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, found dead and removed.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, found dead and removed.", ObjectId, obj.ObjectID); DestroyObject(obj); obj = null; // Setting to null in case creating a new object fails @@ -1371,7 +1323,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj #endif try { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Creating new connection.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Creating new connection.", ObjectId); obj = UserCreateRequest(owningObject, userOptions); } finally @@ -1382,7 +1334,7 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj else { // Timeout waiting for creation semaphore - return null - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Wait timed out.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Wait timed out.", ObjectId); connection = null; return false; } @@ -1391,22 +1343,22 @@ private bool TryGetConnection(DbConnection owningObject, uint waitForMultipleObj break; case WAIT_ABANDONED + SEMAPHORE_HANDLE: - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Semaphore handle abandonded.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Semaphore handle abandonded.", ObjectId); Interlocked.Decrement(ref _waitCount); throw new AbandonedMutexException(SEMAPHORE_HANDLE, _waitHandles.PoolSemaphore); case WAIT_ABANDONED + ERROR_HANDLE: - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Error handle abandonded.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Error handle abandonded.", ObjectId); Interlocked.Decrement(ref _waitCount); throw new AbandonedMutexException(ERROR_HANDLE, _waitHandles.ErrorEvent); case WAIT_ABANDONED + CREATION_HANDLE: - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Creation handle abandoned.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Creation handle abandoned.", ObjectId); Interlocked.Decrement(ref _waitCount); throw new AbandonedMutexException(CREATION_HANDLE, _waitHandles.CreationSemaphore); default: - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, WaitForMultipleObjects={1}", ObjectID, waitResult); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, WaitForMultipleObjects={1}", ObjectId, waitResult); Interlocked.Decrement(ref _waitCount); throw ADP.InternalError(ADP.InternalErrorCode.UnexpectedWaitAnyResult); } @@ -1471,7 +1423,7 @@ internal override DbConnectionInternal ReplaceConnection(DbConnection owningObje #if NETFRAMEWORK PerformanceCounters.SoftConnectsPerSecond.Increment(); #endif - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, replacing connection.", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, replacing connection.", ObjectId); DbConnectionInternal newConnection = UserCreateRequest(owningObject, userOptions, oldConnection); if (newConnection != null) @@ -1515,7 +1467,7 @@ private DbConnectionInternal GetFromGeneralPool() if (obj != null) { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Popped from general pool.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Popped from general pool.", ObjectId, obj.ObjectID); #if NET SqlClientEventSource.Log.ExitFreeConnection(); #else @@ -1536,7 +1488,7 @@ private DbConnectionInternal GetFromTransactedPool(out Transaction transaction) if (obj != null) { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Popped from transacted pool.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Popped from transacted pool.", ObjectId, obj.ObjectID); #if NET SqlClientEventSource.Log.ExitFreeConnection(); #else @@ -1551,14 +1503,14 @@ private DbConnectionInternal GetFromTransactedPool(out Transaction transaction) } catch { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, found dead and removed.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, found dead and removed.", ObjectId, obj.ObjectID); DestroyObject(obj); throw; } } else if (!obj.IsConnectionAlive()) { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, found dead and removed.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, found dead and removed.", ObjectId, obj.ObjectID); DestroyObject(obj); obj = null; } @@ -1575,10 +1527,10 @@ private void PoolCreateRequest(object state) { // called by pooler to ensure pool requests are currently being satisfied - // creation mutex has not been obtained - long scopeID = SqlClientEventSource.Log.TryPoolerScopeEnterEvent(" {0}", ObjectID); + long scopeID = SqlClientEventSource.Log.TryPoolerScopeEnterEvent(" {0}", ObjectId); try { - if (State == Running) + if (State is Running) { // in case WaitForPendingOpen ever failed with no subsequent OpenAsync calls, // start it back up again @@ -1669,7 +1621,7 @@ private void PoolCreateRequest(object state) else { // trace waitResult and ignore the failure - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, PoolCreateRequest called WaitForSingleObject failed {1}", ObjectID, waitResult); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, PoolCreateRequest called WaitForSingleObject failed {1}", ObjectId, waitResult); } } catch (Exception e) @@ -1682,7 +1634,7 @@ private void PoolCreateRequest(object state) // Now that CreateObject can throw, we need to catch the exception and discard it. // There is no further action we can take beyond tracing. The error will be // thrown to the user the next time they request a connection. - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, PoolCreateRequest called CreateConnection which threw an exception: {1}", ObjectID, e); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, PoolCreateRequest called CreateConnection which threw an exception: {1}", ObjectId, e); } finally { @@ -1706,7 +1658,7 @@ internal override void PutNewObject(DbConnectionInternal obj) { Debug.Assert(obj != null, "why are we adding a null object to the pool?"); - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Pushing to general pool.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Pushing to general pool.", ObjectId, obj.ObjectID); _stackNew.Push(obj); _waitHandles.PoolSemaphore.Release(1); @@ -1765,9 +1717,9 @@ internal override void PutObjectFromTransactedPool(DbConnectionInternal obj) // method, we can safely presume that the caller is the only person // that is using the connection, and that all pre-push logic has been // done and all transactions are ended. - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Transaction has ended.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Transaction has ended.", ObjectId, obj.ObjectID); - if (State == Running && obj.CanBePooled) + if (State is Running && obj.CanBePooled) { PutNewObject(obj); } @@ -1780,7 +1732,7 @@ internal override void PutObjectFromTransactedPool(DbConnectionInternal obj) private void QueuePoolCreateRequest() { - if (State == Running) + if (State is Running) { // Make sure we're at quota by posting a callback to the threadpool. ThreadPool.QueueUserWorkItem(_poolCreateRequest); @@ -1790,7 +1742,7 @@ private void QueuePoolCreateRequest() private bool ReclaimEmancipatedObjects() { bool emancipatedObjectFound = false; - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}", ObjectId); List reclaimedObjects = new List(); int count; @@ -1842,7 +1794,7 @@ private bool ReclaimEmancipatedObjects() for (int i = 0; i < count; ++i) { DbConnectionInternal obj = reclaimedObjects[i]; - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Reclaiming.", ObjectID, obj.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Connection {1}, Reclaiming.", ObjectId, obj.ObjectID); #if NET SqlClientEventSource.Log.ReclaimedConnectionRequest(); #else @@ -1859,7 +1811,7 @@ private bool ReclaimEmancipatedObjects() internal override void Startup() { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, CleanupWait={1}", ObjectID, _cleanupWait); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, CleanupWait={1}", ObjectId, _cleanupWait); _cleanupTimer = CreateCleanupTimer(); if (NeedToReplenish) @@ -1870,7 +1822,7 @@ internal override void Startup() internal override void Shutdown() { - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}", ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}", ObjectId); State = ShuttingDown; // deactivate timer callbacks @@ -1892,7 +1844,7 @@ internal override void TransactionEnded(Transaction transaction, DbConnectionInt Debug.Assert(transactedObject != null, "null transactedObject?"); // Note: connection may still be associated with transaction due to Explicit Unbinding requirement. - SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Transaction {1}, Connection {2}, Transaction Completed", ObjectID, transaction.GetHashCode(), transactedObject.ObjectID); + SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Transaction {1}, Connection {2}, Transaction Completed", ObjectId, transaction.GetHashCode(), transactedObject.ObjectID); // called by the internal connection when it get's told that the // transaction is completed. We tell the transacted pool to remove