Skip to content
Open
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
9 changes: 0 additions & 9 deletions src/Npgsql/NpgsqlConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,6 @@ void GetPoolAndSettings()
var newPool = new ConnectorPool(Settings, canonical);
_pool = PoolManager.GetOrAdd(canonical, newPool);

// If the pool we created was the one that ended up being stored we need to increment the appropriate counter.
// Avoids a race condition where multiple threads will create a pool but only one will be stored.
if (_pool == newPool)
{
// If the pool we created was the one that ended up being stored we need to increment the appropriate counter.
// Avoids a race condition where multiple threads will create a pool but only one will be stored.
NpgsqlEventSource.Log.PoolCreated(newPool);
}

_pool = PoolManager.GetOrAdd(_connectionString, _pool);
}

Expand Down
8 changes: 8 additions & 0 deletions src/Npgsql/NpgsqlEventSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ internal void PoolCreated(ConnectorPool pool)
}
}

internal void PoolDeleted(ConnectorPool pool)
{
lock (_poolsLock)
{
_pools.Remove(pool);
}
}

internal void MultiplexingBatchSent(int numCommands, int waits, Stopwatch stopwatch)
{
// TODO: CAS loop instead of 4 separate interlocked operations?
Expand Down
14 changes: 13 additions & 1 deletion src/Npgsql/PoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ internal static ConnectorPool GetOrAdd(string key, ConnectorPool pool)
_pools[_nextSlot].Key = key;
_pools[_nextSlot].Pool = pool;
Interlocked.Increment(ref _nextSlot);

NpgsqlEventSource.Log.PoolCreated(pool);

return pool;
}
}
Expand Down Expand Up @@ -110,7 +113,9 @@ internal static void Delete(ConnectorPool pool)

Interlocked.Decrement(ref _nextSlot);
_pools = newPools;
}

NpgsqlEventSource.Log.PoolDeleted(pool);
}
}

internal static void Clear(string connString)
Expand Down Expand Up @@ -151,6 +156,13 @@ internal static void Reset()
lock (Lock)
{
ClearAll();
var pools = _pools;
foreach (var (_, pool) in pools)
{
if (pool != null)
NpgsqlEventSource.Log.PoolDeleted(pool);
}

_pools = new (string, ConnectorPool)[InitialPoolsSize];
_nextSlot = 0;
}
Expand Down