Class Segment
- java.lang.Object
-
- org.apache.jackrabbit.oak.segment.Segment
-
public class Segment extends Object
A list of records.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Segment.RecordConsumer
A consumer of record data.
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_SEGMENT_SIZE
Maximum segment size (in bytes)static int
MEDIUM_LIMIT
The size limit for medium values.
-
Constructor Summary
Constructors Constructor Description Segment(@NotNull SegmentIdProvider idProvider, @NotNull SegmentId id, @NotNull Buffer data)
Segment(@NotNull SegmentId id, @NotNull SegmentData data, @NotNull RecordNumbers recordNumbers, @NotNull SegmentReferences segmentReferences)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
forEachRecord(Segment.RecordConsumer consumer)
Iterate over the records contained in this segment.int
getAddress(int offset)
Convert an offset into an address.@NotNull GCGeneration
getGcGeneration()
Determine the gc generation of this segment.static GCGeneration
getGcGeneration(SegmentData data, UUID segmentId)
Determine the gc generation a segment from its data.UUID
getReferencedSegmentId(int index)
int
getReferencedSegmentIdCount()
SegmentId
getSegmentId()
@Nullable String
getSegmentInfo()
Returns the segment meta data of this segment ornull
if none is present.SegmentVersion
getSegmentVersion()
byte
readByte(int recordNumber)
byte
readByte(int recordNumber, int offset)
void
readBytes(int recordNumber, int position, byte[] buffer, int offset, int length)
Buffer
readBytes(int recordNumber, int position, int length)
int
size()
String
toString()
void
writeTo(OutputStream stream)
-
-
-
Field Detail
-
MAX_SEGMENT_SIZE
public static final int MAX_SEGMENT_SIZE
Maximum segment size (in bytes)- See Also:
- Constant Field Values
-
MEDIUM_LIMIT
public static final int MEDIUM_LIMIT
The size limit for medium values. The variable length of medium values is encoded as two bytes with the highest bits of the first byte set to one and zero, which gives us 14 bits for encoding the length of the value. And since small values are never stored as medium ones, we can extend the size range to cover that many longer values.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Segment
public Segment(@NotNull @NotNull SegmentIdProvider idProvider, @NotNull @NotNull SegmentId id, @NotNull @NotNull Buffer data)
-
Segment
public Segment(@NotNull @NotNull SegmentId id, @NotNull @NotNull SegmentData data, @NotNull @NotNull RecordNumbers recordNumbers, @NotNull @NotNull SegmentReferences segmentReferences)
-
-
Method Detail
-
getSegmentVersion
public SegmentVersion getSegmentVersion()
-
getSegmentId
public SegmentId getSegmentId()
-
getReferencedSegmentIdCount
public int getReferencedSegmentIdCount()
-
getReferencedSegmentId
public UUID getReferencedSegmentId(int index)
-
getGcGeneration
public static GCGeneration getGcGeneration(SegmentData data, UUID segmentId)
Determine the gc generation a segment from its data. Note that bulk segments don't have generations (i.e. stay at 0).- Parameters:
data
- the data of the segmentsegmentId
- the id of the segment- Returns:
- the gc generation of this segment or
GCGeneration.NULL
if this is bulk segment.
-
getGcGeneration
@NotNull public @NotNull GCGeneration getGcGeneration()
Determine the gc generation of this segment. Note that bulk segments don't have generations (i.e. stay at 0).- Returns:
- the gc generation of this segment or 0 if this is bulk segment.
-
getSegmentInfo
@Nullable public @Nullable String getSegmentInfo()
Returns the segment meta data of this segment ornull
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 idwid
,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 toSystem.currentTimeMillis()
.
- Returns:
- the segment meta data
-
size
public int size()
-
readByte
public byte readByte(int recordNumber)
-
readByte
public byte readByte(int recordNumber, int offset)
-
readBytes
public void readBytes(int recordNumber, int position, byte[] buffer, int offset, int length)
-
readBytes
public Buffer readBytes(int recordNumber, int position, int length)
-
writeTo
public void writeTo(OutputStream stream) throws IOException
- Throws:
IOException
-
getAddress
public int getAddress(int offset)
Convert an offset into an address.- Parameters:
offset
-- Returns:
- the address corresponding the
offset
-
forEachRecord
public void forEachRecord(Segment.RecordConsumer consumer)
Iterate over the records contained in this segment.- Parameters:
consumer
- an instance ofSegment.RecordConsumer
.
-
-