Record Class LeadershipStatus

java.lang.Object
java.lang.Record
io.krabka.streams.coordination.LeadershipStatus
Record Components:
role - the role the status describes
token - the token the transaction coordinator reports for the role
state - the folded state of the coordination topic for the role

public record LeadershipStatus(Role role, FencingToken token, RoleState state) extends Record
What one role looks like to a third party right now.

The status pairs the two independent answers about a role. The token is the pair that Kafka's transaction coordinator reports for the transactional.id of the role, and it is FencingToken.NO_EPOCH when no member has ever taken the role. The state is the fold of the coordination topic, and it names the roster and the last lease record.

current() joins the two. It reports whether the member that wrote the lease still holds the epoch of the role. A checker needs no membership and no lease clock to answer that question. It is the check the design promises: "a third party verifies a writer's authority with one request and no membership".

The lease deadline says nothing about authority. A holder past its deadline still owns the newest epoch until a challenger mints a newer one.

Example

LeadershipStatus status = client.describe(Role.of("controller"));
System.out.println(status.holder().map(MemberId::id).orElse("none")
    + " holds " + status.token() + ", current=" + status.current());
  • Constructor Details

    • LeadershipStatus

      public LeadershipStatus(Role role, FencingToken token, RoleState state)
      Rejects a null component.
      Parameters:
      role - the role the status describes
      token - the token the transaction coordinator reports for the role
      state - the folded state of the coordination topic for the role
  • Method Details

    • holder

      public Optional<MemberId> holder()
      Returns the member the last lease record names.
      Returns:
      the member that wrote the lease, and empty when the role has no lease
    • lease

      public Optional<Lease> lease()
      Returns the last lease record of the role.
      Returns:
      the lease, and empty when no member holds the role
    • held

      public boolean held()
      Reports whether any member has ever taken the role.
      Returns:
      true when the coordinator reports a minted token
    • current

      public boolean current()
      Reports whether the author of the lease still holds the epoch of the role.

      A false answer means one of two things. Either no member holds the role, or a challenger minted a newer epoch and has not written its own lease yet. In both cases the broker already rejects every write that the author of this lease makes.

      Returns:
      true when the lease token equals the token of the coordinator
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • role

      public Role role()
      Returns the value of the role record component.
      Returns:
      the value of the role record component
    • token

      public FencingToken token()
      Returns the value of the token record component.
      Returns:
      the value of the token record component
    • state

      public RoleState state()
      Returns the value of the state record component.
      Returns:
      the value of the state record component