Skip to content

Commit f09a8fe

Browse files
authored
Merge pull request #43 Session create fix
2 parents 5f82083 + 808410d commit f09a8fe

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

src/Ydb.Sdk/src/Services/Table/SessionPool.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,25 @@ namespace Ydb.Sdk.Services.Table;
66
public class SessionPoolConfig
77
{
88
public SessionPoolConfig(
9-
uint? sizeLimit = null)
9+
uint? sizeLimit = null,
10+
TimeSpan? keepAliveIdleThreshold = null,
11+
TimeSpan? periodicCheckInterval = null,
12+
TimeSpan? keepAliveTimeout = null,
13+
TimeSpan? createSessionTimeout = null
14+
)
1015
{
1116
SizeLimit = sizeLimit ?? 100;
17+
KeepAliveIdleThreshold = keepAliveIdleThreshold ?? TimeSpan.FromMinutes(5);
18+
PeriodicCheckInterval = periodicCheckInterval ?? TimeSpan.FromSeconds(10);
19+
KeepAliveTimeout = keepAliveTimeout ?? TimeSpan.FromSeconds(1);
20+
CreateSessionTimeout = createSessionTimeout ?? TimeSpan.FromSeconds(1);
1221
}
1322

1423
public uint SizeLimit { get; }
15-
16-
internal TimeSpan KeepAliveIdleThreshold { get; } = TimeSpan.FromMinutes(5);
17-
internal TimeSpan PeriodicCheckInterval { get; } = TimeSpan.FromSeconds(10);
18-
internal TimeSpan KeepAliveTimeout { get; } = TimeSpan.FromSeconds(1);
19-
internal TimeSpan CreateSessionTimeout { get; } = TimeSpan.FromSeconds(1);
24+
public TimeSpan KeepAliveIdleThreshold { get; }
25+
public TimeSpan PeriodicCheckInterval { get; }
26+
public TimeSpan KeepAliveTimeout { get; }
27+
public TimeSpan CreateSessionTimeout { get; }
2028
}
2129

2230
internal class GetSessionResponse : ResponseWithResultBase<Session>, IDisposable
@@ -83,6 +91,21 @@ public SessionPool(Driver driver, SessionPoolConfig config)
8391
}
8492

8593
public async Task<GetSessionResponse> GetSession()
94+
{
95+
const int maxAttempts = 100;
96+
97+
GetSessionResponse getSessionResponse = null!;
98+
for (var attempt = 0; attempt < maxAttempts; attempt++)
99+
{
100+
getSessionResponse = await GetSessionAttempt();
101+
if (getSessionResponse.Status.IsSuccess) return getSessionResponse;
102+
}
103+
104+
_logger.LogError($"Failed to get session from pool or create it (attempts: {maxAttempts})");
105+
return getSessionResponse;
106+
}
107+
108+
private async Task<GetSessionResponse> GetSessionAttempt()
86109
{
87110
lock (_lock)
88111
{

0 commit comments

Comments
 (0)