Skip to content

Commit

Permalink
sdk/java: ensure the client retry timespan exceeds leader election
Browse files Browse the repository at this point in the history
Leader election could potentially take 15secs. We need
to ensure the client retry logic takes this into account.

Closes #726
  • Loading branch information
boymanjor authored and iampogo committed Mar 8, 2017
1 parent 85eff5c commit 8a09678
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sdk/java/src/main/java/com/chain/http/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,17 @@ private OkHttpClient buildHttpClient(Builder builder) {
private static final Random randomGenerator = new Random();
private static final int MAX_RETRIES = 10;
private static final int RETRY_BASE_DELAY_MILLIS = 40;
private static final int RETRY_MAX_DELAY_MILLIS = 4000;

// the max amount of time cored leader election could take
private static final int RETRY_MAX_DELAY_MILLIS = 15000;

private static int retryDelayMillis(int retryAttempt) {
// Calculate the max delay as base * 2 ^ (retryAttempt - 1).
int max = RETRY_BASE_DELAY_MILLIS * (1 << (retryAttempt - 1));
max = Math.min(max, RETRY_MAX_DELAY_MILLIS);

// To incorporate jitter, use a pseudorandom delay between [1, max] millis.
return randomGenerator.nextInt(max) + 1;
// To incorporate jitter, use a pseudo random delay between [max/2, max] millis.
return randomGenerator.nextInt(max / 2) + max / 2 + 1;
}

private static final int[] RETRIABLE_STATUS_CODES = {
Expand Down

0 comments on commit 8a09678

Please sign in to comment.