Record Class LeaseConfig

java.lang.Object
java.lang.Record
com.loomcache.server.consensus.LeaseConfig
Record Components:
leaseDurationMs - duration of the leader lease in milliseconds (default: 300)
maxClockSkewMs - maximum allowed clock skew in milliseconds (default: 50)
leaseCheckEnabled - whether to enforce lease validity for reads (default: true)

public record LeaseConfig(long leaseDurationMs, long maxClockSkewMs, boolean leaseCheckEnabled) extends Record
Configuration for leader lease with clock skew protection.

The leader lease allows serving linearizable reads locally without a quorum round-trip. The lease is guaranteed to be valid as long as:

  • A majority of followers have acknowledged heartbeats recently
  • The lease has not expired (accounting for clock skew)

Clock skew protection works by applying a safety margin (maxClockSkewMs) to the lease expiration check. The leader's local check:

  isValid = (currentTime + maxClockSkew) < (leaseStart + leaseDuration)

This ensures the leader's lease always expires BEFORE followers think it has, preventing stale reads during clock skew.

This record is a passive value carrier and performs no cross-field validation. Callers are responsible for supplying values that satisfy their own operational constraints (e.g. skew < duration for production use).

  • Field Details

    • DEFAULT_LEASE_DURATION_MS

      public static final long DEFAULT_LEASE_DURATION_MS
      See Also:
    • DEFAULT_MAX_CLOCK_SKEW_MS

      public static final long DEFAULT_MAX_CLOCK_SKEW_MS
      See Also:
    • DEFAULT_LEASE_CHECK_ENABLED

      public static final boolean DEFAULT_LEASE_CHECK_ENABLED
      See Also:
  • Constructor Details

    • LeaseConfig

      public LeaseConfig(long leaseDurationMs, long maxClockSkewMs, boolean leaseCheckEnabled)
      Creates an instance of a LeaseConfig record class.
      Parameters:
      leaseDurationMs - the value for the leaseDurationMs record component
      maxClockSkewMs - the value for the maxClockSkewMs record component
      leaseCheckEnabled - the value for the leaseCheckEnabled record component
  • Method Details

    • defaults

      public static LeaseConfig defaults()
      Create a default LeaseConfig with standard values.
      Returns:
      default LeaseConfig
    • withDuration

      public static LeaseConfig withDuration(long leaseDurationMs)
      Create a LeaseConfig with custom lease duration.
      Parameters:
      leaseDurationMs - lease duration in milliseconds
      Returns:
      LeaseConfig with default clock skew
    • withClockSkew

      public static LeaseConfig withClockSkew(long maxClockSkewMs)
      Create a LeaseConfig with custom clock skew tolerance.
      Parameters:
      maxClockSkewMs - maximum clock skew in milliseconds
      Returns:
      LeaseConfig with default duration
    • disabled

      public static LeaseConfig disabled()
      Create a LeaseConfig with disabled lease checking.
      Returns:
      LeaseConfig with lease checking disabled
    • 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 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.
    • leaseDurationMs

      public long leaseDurationMs()
      Returns the value of the leaseDurationMs record component.
      Returns:
      the value of the leaseDurationMs record component
    • maxClockSkewMs

      public long maxClockSkewMs()
      Returns the value of the maxClockSkewMs record component.
      Returns:
      the value of the maxClockSkewMs record component
    • leaseCheckEnabled

      public boolean leaseCheckEnabled()
      Returns the value of the leaseCheckEnabled record component.
      Returns:
      the value of the leaseCheckEnabled record component