From 7fa7a104761b3609a10bb41e57d423b90360a1d8 Mon Sep 17 00:00:00 2001 From: XmasApple Date: Wed, 1 Nov 2023 20:12:03 +0300 Subject: [PATCH] More logs on retry --- src/Ydb.Sdk/src/Services/Query/QueryClient.cs | 2 +- .../src/Services/Shared/SessionPool.cs | 33 ++++++++----------- src/Ydb.Sdk/src/Services/Table/Retry.cs | 2 +- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/Ydb.Sdk/src/Services/Query/QueryClient.cs b/src/Ydb.Sdk/src/Services/Query/QueryClient.cs index 38533cb9..1b129e8e 100644 --- a/src/Ydb.Sdk/src/Services/Query/QueryClient.cs +++ b/src/Ydb.Sdk/src/Services/Query/QueryClient.cs @@ -535,7 +535,7 @@ private async Task ExecOnSession( $"Unexpected cast error: {nameof(_sessionPool)} is not object of type {typeof(SessionPool).FullName}"); } - return await sessionPool.ExecOnSession(func, retrySettings); + return await sessionPool.ExecWithRetry(func, retrySettings); } public async Task> Query(string queryString, Dictionary parameters, diff --git a/src/Ydb.Sdk/src/Services/Shared/SessionPool.cs b/src/Ydb.Sdk/src/Services/Shared/SessionPool.cs index 7774989d..82e8641b 100644 --- a/src/Ydb.Sdk/src/Services/Shared/SessionPool.cs +++ b/src/Ydb.Sdk/src/Services/Shared/SessionPool.cs @@ -199,7 +199,7 @@ private void Dispose(bool disposing) } } - internal async Task ExecOnSession( + internal async Task ExecWithRetry( Func> func, RetrySettings? retrySettings) { @@ -225,41 +225,34 @@ internal async Task ExecOnSession( if (session is not null) { - var funcResponse = await func(session); - if (funcResponse.Status.IsSuccess) + response = await func(session); + if (response.Status.IsSuccess) { - ReturnSession(session.Id); - session = null; - return funcResponse; + return response; } - - response = funcResponse; } var retryRule = retrySettings.GetRetryRule(response.Status.StatusCode); - if (session is not null) + if (session is not null && retryRule.DeleteSession) { - if (retryRule.DeleteSession) - { - Logger.LogTrace($"Retry: Session ${session.Id} invalid, disposing"); - InvalidateSession(session.Id); - } - else - { - ReturnSession(session.Id); - } + Logger.LogTrace($"Retry: attempt {attempt}, Session ${session.Id} invalid, disposing"); + InvalidateSession(session.Id); + session = null; } if (retryRule.Idempotency == Idempotency.Idempotent && retrySettings.IsIdempotent || retryRule.Idempotency == Idempotency.NonIdempotent) { Logger.LogTrace( - $"Retry: Session ${session?.Id}, " + - $"idempotent error {response.Status.StatusCode} retrying "); + $"Retry: attempt {attempt}, Session ${session?.Id}, " + + $"idempotent error {response.Status} retrying"); await Task.Delay(retryRule.BackoffSettings.CalcBackoff(attempt)); } else { + Logger.LogTrace( + $"Retry: attempt {attempt}, Session ${session?.Id}, " + + $"not idempotent error {response.Status}"); return response; } } diff --git a/src/Ydb.Sdk/src/Services/Table/Retry.cs b/src/Ydb.Sdk/src/Services/Table/Retry.cs index 2f45c85f..79ac666a 100644 --- a/src/Ydb.Sdk/src/Services/Table/Retry.cs +++ b/src/Ydb.Sdk/src/Services/Table/Retry.cs @@ -14,6 +14,6 @@ public async Task SessionExec( $"Unexpected cast error: {nameof(_sessionPool)} is not object of type {typeof(SessionPool).FullName}"); } - return await sessionPool.ExecOnSession(operationFunc, retrySettings); + return await sessionPool.ExecWithRetry(operationFunc, retrySettings); } } \ No newline at end of file