Module org.elasticsearch.server
Class EncodingContext
java.lang.Object
org.elasticsearch.index.codec.tsdb.pipeline.EncodingContext
Mutable per-block context for encoding, tracking the position bitmap, metadata buffer,
and position offsets. Reused across blocks via
clear().-
Constructor Summary
ConstructorsConstructorDescriptionEncodingContext(int blockSize, int pipelineLength) Creates an encoding context with default metadata buffer capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyStage(int position) Records that the stage at the given position was applied.intReturns the block size.voidclear()Resets this context for reuse with the next block.booleanisStageApplied(int position) Returnstrueif the stage at the given position was applied.metadata()Returns the metadata writer, marking the current position as applied.intReturns the number of stages in the pipeline.shortReturns the bitmap of applied stage positions.voidsetCurrentPosition(int position) Sets the current stage position before invoking each stage's encode method.voidsetValueCount(int count) Sets the number of values in the current block.intReturns the number of values in the current block.voidwriteStageMetadata(org.apache.lucene.store.DataOutput out) Flushes stage metadata to disk in reverse stage order (N-1 first, 0 last).
-
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 blockpipelineLength- 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) Returnstrueif 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
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
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.
-