Record Class Decision

java.lang.Object
java.lang.Record
io.krabka.streams.coordination.Decision
Record Components:
action - the step the member takes now
waitUntilMillis - the instant of the next evaluation, in milliseconds since the Unix epoch, for Decision.Action.WAIT only

public record Decision(Decision.Action action, long waitUntilMillis) extends Record
What one member does about a role right now.

Succession.evaluate(RoleState, MemberId, long, LeaseConfig) returns one. The wait instant carries a value for Decision.Action.WAIT only, and it is zero for every other action.

A decision never makes a member authoritative. It decides when a member calls InitProducerId, and the transaction coordinator decides who wins. A wrong decision makes a failover early or late, and it costs epoch churn.

Example

Decision decision = Succession.evaluate(state, me, clock.nowMillis(), config);
switch (decision.action()) {
    case NOT_REGISTERED -> transport.register(role, me);
    case CHALLENGE -> transport.acquireEpoch(role);
    case HOLD -> leadership.renew();
    case WAIT -> parkUntil(decision.waitUntilMillis());
}
  • Constructor Details

    • Decision

      public Decision(Decision.Action action, long waitUntilMillis)
      Rejects a null action.
      Parameters:
      action - the step the member takes now
      waitUntilMillis - the instant of the next evaluation, in milliseconds since the Unix epoch, for Decision.Action.WAIT only
  • Method Details

    • notRegistered

      public static Decision notRegistered()
      Returns the decision to register first.
      Returns:
      a decision that carries Decision.Action.NOT_REGISTERED
    • hold

      public static Decision hold()
      Returns the decision to keep the role.
      Returns:
      a decision that carries Decision.Action.HOLD
    • challenge

      public static Decision challenge()
      Returns the decision to call InitProducerId now.
      Returns:
      a decision that carries Decision.Action.CHALLENGE
    • waitUntil

      public static Decision waitUntil(long untilMillis)
      Returns the decision to wait until one instant.
      Parameters:
      untilMillis - the instant of the next evaluation, in milliseconds since the Unix epoch
      Returns:
      a decision that carries Decision.Action.WAIT
    • 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.
    • action

      public Decision.Action action()
      Returns the value of the action record component.
      Returns:
      the value of the action record component
    • waitUntilMillis

      public long waitUntilMillis()
      Returns the value of the waitUntilMillis record component.
      Returns:
      the value of the waitUntilMillis record component