Record Class Lease

java.lang.Object
java.lang.Record
io.krabka.streams.coordination.Lease
Record Components:
member - the member that holds the role
token - the quorum-minted proof of the claim of the holder
grantedAt - the time the holder took the lease, in milliseconds since the Unix epoch; a renewal moves it forward
deadline - the time the lease expires, in milliseconds since the Unix epoch
All Implemented Interfaces:
CoordinationValue

public record Lease(MemberId member, FencingToken token, long grantedAt, long deadline) extends Record implements CoordinationValue
The member that holds a role now, and the time its claim ends.

The token is the authority. The broker fences a write that carries an older token, and no clock takes part in that check. The deadline is an anti-flap device. A standby waits for the deadline to pass before it challenges the holder, so a short pause does not move the role. A wrong deadline makes a failover early or late. A wrong deadline never makes two members authoritative.

The holder writes the record inside a transaction under the epoch of the role, so a lease record that reached the log is proof that its author held the epoch. A reader uses read_committed, so an aborted lease write stays invisible.

Example

Lease lease = config.grant(me, token, clock.nowMillis());
transport.writeLease(role, token, lease);
boolean live = config.timing(lease).liveAt(clock.nowMillis());
  • Constructor Details

    • Lease

      public Lease(MemberId member, FencingToken token, long grantedAt, long deadline)
      Rejects a null member and a null token.
      Parameters:
      member - the member that holds the role
      token - the quorum-minted proof of the claim of the holder
      grantedAt - the time the holder took the lease, in milliseconds since the Unix epoch
      deadline - the time the lease expires, in milliseconds since the Unix epoch
  • Method Details

    • kind

      public RecordKind kind()
      Returns the kind of the key that a lease sits under.
      Specified by:
      kind in interface CoordinationValue
      Returns:
      RecordKind.LEASE
    • 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.
    • member

      public MemberId member()
      Returns the value of the member record component.
      Specified by:
      member in interface CoordinationValue
      Returns:
      the value of the member record component
    • token

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

      public long grantedAt()
      Returns the value of the grantedAt record component.
      Returns:
      the value of the grantedAt record component
    • deadline

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