-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-902608 - new pool version implementation
- Loading branch information
1 parent
ceef6c4
commit 73bb45c
Showing
5 changed files
with
197 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. | ||
*/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Security; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Snowflake.Data.Log; | ||
|
||
namespace Snowflake.Data.Core.Session | ||
{ | ||
internal sealed class ConnectionManagerV2 : IConnectionManager | ||
{ | ||
private static readonly SFLogger s_logger = SFLoggerFactory.GetLogger<ConnectionManagerV2>(); | ||
private static readonly Object s_poolsLock = new Object(); | ||
private readonly Dictionary<string, SessionPool> _pools; | ||
|
||
internal ConnectionManagerV2() | ||
{ | ||
lock (s_poolsLock) | ||
{ | ||
_pools = new Dictionary<string, SessionPool>(); | ||
} | ||
} | ||
|
||
public SFSession GetSession(string connectionString, SecureString password) | ||
=> GetPool(connectionString, password).GetSession(); | ||
|
||
public Task<SFSession> GetSessionAsync(string connectionString, SecureString password, CancellationToken cancellationToken) | ||
=> GetPool(connectionString, password).GetSessionAsync(cancellationToken); | ||
|
||
public bool AddSession(SFSession session) | ||
=> GetPool(session.ConnectionString, session.Password).AddSession(session); | ||
|
||
public void ClearAllPools() | ||
{ | ||
foreach (var sessionPool in _pools.Values) | ||
{ | ||
sessionPool.ClearAllPools(); | ||
} | ||
} | ||
|
||
public void SetMaxPoolSize(int maxPoolSize) | ||
{ | ||
foreach (var pool in _pools.Values) | ||
{ | ||
pool.SetMaxPoolSize(maxPoolSize); | ||
} | ||
} | ||
|
||
public int GetMaxPoolSize() => throw ApiNotSupportedException(); | ||
|
||
public void SetTimeout(long connectionTimeout) | ||
{ | ||
foreach (var pool in _pools.Values) | ||
{ | ||
pool.SetTimeout(connectionTimeout); | ||
} | ||
} | ||
|
||
public long GetTimeout() => throw ApiNotSupportedException(); | ||
|
||
public int GetCurrentPoolSize() => throw ApiNotSupportedException(); | ||
|
||
public bool SetPooling(bool poolingEnabled) | ||
{ | ||
bool switched = true; | ||
foreach (var pool in _pools.Values) | ||
{ | ||
if (!pool.SetPooling(poolingEnabled)) | ||
switched = false; | ||
} | ||
return switched; | ||
} | ||
|
||
public bool GetPooling() => throw ApiNotSupportedException(); | ||
|
||
private NotSupportedException ApiNotSupportedException() | ||
{ | ||
var message = "Pool settings are controlled with connection string parameters or from a Session Pool object"; | ||
s_logger.Error(message); | ||
return new NotSupportedException(message); | ||
} | ||
|
||
internal SessionPool GetPool(string connectionString, SecureString password) | ||
{ | ||
var poolKey = GetPoolKey(connectionString); | ||
|
||
if (_pools.TryGetValue(poolKey, out var item)) | ||
return item; | ||
lock (s_poolsLock) | ||
{ | ||
var pool = SessionPool.CreateSessionPoolV2(connectionString, password); | ||
_pools.Add(poolKey, pool); | ||
return pool; | ||
} | ||
} | ||
|
||
// TODO: SNOW-937188 | ||
private string GetPoolKey(string connectionString) | ||
{ | ||
return connectionString; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.