Class BackoffPolicy

java.lang.Object
org.elasticsearch.action.bulk.BackoffPolicy
All Implemented Interfaces:
Iterable<org.elasticsearch.core.TimeValue>

public abstract class BackoffPolicy extends Object implements Iterable<org.elasticsearch.core.TimeValue>
Provides a backoff policy for bulk requests. Whenever a bulk request is rejected due to resource constraints (i.e. the client's internal thread pool is full), the backoff policy decides how long the bulk processor will wait before the operation is retried internally. Notes for implementing custom subclasses: The underlying mathematical principle of BackoffPolicy are progressions which can be either finite or infinite although the latter should not be used for retrying. A progression can be mapped to a java.util.Iterator with the following semantics:
  • #hasNext() determines whether the progression has more elements. Return true for infinite progressions
  • #next() determines the next element in the progression, i.e. the next wait time period
Note that backoff policies are exposed as Iterables in order to be consumed multiple times.
  • Constructor Details

    • BackoffPolicy

      public BackoffPolicy()
  • Method Details

    • noBackoff

      public static BackoffPolicy noBackoff()
      Creates a backoff policy that will not allow any backoff, i.e. an operation will fail after the first attempt.
      Returns:
      A backoff policy without any backoff period. The returned instance is thread safe.
    • constantBackoff

      public static BackoffPolicy constantBackoff(org.elasticsearch.core.TimeValue delay, int maxNumberOfRetries)
      Creates an new constant backoff policy with the provided configuration.
      Parameters:
      delay - The delay defines how long to wait between retry attempts. Must not be null. Must be <= Integer.MAX_VALUE ms.
      maxNumberOfRetries - The maximum number of retries. Must be a non-negative number.
      Returns:
      A backoff policy with a constant wait time between retries. The returned instance is thread safe but each iterator created from it should only be used by a single thread.
    • exponentialBackoff

      public static BackoffPolicy exponentialBackoff()
      Creates an new exponential backoff policy with a default configuration of 50 ms initial wait period and 8 retries taking roughly 5.1 seconds in total.
      Returns:
      A backoff policy with an exponential increase in wait time for retries. The returned instance is thread safe but each iterator created from it should only be used by a single thread.
    • exponentialBackoff

      public static BackoffPolicy exponentialBackoff(org.elasticsearch.core.TimeValue initialDelay, int maxNumberOfRetries)
      Creates an new exponential backoff policy with the provided configuration.
      Parameters:
      initialDelay - The initial delay defines how long to wait for the first retry attempt. Must not be null. Must be <= Integer.MAX_VALUE ms.
      maxNumberOfRetries - The maximum number of retries. Must be a non-negative number.
      Returns:
      A backoff policy with an exponential increase in wait time for retries. The returned instance is thread safe but each iterator created from it should only be used by a single thread.
    • wrap

      public static BackoffPolicy wrap(BackoffPolicy delegate, Runnable onBackoff)
      Wraps the backoff policy in one that calls a method every time a new backoff is taken from the policy.