java.lang.Object
org.elasticsearch.index.codec.tsdb.pipeline.EncodingContext

public final class EncodingContext extends Object
Mutable per-block context for encoding, tracking the position bitmap, metadata buffer, and position offsets. Reused across blocks via clear().
  • Constructor Summary

    Constructors
    Constructor
    Description
    EncodingContext(int blockSize, int pipelineLength)
    Creates an encoding context with default metadata buffer capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    applyStage(int position)
    Records that the stage at the given position was applied.
    int
    Returns the block size.
    void
    Resets this context for reuse with the next block.
    boolean
    isStageApplied(int position)
    Returns true if the stage at the given position was applied.
    Returns the metadata writer, marking the current position as applied.
    int
    Returns the number of stages in the pipeline.
    short
    Returns the bitmap of applied stage positions.
    void
    setCurrentPosition(int position)
    Sets the current stage position before invoking each stage's encode method.
    void
    setValueCount(int count)
    Sets the number of values in the current block.
    int
    Returns the number of values in the current block.
    void
    writeStageMetadata(org.apache.lucene.store.DataOutput out)
    Flushes stage metadata to disk in reverse stage order (N-1 first, 0 last).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EncodingContext

      public EncodingContext(int blockSize, int pipelineLength)
      Creates an encoding context with default metadata buffer capacity.
      Parameters:
      blockSize - the number of values per block
      pipelineLength - the number of stages in the pipeline
  • Method Details

    • pipelineLength

      public int pipelineLength()
      Returns the number of stages in the pipeline.
      Returns:
      the pipeline length
    • setCurrentPosition

      public void setCurrentPosition(int position)
      Sets the current stage position before invoking each stage's encode method.

      NOTE: Internal use only - called by the encode pipeline.

      Parameters:
      position - the zero-based stage index
    • applyStage

      public void applyStage(int position)
      Records that the stage at the given position was applied. Tracks the metadata buffer offset on the first call for each position.
      Parameters:
      position - the zero-based stage index
    • isStageApplied

      public boolean isStageApplied(int position)
      Returns true if the stage at the given position was applied.
      Parameters:
      position - the zero-based stage index
      Returns:
      whether the stage was applied
    • positionBitmap

      public short positionBitmap()
      Returns the bitmap of applied stage positions.
      Returns:
      the position bitmap
    • metadata

      public MetadataWriter metadata()
      Returns the metadata writer, marking the current position as applied.
      Returns:
      the metadata writer
      Throws:
      AssertionError - if the current position has not been set
    • writeStageMetadata

      public void writeStageMetadata(org.apache.lucene.store.DataOutput out) throws IOException
      Flushes stage metadata to disk in reverse stage order (N-1 first, 0 last). During encoding, stages run forward so metadata accumulates in the buffer in forward order. During decoding, stages run in reverse and the decoder reads metadata directly from the stream with no buffering. By reordering on flush, the on-disk layout matches decode execution order, giving the decoder a free sequential read without seeking or knowing variable-length metadata sizes.
      Parameters:
      out - the data output stream
      Throws:
      IOException - if an I/O error occurs
    • blockSize

      public int blockSize()
      Returns the block size.
      Returns:
      the number of values per block
    • setValueCount

      public void setValueCount(int count)
      Sets the number of values in the current block.
      Parameters:
      count - the value count
    • valueCount

      public int valueCount()
      Returns the number of values in the current block.
      Returns:
      the value count
    • clear

      public void clear()
      Resets this context for reuse with the next block.