Class KeyLookup.Cursor

java.lang.Object
org.apache.cassandra.index.sai.disk.v1.keystore.KeyLookup.Cursor
All Implemented Interfaces:
AutoCloseable
Enclosing class:
KeyLookup

@NotThreadSafe public class KeyLookup.Cursor extends Object implements AutoCloseable
Allows reading the keys from the keys file. Can quickly seek to a random key by point id.

This object is stateful and not thread safe. It maintains a position to the current key as well as a buffer that can hold one key.

  • Method Details

    • seekToPointId

      @Nonnull public ByteSource seekToPointId(long pointId)
      Positions the cursor on the target point id and reads the key at the target to the current key buffer.

      It is allowed to position the cursor before the first item or after the last item; in these cases the internal buffer is cleared.

      Parameters:
      pointId - point id to lookup
      Returns:
      The ByteSource containing the key
      Throws:
      IndexOutOfBoundsException - if the target point id is less than -1 or greater than the number of keys
    • clusteredSeekToKey

      public long clusteredSeekToKey(ByteComparable key, long startingPointId, long endingPointId)
      Finds the pointId for a clustering key within a range of pointIds. The start and end of the range must not exceed the number of keys available. The keys within the range are expected to be in lexographical order.

      If the key is not in the block containing the start of the range a binary search is done to find the block containing the search key. That block is then searched to return the pointId that corresponds to the key that is either equal to or next highest to the search key.

      Parameters:
      key - The key to seek for with the partition
      startingPointId - the inclusive starting point for the partition
      endingPointId - the exclusive ending point for the partition. Note: this can be equal to the number of keys if this is the last partition
      Returns:
      a long representing the pointId of the key that is >= to the key passed to the method, or -1 if the key passed is > all the keys.
    • reset

      public void reset() throws IOException
      Throws:
      IOException
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable