Skip to content

Commit

Permalink
SNOW-1629635 fix connection pool allocation (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mhofman authored Sep 23, 2024
1 parent aef4d3a commit 77410c7
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 251 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ConnectionMultiplePoolsAsyncIT: SFBaseTestAsync
[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ClearAllPools();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ConnectionMultiplePoolsIT: SFBaseTest
[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ClearAllPools();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ConnectionPoolChangedSessionIT : SFBaseTest
public static void BeforeAllTests()
{
s_previousPoolConfigRestorer = new PoolConfig();
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
}

[SetUp]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ConnectionPoolCommonIT(ConnectionPoolType connectionPoolTypeUnderTest)
[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(_connectionPoolTypeUnderTest);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(_connectionPoolTypeUnderTest);
SnowflakeDbConnectionPool.ClearAllPools();
if (_connectionPoolTypeUnderTest == ConnectionPoolType.SingleConnectionCache)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ConnectionSinglePoolCacheAsyncIT: SFBaseTestAsync
[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SnowflakeDbConnectionPool.ClearAllPools();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ConnectionSinglePoolCacheIT: SFBaseTest
[SetUp]
public new void BeforeTest()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SnowflakeDbConnectionPool.ClearAllPools();
SnowflakeDbConnectionPool.SetPooling(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ConnectionCacheManagerTest
public static void BeforeAllTests()
{
s_poolConfig = new PoolConfig();
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
SessionPool.SessionFactory = new MockSessionFactory();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ConnectionPoolManagerTest
public static void BeforeAllTests()
{
s_poolConfig = new PoolConfig();
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SessionPool.SessionFactory = new MockSessionFactory();
}

Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/Util/PoolConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public PoolConfig()

public void Reset()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(_connectionPoolType);
SnowflakeDbConnectionPool.ForceConnectionPoolVersion(_connectionPoolType);
if (_connectionPoolType == ConnectionPoolType.MultipleConnectionPool)
return; // for multiple connection pool setting parameters for all the pools doesn't work by design
SnowflakeDbConnectionPool.SetMaxPoolSize(_maxPoolSize);
Expand Down
15 changes: 12 additions & 3 deletions Snowflake.Data/Client/SnowflakeDbConnectionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Snowflake.Data.Core;
using Snowflake.Data.Core.Session;
using Snowflake.Data.Core.Tools;
using Snowflake.Data.Log;

namespace Snowflake.Data.Client
Expand All @@ -25,7 +26,7 @@ private static IConnectionManager ConnectionManager
{
if (s_connectionManager != null)
return s_connectionManager;
SetConnectionPoolVersion(DefaultConnectionPoolType);
SetConnectionPoolVersion(DefaultConnectionPoolType, false);
return s_connectionManager;
}
}
Expand Down Expand Up @@ -122,13 +123,16 @@ public static bool GetPooling()

public static void SetOldConnectionPoolVersion()
{
SetConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
ForceConnectionPoolVersion(ConnectionPoolType.SingleConnectionCache);
}

internal static void SetConnectionPoolVersion(ConnectionPoolType requestedPoolType)
private static void SetConnectionPoolVersion(ConnectionPoolType requestedPoolType, bool force)
{
lock (s_connectionManagerInstanceLock)
{
if (s_connectionManager != null && !force)
return;
Diagnostics.LogDiagnostics();
s_connectionManager?.ClearAllPools();
if (requestedPoolType == ConnectionPoolType.MultipleConnectionPool)
{
Expand All @@ -143,6 +147,11 @@ internal static void SetConnectionPoolVersion(ConnectionPoolType requestedPoolTy
}
}

internal static void ForceConnectionPoolVersion(ConnectionPoolType requestedPoolType)
{
SetConnectionPoolVersion(requestedPoolType, true);
}

internal static ConnectionPoolType GetConnectionPoolVersion()
{
if (ConnectionManager != null)
Expand Down
Loading

0 comments on commit 77410c7

Please sign in to comment.