public class Segment extends Object
Record data is not kept in memory, but some entries are cached (templates, all strings in the segment).
This class includes method to read records from the raw bytes.
Modifier and Type | Class and Description |
---|---|
static interface |
Segment.RecordConsumer
A consumer of record data.
|
Modifier and Type | Field and Description |
---|---|
static int |
BLOB_ID_SMALL_LIMIT
Maximum size of small blob IDs.
|
static int |
GC_GENERATION_OFFSET |
static int |
MAX_SEGMENT_SIZE
Maximum segment size.
|
static int |
MEDIUM_LIMIT
The size limit for medium values.
|
static int |
RECORD_ALIGN_BITS
The number of bytes (or bits of address space) to use for the
alignment boundary of segment records.
|
static int |
RECORD_NUMBER_COUNT_OFFSET |
static int |
REFERENCED_SEGMENT_ID_COUNT_OFFSET |
Constructor and Description |
---|
Segment(SegmentStore store,
SegmentReader reader,
SegmentId id,
ByteBuffer data) |
Modifier and Type | Method and Description |
---|---|
static int |
align(int address,
int boundary)
Align an
address on the given boundary |
int |
estimateMemoryUsage()
Estimate of how much memory this instance would occupy in the segment
cache.
|
void |
forEachRecord(Segment.RecordConsumer consumer)
Iterate over the records contained in this segment.
|
int |
getGcGeneration()
Determine the gc generation of this segment.
|
static int |
getGcGeneration(ByteBuffer data,
UUID segmentId)
Determine the gc generation a segment from its data.
|
int |
getRecordNumberCount() |
UUID |
getReferencedSegmentId(int index) |
int |
getReferencedSegmentIdCount() |
SegmentId |
getSegmentId() |
String |
getSegmentInfo()
Returns the segment meta data of this segment or
null if none is present. |
SegmentVersion |
getSegmentVersion() |
int |
size() |
String |
toString() |
void |
writeTo(OutputStream stream) |
public static final int RECORD_ALIGN_BITS
public static final int MAX_SEGMENT_SIZE
public static final int MEDIUM_LIMIT
public static final int BLOB_ID_SMALL_LIMIT
public static final int GC_GENERATION_OFFSET
public static final int REFERENCED_SEGMENT_ID_COUNT_OFFSET
public static final int RECORD_NUMBER_COUNT_OFFSET
public Segment(@Nonnull SegmentStore store, @Nonnull SegmentReader reader, @Nonnull SegmentId id, @Nonnull ByteBuffer data)
public static int align(int address, int boundary)
address
on the given boundary
address
- address to alignboundary
- boundary to align ton = address + a
such that n % boundary == 0
and
0 <= a < boundary
.public SegmentVersion getSegmentVersion()
public SegmentId getSegmentId()
public int getReferencedSegmentIdCount()
public int getRecordNumberCount()
public UUID getReferencedSegmentId(int index)
public static int getGcGeneration(ByteBuffer data, UUID segmentId)
data
- the date of the segmentsegmentId
- the id of the segmentpublic int getGcGeneration()
@CheckForNull public String getSegmentInfo()
null
if none is present.
The segment meta data is a string of the format "{wid=W,sno=S,gc=G,t=T}"
where:
W
is the writer id wid
, S
is a unique, increasing sequence number corresponding to the allocation order
of the segments in this store, G
is the garbage collection generation (i.e. the number of compaction cycles
that have been run),T
is a time stamp according to System.currentTimeMillis()
.public int size()
public void writeTo(OutputStream stream) throws IOException
IOException
public void forEachRecord(Segment.RecordConsumer consumer)
consumer
- an instance of Segment.RecordConsumer
.public int estimateMemoryUsage()
Copyright © 2012-2019 The Apache Software Foundation. All Rights Reserved.