Skip to content

Commit

Permalink
Titus: change retry interceptor behavior to retry all the time on fin…
Browse files Browse the repository at this point in the history
…d and get methods and not on other methods like set or create
  • Loading branch information
tomaslin committed Mar 26, 2018
1 parent 8c205de commit 57cd99d
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import io.grpc.internal.SharedResourceHolder;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
Expand Down Expand Up @@ -67,7 +64,6 @@ private class RetryingCall<ReqT, RespT> extends ClientCall<ReqT, RespT> {
private int retries = 0;
private long backOff = 100;
private int maxRetries = 8;
private final Set<Status.Code> retryOnStatuses = new HashSet<>(Arrays.asList(Status.Code.UNAVAILABLE, Status.Code.RESOURCE_EXHAUSTED, Status.Code.DEADLINE_EXCEEDED));

RetryingCall(MethodDescriptor<ReqT, RespT> method,
CallOptions callOptions, Channel channel, Context context) {
Expand Down Expand Up @@ -132,8 +128,9 @@ private void maybeRetry(AttemptListener attempt) {
return;
}

Status.Code code = status.getCode();
if (!retryOnStatuses.contains(code)) {
// retries all methods that start with find but nothing else
if (extractSimpleMethodName(method.getFullMethodName()).startsWith("find") ||
extractSimpleMethodName(method.getFullMethodName()).startsWith("get")) {
AttemptListener latest = latestResponse;
if (latest != null) {
useResponse(latest);
Expand Down Expand Up @@ -209,4 +206,9 @@ public void onReady() {
}
}
}

public static String extractSimpleMethodName(String fullMethodName) {
int pos = fullMethodName.indexOf("/");
return pos > -1 ? fullMethodName.substring(pos + 1) : fullMethodName;
}
}

0 comments on commit 57cd99d

Please sign in to comment.