Class RetryUtils
- java.lang.Object
-
- org.apache.druid.java.util.common.RetryUtils
-
public class RetryUtils extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RetryUtils.CleanupAfterFailure
static interface
RetryUtils.Task<T>
-
Field Summary
Fields Modifier and Type Field Description static long
BASE_SLEEP_MILLIS
static int
DEFAULT_MAX_TRIES
static Logger
log
static long
MAX_SLEEP_MILLIS
-
Constructor Summary
Constructors Constructor Description RetryUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
awaitNextRetry(Throwable e, String messageOnRetry, int nTry, int maxRetries, boolean quiet)
static long
nextRetrySleepMillis(int nTry)
static <T> T
retry(RetryUtils.Task<T> f, com.google.common.base.Predicate<Throwable> shouldRetry, int maxTries)
static <T> T
retry(RetryUtils.Task<T> f, com.google.common.base.Predicate<Throwable> shouldRetry, int quietTries, int maxTries)
static <T> T
retry(RetryUtils.Task<T> f, com.google.common.base.Predicate<Throwable> shouldRetry, int quietTries, int maxTries, RetryUtils.CleanupAfterFailure cleanupAfterFailure, String messageOnRetry)
Retry an operation using fuzzy exponentially increasing backoff.static <T> T
retry(RetryUtils.Task<T> f, com.google.common.base.Predicate<Throwable> shouldRetry, RetryUtils.CleanupAfterFailure onEachFailure, int maxTries, String messageOnRetry)
-
-
-
Field Detail
-
log
public static final Logger log
-
MAX_SLEEP_MILLIS
public static final long MAX_SLEEP_MILLIS
- See Also:
- Constant Field Values
-
BASE_SLEEP_MILLIS
public static final long BASE_SLEEP_MILLIS
- See Also:
- Constant Field Values
-
DEFAULT_MAX_TRIES
public static final int DEFAULT_MAX_TRIES
- See Also:
- Constant Field Values
-
-
Method Detail
-
retry
public static <T> T retry(RetryUtils.Task<T> f, com.google.common.base.Predicate<Throwable> shouldRetry, int quietTries, int maxTries, @Nullable RetryUtils.CleanupAfterFailure cleanupAfterFailure, @Nullable String messageOnRetry) throws Exception
Retry an operation using fuzzy exponentially increasing backoff. The wait time after the nth failed attempt is min(60000ms, 1000ms * pow(2, n - 1)), fuzzed by a number drawn from a Gaussian distribution with mean 0 and standard deviation 0.2. If maxTries is exhausted, or if shouldRetry returns false, the last exception thrown by "f" will be thrown by this function.- Parameters:
f
- the operationshouldRetry
- predicate determining whether we should retry after a particular exception thrown by "f"quietTries
- first quietTries attempts will log exceptions at DEBUG level rather than WARNmaxTries
- maximum number of attempts- Returns:
- result of the first successful operation
- Throws:
Exception
- if maxTries is exhausted, or shouldRetry returns false
-
retry
public static <T> T retry(RetryUtils.Task<T> f, com.google.common.base.Predicate<Throwable> shouldRetry, int maxTries) throws Exception
- Throws:
Exception
-
retry
public static <T> T retry(RetryUtils.Task<T> f, com.google.common.base.Predicate<Throwable> shouldRetry, int quietTries, int maxTries) throws Exception
- Throws:
Exception
-
retry
public static <T> T retry(RetryUtils.Task<T> f, com.google.common.base.Predicate<Throwable> shouldRetry, RetryUtils.CleanupAfterFailure onEachFailure, int maxTries, String messageOnRetry) throws Exception
- Throws:
Exception
-
awaitNextRetry
public static void awaitNextRetry(Throwable e, @Nullable String messageOnRetry, int nTry, int maxRetries, boolean quiet) throws InterruptedException
- Throws:
InterruptedException
-
nextRetrySleepMillis
public static long nextRetrySleepMillis(int nTry)
-
-