Class Segment


  • public class Segment
    extends java.lang.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

      • 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 java.util.UUID getReferencedSegmentId​(int index)
      • getGcGeneration

        public static GCGeneration getGcGeneration​(SegmentData data,
                                                   java.util.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 java.lang.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()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • writeTo

        public void writeTo​(java.io.OutputStream stream)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • getAddress

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