Package org.opendaylight.raft.journal
Record Class SegmentDescriptor
java.lang.Object
java.lang.Record
org.opendaylight.raft.journal.SegmentDescriptor
- Record Components:
version
- the versionid
- segment identifierindex
- first index stored in this segmentmaxSegmentSize
- maximum size of a single segment filemaxEntries
- maximum number of entriesupdated
- last updated, as epoch millisecondslocked
- 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 at1
. 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, theupdated
time is0
. Once all entries in the segment have been committed, theupdated
time should be set to the current time. Log compaction should not result in a change toupdated
.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.
- Author:
- Jordan Halterman
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Segment descriptor builder. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSegmentDescriptor
(int version, long id, long index, int maxSegmentSize, int maxEntries, long updated, boolean locked) Creates an instance of aSegmentDescriptor
record class. -
Method Summary
Modifier and TypeMethodDescriptionstatic SegmentDescriptor.Builder
builder()
Returns a descriptor builder.static SegmentDescriptor.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
hashCode()
Returns a hash code value for this object.long
id()
Returns the segment identifier.long
index()
Returns the segment index.boolean
locked()
Returns the value of thelocked
record component.int
Returns the maximum number of entries allowed in the segment.int
Returns the maximum count of the segment.static @NonNull SegmentDescriptor
readFrom
(ReadableByteChannel channel) Read a JournalSegmentDescriptor from aReadableByteChannel
.final String
toString()
Returns a string representation of this record class.long
updated()
Returns last time the segment was updated.int
version()
Returns the segment version.
-
Field Details
-
BYTES
public static final int BYTES- See Also:
-
-
Constructor Details
-
SegmentDescriptor
public SegmentDescriptor(int version, long id, long index, int maxSegmentSize, int maxEntries, long updated, boolean locked) Creates an instance of aSegmentDescriptor
record class.- Parameters:
version
- the value for theversion
record componentid
- the value for theid
record componentindex
- the value for theindex
record componentmaxSegmentSize
- the value for themaxSegmentSize
record componentmaxEntries
- the value for themaxEntries
record componentupdated
- the value for theupdated
record componentlocked
- the value for thelocked
record component
-
-
Method Details
-
readFrom
Read a JournalSegmentDescriptor from aReadableByteChannel
.- 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 at1
.- 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 is0
. Once all entries in the segment have been committed, theupdated
time should be set to the current time. Log compaction should not result in a change toupdated
.- Returns:
- The last time the segment was updated in terms of milliseconds since the epoch.
-
builder
Returns a descriptor builder. The descriptor builder will write segment metadata to a48
byte in-memory buffer.- Returns:
- The descriptor builder.
-
builder
Returns a descriptor builder for the given descriptor buffer.- Parameters:
version
- version to build- Returns:
- The descriptor builder.
- Throws:
NullPointerException
- ifbuffer
is null
-
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. -
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. -
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 '=='. -
locked
public boolean locked()Returns the value of thelocked
record component.- Returns:
- the value of the
locked
record component
-