public final class SegmentDescriptor extends Object implements AutoCloseable
Segment of the log.
The segment descriptor manages metadata related to a single segment of the log. Descriptors are stored within the
first 48 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.range (64-bit signed integer) - The effective length of the segment. Regardless of the actual number of
entries in the segment, the range indicates the total number of allowed entries within each segment. If a segment's
index is 1 and its range is 10 then the next segment should start at index 11.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.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.maxEntrySize (32-bit signed integer) - The maximum length in bytes of entry values allowed by the segment.entries (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.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 |
SegmentDescriptor.Builder
Segment descriptor builder.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
BYTES |
| Constructor and Description |
|---|
SegmentDescriptor(Buffer buffer) |
| Modifier and Type | Method and Description |
|---|---|
static SegmentDescriptor.Builder |
builder()
Returns a descriptor builder.
|
static SegmentDescriptor.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.
|
void |
lock()
Locks the segment.
|
boolean |
locked()
Returns whether the segment has been locked by commitment.
|
int |
maxEntries()
Returns the maximum number of entries allowed in the segment.
|
long |
maxSegmentSize()
Returns the maximum count of the segment.
|
void |
update(long timestamp)
Writes an update to the descriptor.
|
long |
updated()
Returns last time the segment was updated.
|
long |
version()
Returns the segment version.
|
public static final int BYTES
public SegmentDescriptor(Buffer buffer)
NullPointerException - if buffer is nullpublic static SegmentDescriptor.Builder builder()
The descriptor builder will write segment metadata to a 48 byte in-memory buffer.
public static SegmentDescriptor.Builder builder(Buffer buffer)
buffer - The descriptor buffer.NullPointerException - if buffer is nullpublic 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 version()
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.
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 long 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 boolean 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.
public void lock()
public void close()
close in interface AutoCloseablepublic void delete()
Copyright © 2013–2016. All rights reserved.