Interface DirectAccessInput


public interface DirectAccessInput
An optional interface that an IndexInput can implement to provide direct access to the underlying data as a MemorySegment. This enables zero-copy access to memory-mapped data for SIMD-accelerated vector scoring.

The memory segment 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 Details

    • withMemorySegmentSlice

      boolean withMemorySegmentSlice(long offset, long length, CheckedConsumer<MemorySegment,IOException> action) throws IOException
      If a direct memory segment view is available for the given range, passes it to action and returns true. Otherwise returns false without invoking the action.

      The memory segment 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 input
      length - the number of bytes requested
      action - the action to perform with the memory segment
      Returns:
      true if a segment was available and the action was invoked
      Throws:
      IOException
    • withMemorySegmentSlices

      boolean withMemorySegmentSlices(long[] offsets, int length, int count, CheckedConsumer<MemorySegment[],IOException> action) throws IOException
      Bulk variant of withMemorySegmentSlice(long, long, org.elasticsearch.core.CheckedConsumer<java.lang.foreign.MemorySegment, java.io.IOException>). Resolves count file ranges to memory segments and invokes the action while all segments are valid. All ref-counting and resource management is handled internally.

      The memory segments 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 range
      length - byte length of each range (same for all)
      count - number of ranges to resolve
      action - receives a MemorySegment[] where entry i corresponds to offsets[i]
      Returns:
      true if all ranges were available and the action was invoked; false otherwise
      Throws:
      IOException
    • checkSlicesArgs

      static boolean checkSlicesArgs(long[] offsets, int count)
      Validates the offsets and count arguments for withMemorySegmentSlices(long[], int, int, org.elasticsearch.core.CheckedConsumer<java.lang.foreign.MemorySegment[], java.io.IOException>). Throws on negative count or an undersized offsets array. Returns true if count is zero (caller should treat as a no-op), false otherwise.