This is an automated email from the ASF dual-hosted git repository.

siddteotia pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new e8a8684e2d Improve the retry policy so that the thread doesn't sleep 
after the last failure (#9158)
e8a8684e2d is described below

commit e8a8684e2de9a3536203f6c448408552be2ded64
Author: Jia Guo <jia...@linkedin.com>
AuthorDate: Thu Aug 4 00:06:31 2022 -0700

    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
---
 .../org/apache/pinot/spi/utils/retry/BaseRetryPolicy.java    | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git 
a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/retry/BaseRetryPolicy.java 
b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/retry/BaseRetryPolicy.java
index 416aa41d16..17d1ac9d38 100644
--- 
a/pinot-spi/src/main/java/org/apache/pinot/spi/utils/retry/BaseRetryPolicy.java
+++ 
b/pinot-spi/src/main/java/org/apache/pinot/spi/utils/retry/BaseRetryPolicy.java
@@ -45,8 +45,8 @@ public abstract class BaseRetryPolicy implements RetryPolicy {
   public void attempt(Callable<Boolean> operation)
       throws AttemptsExceededException, RetriableOperationException {
     int attempt = 0;
-    while (attempt < _maxNumAttempts) {
-      try {
+    try {
+      while (attempt < _maxNumAttempts - 1) {
         if (Boolean.TRUE.equals(operation.call())) {
           // Succeeded
           return;
@@ -54,9 +54,13 @@ public abstract class BaseRetryPolicy implements RetryPolicy 
{
           // Failed
           Thread.sleep(getDelayMs(attempt++));
         }
-      } catch (Exception e) {
-        throw new RetriableOperationException(e);
       }
+      if (_maxNumAttempts > 0 && Boolean.TRUE.equals(operation.call())) {
+        // Succeeded
+        return;
+      }
+    } catch (Exception e) {
+      throw new RetriableOperationException(e);
     }
     throw new AttemptsExceededException("Operation failed after " + 
_maxNumAttempts + " attempts");
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to