Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public TimedAttemptSettings createFirstAttempt() {
.setRpcTimeout(globalSettings.getInitialRpcTimeout())
.setRandomizedRetryDelay(Duration.ZERO)
.setAttemptCount(0)
.setOverallAttemptCount(0)
.setFirstAttemptStartTimeNanos(clock.nanoTime())
.build();
}
Expand Down Expand Up @@ -113,6 +114,7 @@ public TimedAttemptSettings createNextAttempt(TimedAttemptSettings prevSettings)
.setRpcTimeout(Duration.ofMillis(newRpcTimeout))
.setRandomizedRetryDelay(Duration.ofMillis(nextRandomLong(newRetryDelay)))
.setAttemptCount(prevSettings.getAttemptCount() + 1)
.setOverallAttemptCount(prevSettings.getOverallAttemptCount() + 1)
.setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public TimedAttemptSettings createNextAttempt(
createFirstAttempt()
.toBuilder()
.setFirstAttemptStartTimeNanos(prevSettings.getFirstAttemptStartTimeNanos())
.setOverallAttemptCount(prevSettings.getOverallAttemptCount())
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,19 @@ public abstract class TimedAttemptSettings {
*/
public abstract Duration getRandomizedRetryDelay();

/** The attempt count. It is a zero-based value (first attempt will have this value set to 0). */
/**
* The attempt count. It is a zero-based value (first attempt will have this value set to 0). For
* streamed RPCs this will be reset after every successful message.
*/
public abstract int getAttemptCount();

/**
* The overall attempt count. It is a zero-based value (first attempt will have this value set to
* 0). This will be the sum of all attempt counts for a streaming RPC and will be equal to {@link
* #getAttemptCount()} for unary RPCs.
*/
public abstract int getOverallAttemptCount();

/**
* The start time of the first attempt. Note that this value is dependent on the actual {@link
* ApiClock} used during the process.
Expand All @@ -70,7 +80,7 @@ public abstract class TimedAttemptSettings {
public abstract Builder toBuilder();

public static Builder newBuilder() {
return new AutoValue_TimedAttemptSettings.Builder();
return new AutoValue_TimedAttemptSettings.Builder().setOverallAttemptCount(0);
}

@AutoValue.Builder
Expand Down Expand Up @@ -99,6 +109,12 @@ public abstract static class Builder {
*/
public abstract Builder setAttemptCount(int value);

/**
* Set the overall attempt count. It is a zero-based value (first attempt will have this value
* set to 0).
*/
public abstract Builder setOverallAttemptCount(int value);

/**
* Set the start time of the first attempt. Note that this value is dependent on the actual
* {@link ApiClock} used during the process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void testCreateFirstAttempt() {

// Checking only the most core values, to not make this test too implementation specific.
assertEquals(0, attempt.getAttemptCount());
assertEquals(0, attempt.getOverallAttemptCount());
assertEquals(Duration.ZERO, attempt.getRetryDelay());
assertEquals(Duration.ZERO, attempt.getRandomizedRetryDelay());
assertEquals(Duration.ofMillis(1L), attempt.getRpcTimeout());
Expand All @@ -76,6 +77,7 @@ public void testCreateNextAttempt() {

// Checking only the most core values, to not make this test too implementation specific.
assertEquals(1, secondAttempt.getAttemptCount());
assertEquals(1, secondAttempt.getOverallAttemptCount());
assertEquals(Duration.ofMillis(1L), secondAttempt.getRetryDelay());
assertEquals(Duration.ofMillis(1L), secondAttempt.getRandomizedRetryDelay());
assertEquals(Duration.ofMillis(2L), secondAttempt.getRpcTimeout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void setUp() {
TimedAttemptSettings.newBuilder()
.setGlobalSettings(RetrySettings.newBuilder().build())
.setAttemptCount(0)
.setOverallAttemptCount(0)
.setFirstAttemptStartTimeNanos(0)
.setRetryDelay(Duration.ofSeconds(1))
.setRandomizedRetryDelay(Duration.ofSeconds(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void setUp() {
TimedAttemptSettings.newBuilder()
.setGlobalSettings(RetrySettings.newBuilder().build())
.setAttemptCount(0)
.setOverallAttemptCount(0)
.setFirstAttemptStartTimeNanos(0)
.setRetryDelay(Duration.ofSeconds(1))
.setRandomizedRetryDelay(Duration.ofSeconds(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ private static class FakeRetryingFuture extends AbstractApiFuture<Void>
RetrySettings.newBuilder().setTotalTimeout(Duration.ofHours(1)).build())
.setFirstAttemptStartTimeNanos(0)
.setAttemptCount(0)
.setOverallAttemptCount(0)
.setRandomizedRetryDelay(Duration.ofMillis(1))
.setRetryDelay(Duration.ofMillis(1))
.setRpcTimeout(Duration.ofMinutes(1))
Expand Down