Skip to content

Commit e8a8684

Browse files
authored
Improve the retry policy so that the thread doesn't sleep after the last failure (#9158)
* Improve the retry policy so that the thread don't sleep after the last failure * Improve the retry policy so that the thread don't sleep after the last failure * Improve the retry policy so that the thread don't sleep after the last failure
1 parent fb4966b commit e8a8684

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pinot-spi/src/main/java/org/apache/pinot/spi/utils/retry/BaseRetryPolicy.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,22 @@ protected BaseRetryPolicy(int maxNumAttempts) {
4545
public void attempt(Callable<Boolean> operation)
4646
throws AttemptsExceededException, RetriableOperationException {
4747
int attempt = 0;
48-
while (attempt < _maxNumAttempts) {
49-
try {
48+
try {
49+
while (attempt < _maxNumAttempts - 1) {
5050
if (Boolean.TRUE.equals(operation.call())) {
5151
// Succeeded
5252
return;
5353
} else {
5454
// Failed
5555
Thread.sleep(getDelayMs(attempt++));
5656
}
57-
} catch (Exception e) {
58-
throw new RetriableOperationException(e);
5957
}
58+
if (_maxNumAttempts > 0 && Boolean.TRUE.equals(operation.call())) {
59+
// Succeeded
60+
return;
61+
}
62+
} catch (Exception e) {
63+
throw new RetriableOperationException(e);
6064
}
6165
throw new AttemptsExceededException("Operation failed after " + _maxNumAttempts + " attempts");
6266
}

0 commit comments

Comments
 (0)