Class 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.

    • 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
    • Method Detail

      • 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 segment
        segmentId - 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 or 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().
        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)
      • getAddress

        public int getAddress​(int offset)
        Convert an offset into an address.
        Parameters:
        offset -
        Returns:
        the address corresponding the offset