Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pool/SNOW-1353952 GetPool interface [WIP] #935

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Snowflake.Data/Client/SnowflakeDbConnectionPool.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
* Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
*/

using System;
Expand Down Expand Up @@ -42,6 +42,12 @@ internal static Task<SFSession> GetSessionAsync(string connectionString, SecureS
return ConnectionManager.GetSessionAsync(connectionString, password, cancellationToken);
}

public static SnowflakeDbSessionPool GetPool(string connectionString, SecureString password)
{
s_logger.Debug($"SnowflakeDbConnectionPool::GetPool");
return new SnowflakeDbSessionPool(ConnectionManager.GetPool(connectionString, password));
}

internal static SessionPool GetPool(string connectionString)
{
s_logger.Debug($"SnowflakeDbConnectionPool::GetPool");
Expand Down
28 changes: 28 additions & 0 deletions Snowflake.Data/Client/SnowflakeDbSessionPool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Snowflake Computing Inc. All rights reserved.
*/
using System;
using Snowflake.Data.Core.Session;

namespace Snowflake.Data.Client
{
public class SnowflakeDbSessionPool : IDisposable
{
private SessionPool _sessionPool;

internal SnowflakeDbSessionPool(SessionPool sessionPool)
=> _sessionPool = sessionPool ?? throw new NullReferenceException("SessionPool not provided!");
public void Dispose() => _sessionPool = null;

public void SetMaxPoolSize(int size) => _sessionPool.SetMaxPoolSize(size);
public int GetMaxPoolSize() => _sessionPool.GetMaxPoolSize();

public void SetTimeout(long seconds) => _sessionPool.SetTimeout(seconds);
public long GetTimeout() => _sessionPool.GetTimeout();

public int GetCurrentPoolSize() => _sessionPool.GetCurrentPoolSize();

public bool SetPooling(bool isEnable) => _sessionPool.SetPooling(isEnable);
public bool GetPooling() => _sessionPool.GetPooling();
}
}
3 changes: 2 additions & 1 deletion Snowflake.Data/Core/Session/ConnectionCacheManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
* Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
*/

using System.Security;
Expand All @@ -25,5 +25,6 @@ public Task<SFSession> GetSessionAsync(string connectionString, SecureString pas
public bool SetPooling(bool poolingEnabled) => _sessionPool.SetPooling(poolingEnabled);
public bool GetPooling() => _sessionPool.GetPooling();
public SessionPool GetPool(string _) => _sessionPool;
public SessionPool GetPool(string _, SecureString __) => _sessionPool;
}
}
9 changes: 7 additions & 2 deletions Snowflake.Data/Core/Session/ConnectionPoolManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
* Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
*/

using System;
Expand Down Expand Up @@ -119,7 +119,7 @@ public bool GetPooling()
return true; // in new pool pooling is always enabled by default, disabling only by connection string parameter
}

internal SessionPool GetPool(string connectionString, SecureString password)
public SessionPool GetPool(string connectionString, SecureString password)
{
s_logger.Debug($"ConnectionPoolManager::GetPool");
var poolKey = GetPoolKey(connectionString);
Expand All @@ -140,6 +140,11 @@ internal SessionPool GetPool(string connectionString, SecureString password)
public SessionPool GetPool(string connectionString)
{
s_logger.Debug($"ConnectionPoolManager::GetPool");
if (!connectionString.ToLower().Contains("password="))
{
s_logger.Error($"To obtain a pool a password must to be given with a connection string or SecureString parameter");
throw new SnowflakeDbException(SFError.MISSING_CONNECTION_PROPERTY, "Could not provide the pool without the password");
}
return GetPool(connectionString, null);
}

Expand Down
3 changes: 2 additions & 1 deletion Snowflake.Data/Core/Session/IConnectionManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
* Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
*/

using System.Security;
Expand All @@ -23,5 +23,6 @@ internal interface IConnectionManager
bool SetPooling(bool poolingEnabled);
bool GetPooling();
SessionPool GetPool(string connectionString);
SessionPool GetPool(string connectionString, SecureString password);
}
}
Loading