public final class JournalSegmentDescriptor extends Object implements AutoCloseable
JournalSegment 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.| Modifier and Type | Class and Description |
|---|---|
static class |
JournalSegmentDescriptor.Builder
Segment descriptor builder.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
BYTES |
| Constructor and Description |
|---|
JournalSegmentDescriptor(Buffer buffer) |
| Modifier and Type | Method and Description |
|---|---|
static JournalSegmentDescriptor.Builder |
builder()
Returns a descriptor builder.
|
static JournalSegmentDescriptor.Builder |
builder(Buffer buffer)
Returns a descriptor builder for the given descriptor buffer.
|
void |
close() |
void |
delete()
Deletes the descriptor.
|
long |
id()
Returns the segment identifier.
|
long |
index()
Returns the segment index.
|
int |
maxEntries()
Returns the maximum number of entries allowed in the segment.
|
int |
maxSegmentSize()
Returns the maximum count of the segment.
|
String |
toString() |
void |
update(long timestamp)
Writes an update to the descriptor.
|
long |
updated()
Returns last time the segment was updated.
|
int |
version()
Returns the segment version.
|
public static final int BYTES
public JournalSegmentDescriptor(Buffer buffer)
NullPointerException - if buffer is nullpublic static JournalSegmentDescriptor.Builder builder()
The descriptor builder will write segment metadata to a 48 byte in-memory buffer.
public static JournalSegmentDescriptor.Builder builder(Buffer buffer)
buffer - The descriptor buffer.NullPointerException - if buffer is nullpublic int version()
Versions are monotonically increasing starting at 1.
public long id()
The segment ID is a monotonically increasing number within each log. Segments with in-sequence identifiers should contain in-sequence indexes.
public long index()
The index indicates the index at which the first entry should be written to the segment. Indexes are monotonically increasing thereafter.
public int maxSegmentSize()
public int maxEntries()
public long 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.
public void update(long timestamp)
public void close()
close in interface AutoCloseablepublic void delete()
Copyright © 2013–2018. All rights reserved.