Record Class RetryPolicy

java.lang.Object
java.lang.Record
org.openspaces.core.multicluster.internal.health.RetryPolicy
Record Components:
maxAttempts - total attempts including the first, >= 1
initialBackoff - delay before the second attempt
maxBackoff - ceiling for the delay, however many attempts have failed
multiplier - factor applied per attempt, >= 1.0
jitter - fraction of the delay to randomise, 0.0 to 1.0

public record RetryPolicy(int maxAttempts, Duration initialBackoff, Duration maxBackoff, double multiplier, double jitter) extends Record
Exponential backoff with jitter, for retrying a mutation against a cluster that was briefly unavailable.

The jitter matters more than it looks. Without it, every client that lost the same cluster retries on exactly the same schedule, so the cluster comes back up into a synchronised thundering herd and falls over again. Spreading each delay randomly across a band breaks that lockstep.

  • Constructor Summary

    Constructors
    Constructor
    Description
    RetryPolicy(int maxAttempts, Duration initialBackoff, Duration maxBackoff, double multiplier, double jitter)
    Creates an instance of a RetryPolicy record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    backoffFor(int attempt)
    How long to wait before attempt number attempt (1-based, so backoffFor(1) is the pause after the first failure).
    Three attempts, 100 ms growing to 5 s, jittered by a fifth.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the initialBackoff record component.
    double
    Returns the value of the jitter record component.
    int
    Returns the value of the maxAttempts record component.
    Returns the value of the maxBackoff record component.
    double
    Returns the value of the multiplier record component.
    A policy that never retries - one attempt and done.
    A maintenance window's worth of patience: up to 60 attempts, 1 s growing to 30 s, jittered.
    boolean
    shouldRetry(int attemptsSoFar)
    Whether another attempt is allowed after attemptsSoFar have failed.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • RetryPolicy

      public RetryPolicy(int maxAttempts, Duration initialBackoff, Duration maxBackoff, double multiplier, double jitter)
      Creates an instance of a RetryPolicy record class.
      Parameters:
      maxAttempts - the value for the maxAttempts record component
      initialBackoff - the value for the initialBackoff record component
      maxBackoff - the value for the maxBackoff record component
      multiplier - the value for the multiplier record component
      jitter - the value for the jitter record component
  • Method Details

    • defaults

      public static RetryPolicy defaults()
      Three attempts, 100 ms growing to 5 s, jittered by a fifth.
    • quiesce

      public static RetryPolicy quiesce()
      A maintenance window's worth of patience: up to 60 attempts, 1 s growing to 30 s, jittered.

      For a quiesced cluster the short transport budget is exactly wrong - the cluster is alive and deliberately refusing writes for as long as an operator needs, and giving up after three attempts would guarantee the divergence the retry exists to prevent.

    • noRetry

      public static RetryPolicy noRetry()
      A policy that never retries - one attempt and done.
    • shouldRetry

      public boolean shouldRetry(int attemptsSoFar)
      Whether another attempt is allowed after attemptsSoFar have failed.
    • backoffFor

      public Duration backoffFor(int attempt)
      How long to wait before attempt number attempt (1-based, so backoffFor(1) is the pause after the first failure).
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • maxAttempts

      public int maxAttempts()
      Returns the value of the maxAttempts record component.
      Returns:
      the value of the maxAttempts record component
    • initialBackoff

      public Duration initialBackoff()
      Returns the value of the initialBackoff record component.
      Returns:
      the value of the initialBackoff record component
    • maxBackoff

      public Duration maxBackoff()
      Returns the value of the maxBackoff record component.
      Returns:
      the value of the maxBackoff record component
    • multiplier

      public double multiplier()
      Returns the value of the multiplier record component.
      Returns:
      the value of the multiplier record component
    • jitter

      public double jitter()
      Returns the value of the jitter record component.
      Returns:
      the value of the jitter record component