Record Class LogEntry
java.lang.Object
java.lang.Record
com.loomcache.server.consensus.LogEntry
- Record Components:
term- the Raft term (non-negative)index- the log index (1-based, positive)type- the entry type (non-null)command- null or empty for NO_OP and CONFIG_CHANGE entriesconfigChange- non-null only for CONFIG_CHANGE entries
public record LogEntry(long term, long index, LogEntry.Type type, byte[] command, @Nullable ConfigChange configChange)
extends Record
A single entry in the Raft replicated log.
Each entry contains:
- term: the leader's term when this entry was created (non-negative)
- index: position in the log (1-based, positive)
- type: entry type (COMMAND, NO_OP, or CONFIG_CHANGE, non-null)
- command: the operation to apply to the state machine (null for NO_OP and CONFIG_CHANGE)
- configChange: configuration change (non-null only for CONFIG_CHANGE entries)
Log entries are appended by the leader and replicated to followers. An entry is "committed" when a majority of nodes have it in their logs. Committed entries are then applied to the state machine (cache store).
Entry Types:
- COMMAND: Regular cache operation (has non-null command)
- NO_OP: No-op entry used during leader election (command is empty)
- CONFIG_CHANGE: Membership change (has configChange object)
- Since:
- 1.0
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionLogEntry(long term, long index, byte[] command) Compact constructor for COMMAND entries.LogEntry(long term, long index, LogEntry.Type type, byte[] command, @Nullable ConfigChange configChange) Full constructor for all entry types (COMMAND, NO_OP, CONFIG_CHANGE). -
Method Summary
Modifier and TypeMethodDescriptionbyte[]command()Returns the value of thecommandrecord component.@Nullable ConfigChangeReturns the value of theconfigChangerecord component.static LogEntryconfigChange(long term, long index, ConfigChange change) Factory method to create a CONFIG_CHANGE entry.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.longindex()Returns the value of theindexrecord component.booleanCheck if this is a COMMAND entry.booleanCheck if this is a CONFIG_CHANGE entry.booleanisNoOp()Check if this is a NO_OP entry.static LogEntrynoOp(long term, long index) Factory method to create a NO_OP entry.longterm()Returns the value of thetermrecord component.toString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.
-
Constructor Details
-
LogEntry
public LogEntry(long term, long index, byte[] command) Compact constructor for COMMAND entries.- Parameters:
term- The Raft term when this entry is created (non-negative)index- The log index (1-based, positive)command- The state machine command (may be null or empty for NO_OP-like entries)- Throws:
IllegalArgumentException- if term is negative or index is non-positiveNullPointerException- if type validation fails
-
LogEntry
public LogEntry(long term, long index, LogEntry.Type type, byte[] command, @Nullable ConfigChange configChange) Full constructor for all entry types (COMMAND, NO_OP, CONFIG_CHANGE).- Parameters:
term- The Raft term when this entry is created (non-negative)index- The log index (1-based, positive)type- The entry type (non-null)command- The state machine command (null for NO_OP and CONFIG_CHANGE)configChange- The config change (non-null only for CONFIG_CHANGE type)- Throws:
IllegalArgumentException- If entry type invariants are violatedNullPointerException- if type is null
-
-
Method Details
-
configChange
Factory method to create a CONFIG_CHANGE entry.- Parameters:
term- The Raft term (non-negative)index- The log index (1-based, positive)change- The configuration change (non-null)- Returns:
- A new CONFIG_CHANGE LogEntry
- Throws:
NullPointerException- if change is nullIllegalArgumentException- if term is negative or index is non-positive
-
noOp
Factory method to create a NO_OP entry.NO_OP entries are used during leader elections and heartbeats to establish a new leader's commitment without performing state machine operations.
- Parameters:
term- The Raft termindex- The log index (1-based)- Returns:
- A new NO_OP LogEntry
-
isCommand
public boolean isCommand()Check if this is a COMMAND entry.- Returns:
- true if type is COMMAND
-
isNoOp
public boolean isNoOp()Check if this is a NO_OP entry.- Returns:
- true if type is NO_OP
-
isConfigChange
public boolean isConfigChange()Check if this is a CONFIG_CHANGE entry.- Returns:
- true if type is CONFIG_CHANGE
-
command
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
term
-
index
-
type
-
configChange
Returns the value of theconfigChangerecord component.- Returns:
- the value of the
configChangerecord component
-