Record Class SegmentDescriptor

java.lang.Object
java.lang.Record
org.opendaylight.raft.journal.SegmentDescriptor
Record Components:
version - the version
id - segment identifier
index - first index stored in this segment
maxSegmentSize - maximum size of a single segment file
maxEntries - maximum number of entries
updated - last updated, as epoch milliseconds
locked - true if the segment is locked

public record SegmentDescriptor(int version, long id, long index, int maxSegmentSize, int maxEntries, long updated, boolean locked) extends Record
Stores information about a Segment of the log. The segment descriptor manages metadata related to a single segment of the log. Descriptors are stored within the first 64 bytes of each segment in the following order:
  • id (64-bit signed integer) - A unique segment identifier. This is a monotonically increasing number within each log. Segments with in-sequence identifiers should contain in-sequence indexes.
  • index (64-bit signed integer) - The effective first index of the segment. This indicates the index at which the first entry should be written to the segment. Indexes are monotonically increasing thereafter.
  • version (64-bit signed integer) - The version of the segment. Versions are monotonically increasing starting at 1. Versions will only be incremented whenever the segment is rewritten to another memory/disk space, e.g. after log compaction.
  • maxSegmentSize (32-bit unsigned integer) - The maximum number of bytes allowed in the segment.
  • maxEntries (32-bit signed integer) - The total number of expected entries in the segment. This is the final number of entries allowed within the segment both before and after compaction. This entry count is used to determine the count of internal indexing and deduplication facilities.
  • updated (64-bit signed integer) - The last update to the segment in terms of milliseconds since the epoch. When the segment is first constructed, the updated time is 0. Once all entries in the segment have been committed, the updated time should be set to the current time. Log compaction should not result in a change to updated.
  • locked (8-bit boolean) - A boolean indicating whether the segment is locked. Segments will be locked once all entries have been committed to the segment. The lock state of each segment is used to determine log compaction and recovery behavior.
The remainder of the 64 segment header bytes are reserved for future metadata.
Author:
Jordan Halterman
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Segment descriptor builder.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SegmentDescriptor(int version, long id, long index, int maxSegmentSize, int maxEntries, long updated, boolean locked)
    Creates an instance of a SegmentDescriptor record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a descriptor builder.
    builder(int version)
    Returns a descriptor builder for the given descriptor buffer.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    long
    id()
    Returns the segment identifier.
    long
    Returns the segment index.
    boolean
    Returns the value of the locked record component.
    int
    Returns the maximum number of entries allowed in the segment.
    int
    Returns the maximum count of the segment.
    static @NonNull SegmentDescriptor
    Read a JournalSegmentDescriptor from a ReadableByteChannel.
    final String
    Returns a string representation of this record class.
    long
    Returns last time the segment was updated.
    int
    Returns the segment version.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • SegmentDescriptor

      public SegmentDescriptor(int version, long id, long index, int maxSegmentSize, int maxEntries, long updated, boolean locked)
      Creates an instance of a SegmentDescriptor record class.
      Parameters:
      version - the value for the version record component
      id - the value for the id record component
      index - the value for the index record component
      maxSegmentSize - the value for the maxSegmentSize record component
      maxEntries - the value for the maxEntries record component
      updated - the value for the updated record component
      locked - the value for the locked record component
  • Method Details

    • readFrom

      public static @NonNull SegmentDescriptor readFrom(ReadableByteChannel channel) throws IOException
      Read a JournalSegmentDescriptor from a ReadableByteChannel.
      Parameters:
      channel - channel to read from
      Returns:
      A SegmentDescriptor
      Throws:
      IOException - if an I/O error occurs or there is not enough data
    • version

      public int version()
      Returns the segment version. Versions are monotonically increasing starting at 1.
      Returns:
      The segment version.
    • id

      public long id()
      Returns the segment identifier. The segment ID is a monotonically increasing number within each log. Segments with in-sequence identifiers should contain in-sequence indexes.
      Returns:
      The segment identifier.
    • index

      public long index()
      Returns the segment index. The index indicates the index at which the first entry should be written to the segment. Indexes are monotonically increasing thereafter.
      Returns:
      The segment index.
    • maxSegmentSize

      public int maxSegmentSize()
      Returns the maximum count of the segment.
      Returns:
      The maximum allowed count of the segment.
    • maxEntries

      public int maxEntries()
      Returns the maximum number of entries allowed in the segment.
      Returns:
      The maximum number of entries allowed in the segment.
    • updated

      public long updated()
      Returns last time the segment was updated.

      When the segment is first constructed, the updated time is 0. Once all entries in the segment have been committed, the updated time should be set to the current time. Log compaction should not result in a change to updated.

      Returns:
      The last time the segment was updated in terms of milliseconds since the epoch.
    • builder

      public static SegmentDescriptor.Builder builder()
      Returns a descriptor builder. The descriptor builder will write segment metadata to a 48 byte in-memory buffer.
      Returns:
      The descriptor builder.
    • builder

      public static SegmentDescriptor.Builder builder(int version)
      Returns a descriptor builder for the given descriptor buffer.
      Parameters:
      version - version to build
      Returns:
      The descriptor builder.
      Throws:
      NullPointerException - if buffer is null
    • 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 '=='.
      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.
    • locked

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