HBASE-19641 AsyncHBaseAdmin should use exponential backoff when polling the procedure result

This commit is contained in:
zhangduo 2018-01-03 16:41:21 +08:00
parent a47afc84cd
commit 1fa3637b4d
1 changed files with 27 additions and 30 deletions

View File

@ -89,6 +89,7 @@ import org.apache.hbase.thirdparty.com.google.protobuf.RpcCallback;
import org.apache.hbase.thirdparty.io.netty.util.HashedWheelTimer; import org.apache.hbase.thirdparty.io.netty.util.HashedWheelTimer;
import org.apache.hbase.thirdparty.io.netty.util.Timeout; import org.apache.hbase.thirdparty.io.netty.util.Timeout;
import org.apache.hbase.thirdparty.io.netty.util.TimerTask; import org.apache.hbase.thirdparty.io.netty.util.TimerTask;
import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter; import org.apache.hadoop.hbase.shaded.protobuf.RequestConverter;
import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService; import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService;
@ -2553,31 +2554,27 @@ class RawAsyncHBaseAdmin implements AsyncAdmin {
future.completeExceptionally(error); future.completeExceptionally(error);
return; return;
} }
getProcedureResult(procId, future); getProcedureResult(procId, future, 0);
}); });
return future; return future;
} }
private void getProcedureResult(final long procId, CompletableFuture<Void> future) { private void getProcedureResult(long procId, CompletableFuture<Void> future, int retries) {
this.<GetProcedureResultResponse> newMasterCaller() this.<GetProcedureResultResponse> newMasterCaller().action((controller, stub) -> this
.action(
(controller, stub) -> this
.<GetProcedureResultRequest, GetProcedureResultResponse, GetProcedureResultResponse> call( .<GetProcedureResultRequest, GetProcedureResultResponse, GetProcedureResultResponse> call(
controller, stub, GetProcedureResultRequest.newBuilder().setProcId(procId).build(), controller, stub, GetProcedureResultRequest.newBuilder().setProcId(procId).build(),
(s, c, req, done) -> s.getProcedureResult(c, req, done), (resp) -> resp)) (s, c, req, done) -> s.getProcedureResult(c, req, done), (resp) -> resp))
.call() .call().whenComplete((response, error) -> {
.whenComplete(
(response, error) -> {
if (error != null) { if (error != null) {
LOG.warn("failed to get the procedure result procId=" + procId, LOG.warn("failed to get the procedure result procId={}", procId,
ConnectionUtils.translateException(error)); ConnectionUtils.translateException(error));
retryTimer.newTimeout(t -> getProcedureResult(procId, future), pauseNs, retryTimer.newTimeout(t -> getProcedureResult(procId, future, retries + 1),
TimeUnit.NANOSECONDS); ConnectionUtils.getPauseTime(pauseNs, retries), TimeUnit.NANOSECONDS);
return; return;
} }
if (response.getState() == GetProcedureResultResponse.State.RUNNING) { if (response.getState() == GetProcedureResultResponse.State.RUNNING) {
retryTimer.newTimeout(t -> getProcedureResult(procId, future), pauseNs, retryTimer.newTimeout(t -> getProcedureResult(procId, future, retries + 1),
TimeUnit.NANOSECONDS); ConnectionUtils.getPauseTime(pauseNs, retries), TimeUnit.NANOSECONDS);
return; return;
} }
if (response.hasException()) { if (response.hasException()) {