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 Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanstatic final longstatic final long -
Constructor Summary
ConstructorsConstructorDescriptionLeaseConfig(long leaseDurationMs, long maxClockSkewMs, boolean leaseCheckEnabled) Creates an instance of aLeaseConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptionstatic LeaseConfigdefaults()Create a default LeaseConfig with standard values.static LeaseConfigdisabled()Create a LeaseConfig with disabled lease checking.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanReturns the value of theleaseCheckEnabledrecord component.longReturns the value of theleaseDurationMsrecord component.longReturns the value of themaxClockSkewMsrecord component.final StringtoString()Returns a string representation of this record class.static LeaseConfigwithClockSkew(long maxClockSkewMs) Create a LeaseConfig with custom clock skew tolerance.static LeaseConfigwithDuration(long leaseDurationMs) Create a LeaseConfig with custom lease duration.
-
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 aLeaseConfigrecord class.- Parameters:
leaseDurationMs- the value for theleaseDurationMsrecord componentmaxClockSkewMs- the value for themaxClockSkewMsrecord componentleaseCheckEnabled- the value for theleaseCheckEnabledrecord component
-
-
Method Details
-
defaults
Create a default LeaseConfig with standard values.- Returns:
- default LeaseConfig
-
withDuration
Create a LeaseConfig with custom lease duration.- Parameters:
leaseDurationMs- lease duration in milliseconds- Returns:
- LeaseConfig with default clock skew
-
withClockSkew
Create a LeaseConfig with custom clock skew tolerance.- Parameters:
maxClockSkewMs- maximum clock skew in milliseconds- Returns:
- LeaseConfig with default duration
-
disabled
Create a LeaseConfig with disabled lease checking.- Returns:
- LeaseConfig with lease checking disabled
-
toString
-
hashCode
-
equals
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 thecomparemethod from their corresponding wrapper classes. -
leaseDurationMs
public long leaseDurationMs()Returns the value of theleaseDurationMsrecord component.- Returns:
- the value of the
leaseDurationMsrecord component
-
maxClockSkewMs
public long maxClockSkewMs()Returns the value of themaxClockSkewMsrecord component.- Returns:
- the value of the
maxClockSkewMsrecord component
-
leaseCheckEnabled
public boolean leaseCheckEnabled()Returns the value of theleaseCheckEnabledrecord component.- Returns:
- the value of the
leaseCheckEnabledrecord component
-