Skip to content

Commit

Permalink
More logs on retry
Browse files Browse the repository at this point in the history
  • Loading branch information
XmasApple committed Nov 1, 2023
1 parent 221b25a commit 7fa7a10
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Ydb.Sdk/src/Services/Query/QueryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ private async Task<IResponse> 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<QueryResponseWithResult<T>> Query<T>(string queryString, Dictionary<string, YdbValue> parameters,
Expand Down
33 changes: 13 additions & 20 deletions src/Ydb.Sdk/src/Services/Shared/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void Dispose(bool disposing)
}
}

internal async Task<IResponse> ExecOnSession(
internal async Task<IResponse> ExecWithRetry(
Func<TSession, Task<IResponse>> func,
RetrySettings? retrySettings)
{
Expand All @@ -225,41 +225,34 @@ internal async Task<IResponse> 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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ydb.Sdk/src/Services/Table/Retry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public async Task<IResponse> 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);
}
}

0 comments on commit 7fa7a10

Please sign in to comment.