Skip to content

Commit

Permalink
Fix retry logic (#182)
Browse files Browse the repository at this point in the history
Add retry logic to GetMasterLeaderInfoAsync()

These methods were affected,
 - GetHiveMetastoreConfigAsync
 - GetLocationAsync
 - GetClusterIdAsync
 - ExportAuthenticationCredentialsAsync
 - FindLeaderMasterServerAsync (only used by tests)

Fixes a regression introduced by #166

This PR also optimizes SendRpcToMasterAsync() and
SendRpcToTxnManagerAsync().
  • Loading branch information
xqrzd authored Sep 18, 2021
1 parent 4866fd2 commit 34537c0
Showing 1 changed file with 44 additions and 15 deletions.
59 changes: 44 additions & 15 deletions src/Knet.Kudu.Client/KuduClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,15 @@ private ValueTask<MasterLeaderInfo> GetMasterLeaderInfoAsync(
return new ValueTask<MasterLeaderInfo>(masterLeaderInfo);
}

var task = ConnectToClusterAsync(cancellationToken);
var task = ConnectAsync(cancellationToken);
return new ValueTask<MasterLeaderInfo>(task);

async Task<MasterLeaderInfo> ConnectAsync(CancellationToken cancellationToken)
{
var rpc = new ConnectToMasterRequest();
await SendRpcAsync(rpc, cancellationToken).ConfigureAwait(false);
return _masterLeaderInfo;
}
}

/// <summary>
Expand Down Expand Up @@ -1431,7 +1438,7 @@ internal async Task<T> SendRpcAsync<T>(
{
KuduMasterRpc<T> masterRpc => SendRpcToMasterAsync(masterRpc, token),
KuduTabletRpc<T> tabletRpc => SendRpcToTabletAsync(tabletRpc, token),
KuduTxnRpc<T> txnRpc => SendRpcToTxnAsync(txnRpc, token),
KuduTxnRpc<T> txnRpc => SendRpcToTxnManagerAsync(txnRpc, token),
_ => throw new NotSupportedException()
};

Expand Down Expand Up @@ -1485,28 +1492,50 @@ private void CompleteTrackedRpc(KuduRpc rpc)
}
}

private async Task<T> SendRpcToMasterAsync<T>(
private Task<T> SendRpcToMasterAsync<T>(
KuduMasterRpc<T> rpc, CancellationToken cancellationToken)
{
var masterLeaderInfo = await GetMasterLeaderInfoAsync(cancellationToken)
.ConfigureAwait(false);
var masterLeaderInfo = _masterLeaderInfo;
if (masterLeaderInfo is not null)
{
var serverInfo = masterLeaderInfo.ServerInfo;
return SendRpcToMasterAsync(rpc, serverInfo, cancellationToken);
}

var serverInfo = masterLeaderInfo.ServerInfo;
return SendAsync(rpc, cancellationToken);

return await SendRpcToMasterAsync(rpc, serverInfo, cancellationToken)
.ConfigureAwait(false);
async Task<T> SendAsync(KuduMasterRpc<T> rpc, CancellationToken cancellationToken)
{
var masterLeaderInfo = await ConnectToClusterAsync(cancellationToken)
.ConfigureAwait(false);

var serverInfo = masterLeaderInfo.ServerInfo;
return await SendRpcToMasterAsync(rpc, serverInfo, cancellationToken)
.ConfigureAwait(false);
}
}

private async Task<T> SendRpcToTxnAsync<T>(
private Task<T> SendRpcToTxnManagerAsync<T>(
KuduTxnRpc<T> rpc, CancellationToken cancellationToken)
{
var masterLeaderInfo = await GetMasterLeaderInfoAsync(cancellationToken)
.ConfigureAwait(false);
var masterLeaderInfo = _masterLeaderInfo;
if (masterLeaderInfo is not null)
{
var serverInfo = masterLeaderInfo.ServerInfo;
return SendRpcToTxnManagerAsync(rpc, serverInfo, cancellationToken);
}

var serverInfo = masterLeaderInfo.ServerInfo;
return SendAsync(rpc, cancellationToken);

return await SendRpcToTxnAsync(rpc, serverInfo, cancellationToken)
.ConfigureAwait(false);
async Task<T> SendAsync(KuduTxnRpc<T> rpc, CancellationToken cancellationToken)
{
var masterLeaderInfo = await ConnectToClusterAsync(cancellationToken)
.ConfigureAwait(false);

var serverInfo = masterLeaderInfo.ServerInfo;
return await SendRpcToTxnManagerAsync(rpc, serverInfo, cancellationToken)
.ConfigureAwait(false);
}
}

/// <summary>
Expand Down Expand Up @@ -1617,7 +1646,7 @@ await SendRpcToServerGenericAsync(rpc, serverInfo, cancellationToken)
return rpc.Output;
}

private async Task<T> SendRpcToTxnAsync<T>(
private async Task<T> SendRpcToTxnManagerAsync<T>(
KuduTxnRpc<T> rpc,
ServerInfo serverInfo,
CancellationToken cancellationToken)
Expand Down

0 comments on commit 34537c0

Please sign in to comment.