4
4
using System . Linq ;
5
5
using System . Threading ;
6
6
using System . Threading . Tasks ;
7
- using MySql . Data . Protocol . Serialization ;
8
- using MySql . Data . Serialization ;
7
+ using MySql . Data . MySqlClient ;
8
+ using MySqlConnector . Protocol . Serialization ;
9
9
10
- namespace MySql . Data . MySqlClient
10
+ namespace MySqlConnector . Core
11
11
{
12
12
internal sealed class ConnectionPool
13
13
{
14
- public async Task < MySqlSession > GetSessionAsync ( MySqlConnection connection , IOBehavior ioBehavior , CancellationToken cancellationToken )
14
+ public async Task < ServerSession > GetSessionAsync ( MySqlConnection connection , IOBehavior ioBehavior , CancellationToken cancellationToken )
15
15
{
16
16
cancellationToken . ThrowIfCancellationRequested ( ) ;
17
17
@@ -33,7 +33,7 @@ public async Task<MySqlSession> GetSessionAsync(MySqlConnection connection, IOBe
33
33
try
34
34
{
35
35
// check for a waiting session
36
- MySqlSession session = null ;
36
+ ServerSession session = null ;
37
37
lock ( m_sessions )
38
38
{
39
39
if ( m_sessions . Count > 0 )
@@ -79,7 +79,7 @@ public async Task<MySqlSession> GetSessionAsync(MySqlConnection connection, IOBe
79
79
}
80
80
81
81
// create a new session
82
- session = new MySqlSession ( this , m_generation , Interlocked . Increment ( ref m_lastId ) ) ;
82
+ session = new ServerSession ( this , m_generation , Interlocked . Increment ( ref m_lastId ) ) ;
83
83
await session . ConnectAsync ( m_connectionSettings , m_loadBalancer , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
84
84
AdjustHostConnectionCount ( session , 1 ) ;
85
85
session . OwningConnection = new WeakReference < MySqlConnection > ( connection ) ;
@@ -94,7 +94,7 @@ public async Task<MySqlSession> GetSessionAsync(MySqlConnection connection, IOBe
94
94
}
95
95
}
96
96
97
- private bool SessionIsHealthy ( MySqlSession session )
97
+ private bool SessionIsHealthy ( ServerSession session )
98
98
{
99
99
if ( ! session . IsConnected )
100
100
return false ;
@@ -109,7 +109,7 @@ private bool SessionIsHealthy(MySqlSession session)
109
109
return true ;
110
110
}
111
111
112
- public void Return ( MySqlSession session )
112
+ public void Return ( ServerSession session )
113
113
{
114
114
try
115
115
{
@@ -150,13 +150,13 @@ public async Task ReapAsync(IOBehavior ioBehavior, CancellationToken cancellatio
150
150
}
151
151
152
152
/// <summary>
153
- /// Examines all the <see cref="MySqlSession "/> objects in <see cref="m_leasedSessions"/> to determine if any
153
+ /// Examines all the <see cref="ServerSession "/> objects in <see cref="m_leasedSessions"/> to determine if any
154
154
/// have an owning <see cref="MySqlConnection"/> that has been garbage-collected. If so, assumes that the connection
155
155
/// was not properly disposed and returns the session to the pool.
156
156
/// </summary>
157
157
private void RecoverLeakedSessions ( )
158
158
{
159
- var recoveredSessions = new List < MySqlSession > ( ) ;
159
+ var recoveredSessions = new List < ServerSession > ( ) ;
160
160
lock ( m_leasedSessions )
161
161
{
162
162
m_lastRecoveryTime = unchecked ( ( uint ) Environment . TickCount ) ;
@@ -170,7 +170,7 @@ private void RecoverLeakedSessions()
170
170
session . ReturnToPool ( ) ;
171
171
}
172
172
173
- private async Task CleanPoolAsync ( IOBehavior ioBehavior , Func < MySqlSession , bool > shouldCleanFn , bool respectMinPoolSize , CancellationToken cancellationToken )
173
+ private async Task CleanPoolAsync ( IOBehavior ioBehavior , Func < ServerSession , bool > shouldCleanFn , bool respectMinPoolSize , CancellationToken cancellationToken )
174
174
{
175
175
// synchronize access to this method as only one clean routine should be run at a time
176
176
if ( ioBehavior == IOBehavior . Asynchronous )
@@ -204,7 +204,7 @@ private async Task CleanPoolAsync(IOBehavior ioBehavior, Func<MySqlSession, bool
204
204
try
205
205
{
206
206
// check for a waiting session
207
- MySqlSession session = null ;
207
+ ServerSession session = null ;
208
208
lock ( m_sessions )
209
209
{
210
210
if ( m_sessions . Count > 0 )
@@ -267,7 +267,7 @@ private async Task CreateMinimumPooledSessions(IOBehavior ioBehavior, Cancellati
267
267
268
268
try
269
269
{
270
- var session = new MySqlSession ( this , m_generation , Interlocked . Increment ( ref m_lastId ) ) ;
270
+ var session = new ServerSession ( this , m_generation , Interlocked . Increment ( ref m_lastId ) ) ;
271
271
await session . ConnectAsync ( m_connectionSettings , m_loadBalancer , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
272
272
AdjustHostConnectionCount ( session , 1 ) ;
273
273
lock ( m_sessions )
@@ -313,8 +313,8 @@ private ConnectionPool(ConnectionSettings cs)
313
313
m_generation = 0 ;
314
314
m_cleanSemaphore = new SemaphoreSlim ( 1 ) ;
315
315
m_sessionSemaphore = new SemaphoreSlim ( cs . MaximumPoolSize ) ;
316
- m_sessions = new LinkedList < MySqlSession > ( ) ;
317
- m_leasedSessions = new Dictionary < int , MySqlSession > ( ) ;
316
+ m_sessions = new LinkedList < ServerSession > ( ) ;
317
+ m_leasedSessions = new Dictionary < int , ServerSession > ( ) ;
318
318
if ( cs . LoadBalance == MySqlLoadBalance . FewestConnections )
319
319
{
320
320
m_hostSessions = new Dictionary < string , int > ( ) ;
@@ -328,7 +328,7 @@ private ConnectionPool(ConnectionSettings cs)
328
328
( ILoadBalancer ) new RoundRobinLoadBalancer ( ) ;
329
329
}
330
330
331
- private void AdjustHostConnectionCount ( MySqlSession session , int delta )
331
+ private void AdjustHostConnectionCount ( ServerSession session , int delta )
332
332
{
333
333
if ( m_hostSessions != null )
334
334
{
@@ -375,9 +375,9 @@ public IEnumerable<string> LoadBalance(IReadOnlyList<string> hosts)
375
375
int m_generation ;
376
376
readonly SemaphoreSlim m_cleanSemaphore ;
377
377
readonly SemaphoreSlim m_sessionSemaphore ;
378
- readonly LinkedList < MySqlSession > m_sessions ;
378
+ readonly LinkedList < ServerSession > m_sessions ;
379
379
readonly ConnectionSettings m_connectionSettings ;
380
- readonly Dictionary < int , MySqlSession > m_leasedSessions ;
380
+ readonly Dictionary < int , ServerSession > m_leasedSessions ;
381
381
readonly ILoadBalancer m_loadBalancer ;
382
382
readonly Dictionary < string , int > m_hostSessions ;
383
383
int m_lastId ;
0 commit comments