public interface DirectAccessInput
An optional interface that an IndexInput can implement to provide direct
access to the underlying data as a
ByteBuffer. This enables
zero-copy access to memory-mapped data for SIMD-accelerated vector scoring.
The byte buffer is passed to the caller's action and is only valid for the duration of that call. All ref-counting and resource releases, if any, is handled internally.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancheckSlicesArgs(long[] offsets, int count) Validates theoffsetsandcountarguments forwithByteBufferSlices(long[], int, int, org.elasticsearch.core.CheckedConsumer<java.nio.ByteBuffer[], java.io.IOException>).booleanwithByteBufferSlice(long offset, long length, CheckedConsumer<ByteBuffer, IOException> action) If a direct byte buffer view is available for the given range, passes it toactionand returnstrue.booleanwithByteBufferSlices(long[] offsets, int length, int count, CheckedConsumer<ByteBuffer[], IOException> action)
-
Method Details
-
withByteBufferSlice
boolean withByteBufferSlice(long offset, long length, CheckedConsumer<ByteBuffer, IOException> action) throws IOExceptionIf a direct byte buffer view is available for the given range, passes it toactionand returnstrue. Otherwise returnsfalsewithout invoking the action.The byte buffer is read-only and valid only for the duration of the action. Callers must not retain references to it after the action returns.
- Parameters:
offset- the byte offset within the inputlength- the number of bytes requestedaction- the action to perform with the byte buffer- Returns:
trueif a buffer was available and the action was invoked- Throws:
IOException
-
withByteBufferSlices
boolean withByteBufferSlices(long[] offsets, int length, int count, CheckedConsumer<ByteBuffer[], IOException> action) throws IOExceptionBulk variant ofwithByteBufferSlice(long, long, org.elasticsearch.core.CheckedConsumer<java.nio.ByteBuffer, java.io.IOException>). Resolvescountfile ranges to direct byte buffers and invokes the action while all buffers are valid. All ref-counting and resource management is handled internally.The byte buffers in the array passed to the action are read-only and valid only for the duration of the action. Callers must not retain references to them after the action returns.
- Parameters:
offsets- file byte offsets for each rangelength- byte length of each range (same for all)count- number of ranges to resolveaction- receives aByteBuffer[]where entryicorresponds tooffsets[i]- Returns:
trueif all ranges were available and the action was invoked;falseotherwise- Throws:
IOException
-
checkSlicesArgs
static boolean checkSlicesArgs(long[] offsets, int count) Validates theoffsetsandcountarguments forwithByteBufferSlices(long[], int, int, org.elasticsearch.core.CheckedConsumer<java.nio.ByteBuffer[], java.io.IOException>). Throws on negative count or an undersized offsets array. Returnstrueif count is zero (caller should treat as a no-op),falseotherwise.
-