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 interfaceSegment.RecordConsumerA consumer of record data.
-
Field Summary
Fields Modifier and Type Field Description static intMAX_SEGMENT_SIZEMaximum segment size (in bytes)static intMEDIUM_LIMITThe 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 voidforEachRecord(Segment.RecordConsumer consumer)Iterate over the records contained in this segment.intgetAddress(int offset)Convert an offset into an address.@NotNull GCGenerationgetGcGeneration()Determine the gc generation of this segment.static GCGenerationgetGcGeneration(SegmentData data, UUID segmentId)Determine the gc generation a segment from its data.UUIDgetReferencedSegmentId(int index)intgetReferencedSegmentIdCount()SegmentIdgetSegmentId()@Nullable StringgetSegmentInfo()Returns the segment meta data of this segment ornullif none is present.SegmentVersiongetSegmentVersion()bytereadByte(int recordNumber)bytereadByte(int recordNumber, int offset)voidreadBytes(int recordNumber, int position, byte[] buffer, int offset, int length)BufferreadBytes(int recordNumber, int position, int length)intsize()StringtoString()voidwriteTo(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.NULLif 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 ornullif none is present.The segment meta data is a string of the format
"{wid=W,sno=S,gc=G,t=T}"where:Wis the writer idwid,Sis a unique, increasing sequence number corresponding to the allocation order of the segments in this store,Gis the garbage collection generation (i.e. the number of compaction cycles that have been run),Tis 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.
-
-