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:
    java.lang.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:
    RocksObject
    • Constructor Detail

      • AbstractRocksIterator

        protected AbstractRocksIterator​(P parent,
                                        long nativeHandle)
    • Method Detail

      • 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
      • 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​(java.nio.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​(java.nio.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.
      • 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