Skip to content

Commit

Permalink
[.NET SDK]: retry discovery task
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillKurdyukov committed Mar 4, 2024
1 parent 5122306 commit 311560f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/Ydb.Sdk/src/Driver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,31 @@ public async Task Initialize()

_logger.LogInformation("Started initial endpoint discovery");

try
var initializeStartTime = DateTime.Now;
var successDiscover = false;

while (initializeStartTime.Add(_config.DiscoveryTimout) < DateTime.Now)
{
var status = await DiscoverEndpoints();
if (!status.IsSuccess)
try
{
var status = await DiscoverEndpoints();
if (status.IsSuccess)
{
successDiscover = true;
break;
}

_logger.LogCritical($"Error during initial endpoint discovery: {status}");
}
catch (RpcException e)
{
var error = $"Error during initial endpoint discovery: {status}";
_logger.LogCritical(error);
throw new InitializationFailureException(error);
_logger.LogCritical($"RPC error during initial endpoint discovery: {e.Status}");
}
}
catch (RpcException e)

if (!successDiscover)
{
_logger.LogCritical($"RPC error during initial endpoint discovery: {e.Status}");
throw new InitializationFailureException("Failed to discover initial endpoints", e);
throw new InitializationFailureException("Error during initial endpoint discovery");
}

_ = Task.Run(PeriodicDiscovery);
Expand Down Expand Up @@ -227,7 +238,7 @@ private async Task PeriodicDiscovery()
try
{
await Task.Delay(_config.EndpointDiscoveryInterval);
var _ = await DiscoverEndpoints();
_ = await DiscoverEndpoints();
}
catch (RpcException e)
{
Expand Down
1 change: 1 addition & 0 deletions src/Ydb.Sdk/src/DriverConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class DriverConfig
internal TimeSpan EndpointDiscoveryInterval = TimeSpan.FromMinutes(1);
internal double PessimizedEndpointRatioTreshold = 0.5;
internal TimeSpan EndpointDiscoveryTimeout = TimeSpan.FromSeconds(10);
internal TimeSpan DiscoveryTimout = TimeSpan.FromSeconds(60);

public DriverConfig(
string endpoint,
Expand Down

0 comments on commit 311560f

Please sign in to comment.