Skip to content

Commit

Permalink
changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-knozderko committed Apr 10, 2024
1 parent 8656584 commit b765c1b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ CancellationTokenSource cancellationTokenSource = new CancellationTokenSource()
Evict the Connection
--------------------

For the open connection, call the `PreventPooling()` to make the connection not return to the pool.
For the open connection, call the `PreventPooling()` to mark the connection to be removed on close instead being still pooled.
The busy sessions counter will be decreased when the connection is closed.

Logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void TestFailWhenPreventingFromReturningToPoolNotOpenedConnection()
var thrown = Assert.Throws<Exception>(() => connection.PreventPooling());

// assert
Assert.That(thrown.Message, Does.Contain("Connection is not ready to prevent its session from returning to the pool"));
Assert.That(thrown.Message, Does.Contain("Session not yet created for this connection. Unable to prevent the session from pooling"));
}
}
}
7 changes: 4 additions & 3 deletions Snowflake.Data/Client/SnowflakeDbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ public void PreventPooling()
throw new Exception("Session not yet created for this connection. Unable to prevent the session from pooling");
}
SfSession.SetPooling(false);
logger.Debug($"Session {SfSession.sessionId} marked not to be pooled any more");
}

internal bool HasActiveExplicitTransaction() => ExplicitTransaction != null && ExplicitTransaction.IsActive;

private bool ReleaseOrReturnSessionToPool()
private bool TryToReturnSessionToPool()
{
var pooling = SnowflakeDbConnectionPool.GetPooling() && SfSession.GetPooling();
var transactionRollbackStatus = pooling ? TerminateTransactionForDirtyConnectionReturningToPool() : TransactionRollbackStatus.Undefined;
Expand Down Expand Up @@ -178,7 +179,7 @@ public override void Close()
logger.Debug("Close Connection.");
if (IsNonClosedWithSession())
{
var returnedToPool = ReleaseOrReturnSessionToPool();
var returnedToPool = TryToReturnSessionToPool();
if (!returnedToPool)
{
SfSession.close();
Expand Down Expand Up @@ -210,7 +211,7 @@ public virtual Task CloseAsync(CancellationToken cancellationToken)
{
if (IsNonClosedWithSession())
{
var returnedToPool = ReleaseOrReturnSessionToPool();
var returnedToPool = TryToReturnSessionToPool();
if (returnedToPool)
{
_connectionState = ConnectionState.Closed;
Expand Down
7 changes: 7 additions & 0 deletions Snowflake.Data/Core/Session/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,17 @@ private Task<SFSession> NewSessionAsync(String connectionString, SecureString pa
internal void ReleaseBusySession(SFSession session)
{
s_logger.Debug("SessionPool::ReleaseBusySession");
int currentPoolSize;
lock (_sessionPoolLock)
{
_busySessionsCounter.Decrease();
currentPoolSize = GetCurrentPoolSize();
}
var currentSizeMessageOldPool = $"After releasing a busy session from the pool, the pool size is: {currentPoolSize}";
var poolSizeMessage = IsMultiplePoolsVersion()
? $"{currentSizeMessageOldPool} - pool identified by: {ConnectionString}"
: currentSizeMessageOldPool;
s_logger.Debug(poolSizeMessage);
}

internal bool AddSession(SFSession session, bool ensureMinPoolSize)
Expand Down

0 comments on commit b765c1b

Please sign in to comment.