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 entries
configChange - 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
    Modifier and Type
    Class
    Description
    static enum 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    LogEntry(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 Type
    Method
    Description
    byte[]
    Returns the value of the command record component.
    @Nullable ConfigChange
    Returns the value of the configChange record component.
    static LogEntry
    configChange(long term, long index, ConfigChange change)
    Factory method to create a CONFIG_CHANGE entry.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    long
    Returns the value of the index record component.
    boolean
    Check if this is a COMMAND entry.
    boolean
    Check if this is a CONFIG_CHANGE entry.
    boolean
    Check if this is a NO_OP entry.
    static LogEntry
    noOp(long term, long index)
    Factory method to create a NO_OP entry.
    long
    Returns the value of the term record component.
    Returns a string representation of this record class.
    Returns the value of the type record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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-positive
      NullPointerException - 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 violated
      NullPointerException - if type is null
  • Method Details

    • configChange

      public static LogEntry configChange(long term, long index, ConfigChange change)
      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 null
      IllegalArgumentException - if term is negative or index is non-positive
    • noOp

      public static LogEntry noOp(long term, long index)
      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 term
      index - 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

      public byte[] command()
      Returns the value of the command record component.
      Returns:
      the value of the command record component
    • toString

      public 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.
    • term

      public long term()
      Returns the value of the term record component.
      Returns:
      the value of the term record component
    • index

      public long index()
      Returns the value of the index record component.
      Returns:
      the value of the index record component
    • type

      public LogEntry.Type type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • configChange

      public @Nullable ConfigChange configChange()
      Returns the value of the configChange record component.
      Returns:
      the value of the configChange record component