From 56798890d0735e83124bea57fbb59316ee9e2708 Mon Sep 17 00:00:00 2001 From: XmasApple Date: Thu, 28 Sep 2023 17:19:54 +0300 Subject: [PATCH 1/3] Make SessionPoolConfig properties public --- src/Ydb.Sdk/src/Services/Table/SessionPool.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Ydb.Sdk/src/Services/Table/SessionPool.cs b/src/Ydb.Sdk/src/Services/Table/SessionPool.cs index cf4c0115..111b2a8d 100644 --- a/src/Ydb.Sdk/src/Services/Table/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Table/SessionPool.cs @@ -6,17 +6,25 @@ namespace Ydb.Sdk.Services.Table; public class SessionPoolConfig { public SessionPoolConfig( - uint? sizeLimit = null) + uint? sizeLimit = null, + TimeSpan? keepAliveIdleThreshold = null, + TimeSpan? periodicCheckInterval = null, + TimeSpan? keepAliveTimeout = null, + TimeSpan? createSessionTimeout = null + ) { SizeLimit = sizeLimit ?? 100; + KeepAliveIdleThreshold = keepAliveIdleThreshold ?? TimeSpan.FromMinutes(5); + PeriodicCheckInterval = periodicCheckInterval ?? TimeSpan.FromSeconds(10); + KeepAliveTimeout = keepAliveTimeout ?? TimeSpan.FromSeconds(1); + CreateSessionTimeout = createSessionTimeout ?? TimeSpan.FromSeconds(1); } public uint SizeLimit { get; } - - internal TimeSpan KeepAliveIdleThreshold { get; } = TimeSpan.FromMinutes(5); - internal TimeSpan PeriodicCheckInterval { get; } = TimeSpan.FromSeconds(10); - internal TimeSpan KeepAliveTimeout { get; } = TimeSpan.FromSeconds(1); - internal TimeSpan CreateSessionTimeout { get; } = TimeSpan.FromSeconds(1); + public TimeSpan KeepAliveIdleThreshold { get; } + public TimeSpan PeriodicCheckInterval { get; } + public TimeSpan KeepAliveTimeout { get; } + public TimeSpan CreateSessionTimeout { get; } } internal class GetSessionResponse : ResponseWithResultBase, IDisposable From 1264518aa71ff4bd8aca6cffe925d0c4c2499b84 Mon Sep 17 00:00:00 2001 From: XmasApple Date: Thu, 28 Sep 2023 17:26:29 +0300 Subject: [PATCH 2/3] Add retry to GetSession in SessionPool.cs --- src/Ydb.Sdk/src/Services/Table/SessionPool.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Ydb.Sdk/src/Services/Table/SessionPool.cs b/src/Ydb.Sdk/src/Services/Table/SessionPool.cs index 111b2a8d..2edf7fd1 100644 --- a/src/Ydb.Sdk/src/Services/Table/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Table/SessionPool.cs @@ -91,6 +91,20 @@ public SessionPool(Driver driver, SessionPoolConfig config) } public async Task GetSession() + { + const int maxAttempts = 100; + + GetSessionResponse getSessionResponse = null!; + for (var attempt = 0; attempt < maxAttempts; attempt++) + { + getSessionResponse = await GetSessionAttempt(); + } + + _logger.LogError($"Failed to get session from pool or create it (attempts: {maxAttempts})"); + return getSessionResponse; + } + + private async Task GetSessionAttempt() { lock (_lock) { From 808410d72148002dc288b7ce182595e9f38844c4 Mon Sep 17 00:00:00 2001 From: XmasApple Date: Thu, 28 Sep 2023 17:35:44 +0300 Subject: [PATCH 3/3] Add leave condition to getSession retryer --- src/Ydb.Sdk/src/Services/Table/SessionPool.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Ydb.Sdk/src/Services/Table/SessionPool.cs b/src/Ydb.Sdk/src/Services/Table/SessionPool.cs index 2edf7fd1..667fc112 100644 --- a/src/Ydb.Sdk/src/Services/Table/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Table/SessionPool.cs @@ -98,6 +98,7 @@ public async Task GetSession() for (var attempt = 0; attempt < maxAttempts; attempt++) { getSessionResponse = await GetSessionAttempt(); + if (getSessionResponse.Status.IsSuccess) return getSessionResponse; } _logger.LogError($"Failed to get session from pool or create it (attempts: {maxAttempts})");