Package com.linkedin.venice.utils
Class RetryUtils
- java.lang.Object
-
- com.linkedin.venice.utils.RetryUtils
-
public class RetryUtils extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RetryUtils.IntermediateFailureHandler
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
executeWithMaxAttempt(VeniceCheckedRunnable runnable, int maxAttempt, java.time.Duration delay, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aRunnable
with fixed delay with a maximum attempt.static void
executeWithMaxAttempt(VeniceCheckedRunnable runnable, int maxAttempt, java.time.Duration delay, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes, RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
Execute aRunnable
with fixed delay with a maximum attempt.static <T> T
executeWithMaxAttempt(VeniceCheckedSupplier<T> supplier, int maxAttempt, java.time.Duration delay, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aSupplier
with fixed delay with a maximum attempt.static <T> T
executeWithMaxAttempt(VeniceCheckedSupplier<T> supplier, int maxAttempt, java.time.Duration delay, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes, RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
Execute aSupplier
with fixed delay with a maximum attempt.static void
executeWithMaxAttemptAndExponentialBackoff(VeniceCheckedRunnable runnable, int maxAttempt, java.time.Duration initialDelay, java.time.Duration maxDelay, java.time.Duration maxDuration, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aRunnable
with exponential backoff.static void
executeWithMaxAttemptAndExponentialBackoff(VeniceCheckedRunnable runnable, int maxAttempt, java.time.Duration initialDelay, java.time.Duration maxDelay, java.time.Duration maxDuration, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes, RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
Execute aRunnable
with exponential backoff.static <T> T
executeWithMaxAttemptAndExponentialBackoff(VeniceCheckedSupplier<T> supplier, int maxAttempt, java.time.Duration initialDelay, java.time.Duration maxDelay, java.time.Duration maxDuration, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aSupplier
with exponential backoff.static <T> T
executeWithMaxAttemptAndExponentialBackoff(VeniceCheckedSupplier<T> supplier, int maxAttempt, java.time.Duration initialDelay, java.time.Duration maxDelay, java.time.Duration maxDuration, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes, RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
Execute aSupplier
with exponential backoff.static void
executeWithMaxAttemptNoIntermediateLogging(VeniceCheckedRunnable runnable, int maxAttempt, java.time.Duration delay, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aRunnable
with fixed delay with a maximum attempt.static <T> T
executeWithMaxRetriesAndFixedAttemptDuration(VeniceCheckedSupplier<T> supplier, int maxRetry, java.time.Duration durationPerAttempt, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aSupplier
with maximum retries and fix duration per retry attempt.
-
-
-
Method Detail
-
executeWithMaxAttempt
public static void executeWithMaxAttempt(VeniceCheckedRunnable runnable, int maxAttempt, java.time.Duration delay, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aRunnable
with fixed delay with a maximum attempt. If all attempts are made and still no success, the last thrown exception will be thrown. This function logs the throwable that failed intermediate execution attempts.- Parameters:
runnable
- Execution unit which returns nothing (Void
)maxAttempt
- Total maximum attempts made before giving up. Value should be at least one.delay
- Fixed delay between retry attempts.retryFailureTypes
- Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
-
executeWithMaxAttemptNoIntermediateLogging
public static void executeWithMaxAttemptNoIntermediateLogging(VeniceCheckedRunnable runnable, int maxAttempt, java.time.Duration delay, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aRunnable
with fixed delay with a maximum attempt. If all attempts are made and still no success, the last thrown exception will be thrown. This function does not log the throwable that failed intermediate execution attempts.- Parameters:
runnable
- Execution unit which returns nothing (Void
)maxAttempt
- Total maximum attempts made before giving up. Value should be at least one.delay
- Fixed delay between retry attempts.retryFailureTypes
- Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
-
executeWithMaxAttempt
public static void executeWithMaxAttempt(VeniceCheckedRunnable runnable, int maxAttempt, java.time.Duration delay, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes, RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
Execute aRunnable
with fixed delay with a maximum attempt. If all attempts are made and still no success, the last thrown exception will be thrown.- Parameters:
runnable
- Execution unit which returns nothing (Void
)maxAttempt
- Total maximum attempts made before giving up. Value should be at least one.delay
- Fixed delay between retry attempts.retryFailureTypes
- Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.intermediateFailureHandler
- A handler for intermediate failure(s).
-
executeWithMaxAttemptAndExponentialBackoff
public static void executeWithMaxAttemptAndExponentialBackoff(VeniceCheckedRunnable runnable, int maxAttempt, java.time.Duration initialDelay, java.time.Duration maxDelay, java.time.Duration maxDuration, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aRunnable
with exponential backoff. If all attempts are made or the max duration has reached and still no success, the last thrown exception will be thrown. This function logs the throwable that failed intermediate execution attempts.- Parameters:
runnable
- Execution unit which returns nothing (Void
)maxAttempt
- Total maximum attempts made before giving up. Value should be at least one.initialDelay
- First delay duration.maxDelay
- Maximum delay duration.maxDuration
- Maximum total execution.retryFailureTypes
- Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
-
executeWithMaxAttemptAndExponentialBackoff
public static void executeWithMaxAttemptAndExponentialBackoff(VeniceCheckedRunnable runnable, int maxAttempt, java.time.Duration initialDelay, java.time.Duration maxDelay, java.time.Duration maxDuration, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes, RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
Execute aRunnable
with exponential backoff. If all attempts are made or the max duration has reached and still no success, the last thrown exception will be thrown.- Parameters:
runnable
- Execution unit which returns nothing (Void
)maxAttempt
- Total maximum attempts made before giving up. Value should be at least one.initialDelay
- First delay duration.maxDelay
- Maximum delay duration.maxDuration
- Maximum total execution.retryFailureTypes
- Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.intermediateFailureHandler
- A handler for intermediate failure(s).
-
executeWithMaxAttempt
public static <T> T executeWithMaxAttempt(VeniceCheckedSupplier<T> supplier, int maxAttempt, java.time.Duration delay, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aSupplier
with fixed delay with a maximum attempt. If all attempts are made and still no success, the last thrown exception will be thrown. This function logs the throwable that failed intermediate execution attempts.- Parameters:
supplier
- Execution unit which returns something (RetryUtils
)maxAttempt
- Total maximum attempts made before giving up. Value should be at least one.delay
- Fixed delay between retry attempts.retryFailureTypes
- Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
-
executeWithMaxAttempt
public static <T> T executeWithMaxAttempt(VeniceCheckedSupplier<T> supplier, int maxAttempt, java.time.Duration delay, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes, RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
Execute aSupplier
with fixed delay with a maximum attempt. If all attempts are made and still no success, the last thrown exception will be thrown.- Parameters:
supplier
- Execution unit which returns something (RetryUtils
)maxAttempt
- Total maximum attempts made before giving up. Value should be at least one.delay
- Fixed delay between retry attempts.retryFailureTypes
- Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.intermediateFailureHandler
- A handler for intermediate failure(s).
-
executeWithMaxAttemptAndExponentialBackoff
public static <T> T executeWithMaxAttemptAndExponentialBackoff(VeniceCheckedSupplier<T> supplier, int maxAttempt, java.time.Duration initialDelay, java.time.Duration maxDelay, java.time.Duration maxDuration, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aSupplier
with exponential backoff. If all attempts are made or the max duration has reached and still no success, the last thrown exception will be thrown. This function logs the throwable that failed intermediate execution attempts.- Parameters:
supplier
- Execution unit which returns something (RetryUtils
)maxAttempt
- Total maximum attempts made before giving up. Value should be at least one.initialDelay
- First delay duration.maxDelay
- Maximum delay duration.maxDuration
- Maximum total execution.retryFailureTypes
- Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it gets thrown to the caller.
-
executeWithMaxAttemptAndExponentialBackoff
public static <T> T executeWithMaxAttemptAndExponentialBackoff(VeniceCheckedSupplier<T> supplier, int maxAttempt, java.time.Duration initialDelay, java.time.Duration maxDelay, java.time.Duration maxDuration, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes, RetryUtils.IntermediateFailureHandler intermediateFailureHandler)
Execute aSupplier
with exponential backoff. If all attempts are made or the max duration has reached and still no success, the last thrown exception will be thrown.- Parameters:
supplier
- Execution unit which returns something (RetryUtils
)maxAttempt
- Total maximum attempts made before giving up. Value should be at least one.initialDelay
- First delay duration.maxDelay
- Maximum delay duration.maxDuration
- Maximum total execution.retryFailureTypes
- Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it get thrown to the caller.intermediateFailureHandler
- A handler for intermediate failure(s).
-
executeWithMaxRetriesAndFixedAttemptDuration
public static <T> T executeWithMaxRetriesAndFixedAttemptDuration(VeniceCheckedSupplier<T> supplier, int maxRetry, java.time.Duration durationPerAttempt, java.util.List<java.lang.Class<? extends java.lang.Throwable>> retryFailureTypes)
Execute aSupplier
with maximum retries and fix duration per retry attempt. If all attempts are made and still no success, the last thrown exception will be thrown.- Parameters:
supplier
- Execution unit which returns something (RetryUtils
)maxRetry
- Total maximum retries made before giving up.durationPerAttempt
- Total duration per attempt. The delay after attempt will be the (duration per attempt - time spent in the current attempt).retryFailureTypes
- Types of failures upon which retry attempt is made. If a failure with type not specified in this list is thrown, it is thrown to the caller.
-
-