Package org.rocksdb

Class AbstractRocksIterator<P extends RocksObject>

Type Parameters:
P - The type of the Parent Object from which the Rocks Iterator was created. This is used by disposeInternal to avoid double-free issues with the underlying C++ object.
All Implemented Interfaces:
AutoCloseable, RocksIteratorInterface
Direct Known Subclasses:
RocksIterator, SstFileReaderIterator, WBWIRocksIterator

public abstract class AbstractRocksIterator<P extends RocksObject> extends RocksObject implements RocksIteratorInterface
Base class implementation for Rocks Iterators in the Java API

Multiple threads can invoke const methods on an RocksIterator without external synchronization, but if any of the threads may call a non-const method, all threads accessing the same RocksIterator must use external synchronization.

See Also:
  • Constructor Details

    • AbstractRocksIterator

      protected AbstractRocksIterator(P parent, long nativeHandle)
  • Method Details

    • isValid

      public boolean isValid()
      Description copied from interface: RocksIteratorInterface

      An iterator is either positioned at an entry, or not valid. This method returns true if the iterator is valid.

      Specified by:
      isValid in interface RocksIteratorInterface
      Returns:
      true if iterator is valid.
    • seekToFirst

      public void seekToFirst()
      Description copied from interface: RocksIteratorInterface

      Position at the first entry in the source. The iterator is Valid() after this call if the source is not empty.

      Specified by:
      seekToFirst in interface RocksIteratorInterface
    • seekToLast

      public void seekToLast()
      Description copied from interface: RocksIteratorInterface

      Position at the last entry in the source. The iterator is valid after this call if the source is not empty.

      Specified by:
      seekToLast in interface RocksIteratorInterface
    • seek

      public void seek(byte[] target)
      Description copied from interface: RocksIteratorInterface

      Position at the first entry in the source whose key is at or past target.

      The iterator is valid after this call if the source contains a key that comes at or past target.

      Specified by:
      seek in interface RocksIteratorInterface
      Parameters:
      target - byte array describing a key or a key prefix to seek for.
    • seekForPrev

      public void seekForPrev(byte[] target)
      Description copied from interface: RocksIteratorInterface

      Position at the first entry in the source whose key is that or before target.

      The iterator is valid after this call if the source contains a key that comes at or before target.

      Specified by:
      seekForPrev in interface RocksIteratorInterface
      Parameters:
      target - byte array describing a key or a key prefix to seek for.
    • seek

      public void seek(ByteBuffer target)
      Description copied from interface: RocksIteratorInterface

      Position at the first entry in the source whose key is that or past target.

      The iterator is valid after this call if the source contains a key that comes at or past target.

      Specified by:
      seek in interface RocksIteratorInterface
      Parameters:
      target - byte array describing a key or a key prefix to seek for. Supports direct buffer only.
    • seekForPrev

      public void seekForPrev(ByteBuffer target)
      Description copied from interface: RocksIteratorInterface

      Position at the last key that is less than or equal to the target key.

      The iterator is valid after this call if the source contains a key that comes at or past target.

      Specified by:
      seekForPrev in interface RocksIteratorInterface
      Parameters:
      target - byte array describing a key or a key prefix to seek for. Supports direct buffer only.
    • next

      public void next()
      Description copied from interface: RocksIteratorInterface

      Moves to the next entry in the source. After this call, Valid() is true if the iterator was not positioned at the last entry in the source.

      REQUIRES: RocksIteratorInterface.isValid()

      Specified by:
      next in interface RocksIteratorInterface
    • prev

      public void prev()
      Description copied from interface: RocksIteratorInterface

      Moves to the previous entry in the source. After this call, Valid() is true if the iterator was not positioned at the first entry in source.

      REQUIRES: RocksIteratorInterface.isValid()

      Specified by:
      prev in interface RocksIteratorInterface
    • refresh

      public void refresh() throws RocksDBException
      Description copied from interface: RocksIteratorInterface

      If supported, the DB state that the iterator reads from is updated to the latest state. The iterator will be invalidated after the call. Regardless of whether the iterator was created/refreshed previously with or without a snapshot, the iterator will be reading the latest DB state after this call.

      Note that you will need to call a Seek*() function to get the iterator back into a valid state before calling a function that assumes the state is already valid, like Next().

      Specified by:
      refresh in interface RocksIteratorInterface
      Throws:
      RocksDBException - thrown if the operation is not supported or an error happens in the underlying native library
    • refresh

      public void refresh(Snapshot snapshot) throws RocksDBException
      Description copied from interface: RocksIteratorInterface
      Similar to RocksIteratorInterface.refresh() but the iterator will be reading the latest DB state under the given snapshot.
      Specified by:
      refresh in interface RocksIteratorInterface
      Throws:
      RocksDBException
    • status

      public void status() throws RocksDBException
      Description copied from interface: RocksIteratorInterface

      If an error has occurred, return it. Else return an ok status. If non-blocking IO is requested and this operation cannot be satisfied without doing some IO, then this returns Status::Incomplete().

      Specified by:
      status in interface RocksIteratorInterface
      Throws:
      RocksDBException - thrown if error happens in underlying native library.
    • disposeInternal

      protected void disposeInternal()

      Deletes underlying C++ iterator pointer.

      Note: the underlying handle can only be safely deleted if the parent instance related to a certain RocksIterator is still valid and initialized. Therefore disposeInternal() checks if the parent is initialized before freeing the native handle.

      Overrides:
      disposeInternal in class RocksObject