Package org.rocksdb

Class RocksDB

  • All Implemented Interfaces:
    java.lang.AutoCloseable
    Direct Known Subclasses:
    OptimisticTransactionDB, TransactionDB, TtlDB

    public class RocksDB
    extends RocksObject
    A RocksDB is a persistent ordered map from keys to values. It is safe for concurrent access from multiple threads without any external synchronization. All methods of this class could potentially throw RocksDBException, which indicates sth wrong at the RocksDB library side and the call failed.
    • Constructor Detail

      • RocksDB

        protected RocksDB​(long nativeHandle)
        Private constructor.
        Parameters:
        nativeHandle - The native handle of the C++ RocksDB object
    • Method Detail

      • loadLibrary

        public static void loadLibrary()
        Loads the necessary library files. Calling this method twice will have no effect. By default the method extracts the shared library for loading at java.io.tmpdir, however, you can override this temporary location by setting the environment variable ROCKSDB_SHAREDLIB_DIR.
      • loadLibrary

        public static void loadLibrary​(java.util.List<java.lang.String> paths)
        Tries to load the necessary library files from the given list of directories.
        Parameters:
        paths - a list of strings where each describes a directory of a library.
      • open

        public static RocksDB open​(java.lang.String path)
                            throws RocksDBException
        The factory constructor of RocksDB that opens a RocksDB instance given the path to the database using the default options w/ createIfMissing set to true.
        Parameters:
        path - the path to the rocksdb.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        See Also:
        Options.setCreateIfMissing(boolean)
      • open

        public static RocksDB open​(java.lang.String path,
                                   java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors,
                                   java.util.List<ColumnFamilyHandle> columnFamilyHandles)
                            throws RocksDBException
        The factory constructor of RocksDB that opens a RocksDB instance given the path to the database using the specified options and db path and a list of column family names.

        If opened in read write mode every existing column family name must be passed within the list to this method.

        If opened in read-only mode only a subset of existing column families must be passed to this method.

        Options instance *should* not be disposed before all DBs using this options instance have been closed. If user doesn't call options dispose explicitly, then this options instance will be GC'd automatically

        ColumnFamily handles are disposed when the RocksDB instance is disposed.

        Parameters:
        path - the path to the rocksdb.
        columnFamilyDescriptors - list of column family descriptors
        columnFamilyHandles - will be filled with ColumnFamilyHandle instances on open.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        See Also:
        DBOptions.setCreateIfMissing(boolean)
      • open

        public static RocksDB open​(Options options,
                                   java.lang.String path)
                            throws RocksDBException
        The factory constructor of RocksDB that opens a RocksDB instance given the path to the database using the specified options and db path.

        Options instance *should* not be disposed before all DBs using this options instance have been closed. If user doesn't call options dispose explicitly, then this options instance will be GC'd automatically.

        Options instance can be re-used to open multiple DBs if DB statistics is not used. If DB statistics are required, then its recommended to open DB with new Options instance as underlying native statistics instance does not use any locks to prevent concurrent updates.

        Parameters:
        options - Options instance.
        path - the path to the rocksdb.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        See Also:
        Options.setCreateIfMissing(boolean)
      • open

        public static RocksDB open​(DBOptions options,
                                   java.lang.String path,
                                   java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors,
                                   java.util.List<ColumnFamilyHandle> columnFamilyHandles)
                            throws RocksDBException
        The factory constructor of RocksDB that opens a RocksDB instance given the path to the database using the specified options and db path and a list of column family names.

        If opened in read write mode every existing column family name must be passed within the list to this method.

        If opened in read-only mode only a subset of existing column families must be passed to this method.

        Options instance *should* not be disposed before all DBs using this options instance have been closed. If user doesn't call options dispose explicitly, then this options instance will be GC'd automatically.

        Options instance can be re-used to open multiple DBs if DB statistics is not used. If DB statistics are required, then its recommended to open DB with new Options instance as underlying native statistics instance does not use any locks to prevent concurrent updates.

        ColumnFamily handles are disposed when the RocksDB instance is disposed.

        Parameters:
        options - DBOptions instance.
        path - the path to the rocksdb.
        columnFamilyDescriptors - list of column family descriptors
        columnFamilyHandles - will be filled with ColumnFamilyHandle instances on open.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        See Also:
        DBOptions.setCreateIfMissing(boolean)
      • openReadOnly

        public static RocksDB openReadOnly​(java.lang.String path)
                                    throws RocksDBException
        The factory constructor of RocksDB that opens a RocksDB instance in Read-Only mode given the path to the database using the default options.
        Parameters:
        path - the path to the RocksDB.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • openReadOnly

        public static RocksDB openReadOnly​(Options options,
                                           java.lang.String path)
                                    throws RocksDBException
        The factory constructor of RocksDB that opens a RocksDB instance in Read-Only mode given the path to the database using the specified options and db path. Options instance *should* not be disposed before all DBs using this options instance have been closed. If user doesn't call options dispose explicitly, then this options instance will be GC'd automatically.
        Parameters:
        options - Options instance.
        path - the path to the RocksDB.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • openReadOnly

        public static RocksDB openReadOnly​(Options options,
                                           java.lang.String path,
                                           boolean errorIfWalFileExists)
                                    throws RocksDBException
        The factory constructor of RocksDB that opens a RocksDB instance in Read-Only mode given the path to the database using the specified options and db path. Options instance *should* not be disposed before all DBs using this options instance have been closed. If user doesn't call options dispose explicitly, then this options instance will be GC'd automatically.
        Parameters:
        options - Options instance.
        path - the path to the RocksDB.
        errorIfWalFileExists - true to raise an error when opening the db if a Write Ahead Log file exists, false otherwise.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • openReadOnly

        public static RocksDB openReadOnly​(java.lang.String path,
                                           java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors,
                                           java.util.List<ColumnFamilyHandle> columnFamilyHandles)
                                    throws RocksDBException
        The factory constructor of RocksDB that opens a RocksDB instance in Read-Only mode given the path to the database using the default options.
        Parameters:
        path - the path to the RocksDB.
        columnFamilyDescriptors - list of column family descriptors
        columnFamilyHandles - will be filled with ColumnFamilyHandle instances on open.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • openReadOnly

        public static RocksDB openReadOnly​(DBOptions options,
                                           java.lang.String path,
                                           java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors,
                                           java.util.List<ColumnFamilyHandle> columnFamilyHandles)
                                    throws RocksDBException
        The factory constructor of RocksDB that opens a RocksDB instance in Read-Only mode given the path to the database using the specified options and db path.

        This open method allows to open RocksDB using a subset of available column families

        Options instance *should* not be disposed before all DBs using this options instance have been closed. If user doesn't call options dispose explicitly,then this options instance will be GC'd automatically.

        Parameters:
        options - DBOptions instance.
        path - the path to the RocksDB.
        columnFamilyDescriptors - list of column family descriptors
        columnFamilyHandles - will be filled with ColumnFamilyHandle instances on open.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • openReadOnly

        public static RocksDB openReadOnly​(DBOptions options,
                                           java.lang.String path,
                                           java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors,
                                           java.util.List<ColumnFamilyHandle> columnFamilyHandles,
                                           boolean errorIfWalFileExists)
                                    throws RocksDBException
        The factory constructor of RocksDB that opens a RocksDB instance in Read-Only mode given the path to the database using the specified options and db path.

        This open method allows to open RocksDB using a subset of available column families

        Options instance *should* not be disposed before all DBs using this options instance have been closed. If user doesn't call options dispose explicitly,then this options instance will be GC'd automatically.

        Parameters:
        options - DBOptions instance.
        path - the path to the RocksDB.
        columnFamilyDescriptors - list of column family descriptors
        columnFamilyHandles - will be filled with ColumnFamilyHandle instances on open.
        errorIfWalFileExists - true to raise an error when opening the db if a Write Ahead Log file exists, false otherwise.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • openAsSecondary

        public static RocksDB openAsSecondary​(Options options,
                                              java.lang.String path,
                                              java.lang.String secondaryPath)
                                       throws RocksDBException
        Open DB as secondary instance with only the default column family. The secondary instance can dynamically tail the MANIFEST of a primary that must have already been created. User can call tryCatchUpWithPrimary() to make the secondary instance catch up with primary (WAL tailing is NOT supported now) whenever the user feels necessary. Column families created by the primary after the secondary instance starts are currently ignored by the secondary instance. Column families opened by secondary and dropped by the primary will be dropped by secondary as well. However the user of the secondary instance can still access the data of such dropped column family as long as they do not destroy the corresponding column family handle. WAL tailing is not supported at present, but will arrive soon.
        Parameters:
        options - the options to open the secondary instance.
        path - the path to the primary RocksDB instance.
        secondaryPath - points to a directory where the secondary instance stores its info log
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • openAsSecondary

        public static RocksDB openAsSecondary​(DBOptions options,
                                              java.lang.String path,
                                              java.lang.String secondaryPath,
                                              java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors,
                                              java.util.List<ColumnFamilyHandle> columnFamilyHandles)
                                       throws RocksDBException
        Open DB as secondary instance with column families. You can open a subset of column families in secondary mode. The secondary instance can dynamically tail the MANIFEST of a primary that must have already been created. User can call tryCatchUpWithPrimary() to make the secondary instance catch up with primary (WAL tailing is NOT supported now) whenever the user feels necessary. Column families created by the primary after the secondary instance starts are currently ignored by the secondary instance. Column families opened by secondary and dropped by the primary will be dropped by secondary as well. However the user of the secondary instance can still access the data of such dropped column family as long as they do not destroy the corresponding column family handle. WAL tailing is not supported at present, but will arrive soon.
        Parameters:
        options - the options to open the secondary instance.
        path - the path to the primary RocksDB instance.
        secondaryPath - points to a directory where the secondary instance stores its info log.
        columnFamilyDescriptors - list of column family descriptors
        columnFamilyHandles - will be filled with ColumnFamilyHandle instances on open.
        Returns:
        a RocksDB instance on success, null if the specified RocksDB can not be opened.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • listColumnFamilies

        public static java.util.List<byte[]> listColumnFamilies​(Options options,
                                                                java.lang.String path)
                                                         throws RocksDBException
        Static method to determine all available column families for a rocksdb database identified by path
        Parameters:
        options - Options for opening the database
        path - Absolute path to rocksdb database
        Returns:
        List<byte[]> List containing the column family names
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • createColumnFamily

        public ColumnFamilyHandle createColumnFamily​(ColumnFamilyDescriptor columnFamilyDescriptor)
                                              throws RocksDBException
        Creates a new column family with the name columnFamilyName and allocates a ColumnFamilyHandle within an internal structure. The ColumnFamilyHandle is automatically disposed with DB disposal.
        Parameters:
        columnFamilyDescriptor - column family to be created.
        Returns:
        ColumnFamilyHandle instance.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • createColumnFamilies

        public java.util.List<ColumnFamilyHandle> createColumnFamilies​(ColumnFamilyOptions columnFamilyOptions,
                                                                       java.util.List<byte[]> columnFamilyNames)
                                                                throws RocksDBException
        Bulk create column families with the same column family options.
        Parameters:
        columnFamilyOptions - the options for the column families.
        columnFamilyNames - the names of the column families.
        Returns:
        the handles to the newly created column families.
        Throws:
        RocksDBException - if an error occurs whilst creating the column families
      • createColumnFamilies

        public java.util.List<ColumnFamilyHandle> createColumnFamilies​(java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors)
                                                                throws RocksDBException
        Bulk create column families with the same column family options.
        Parameters:
        columnFamilyDescriptors - the descriptions of the column families.
        Returns:
        the handles to the newly created column families.
        Throws:
        RocksDBException - if an error occurs whilst creating the column families
      • dropColumnFamily

        public void dropColumnFamily​(ColumnFamilyHandle columnFamilyHandle)
                              throws RocksDBException
        Drops the column family specified by columnFamilyHandle. This call only records a drop record in the manifest and prevents the column family from flushing and compacting.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • destroyColumnFamilyHandle

        public void destroyColumnFamilyHandle​(ColumnFamilyHandle columnFamilyHandle)
        Deletes native column family handle of given ColumnFamilyHandle Java object and removes reference from ownedColumnFamilyHandles.
        Parameters:
        columnFamilyHandle - column family handle object.
      • put

        public void put​(byte[] key,
                        byte[] value)
                 throws RocksDBException
        Set the database entry for "key" to "value".
        Parameters:
        key - the specified key to be inserted.
        value - the value associated with the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • put

        public void put​(byte[] key,
                        int offset,
                        int len,
                        byte[] value,
                        int vOffset,
                        int vLen)
                 throws RocksDBException
        Set the database entry for "key" to "value".
        Parameters:
        key - The specified key to be inserted
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        value - the value associated with the specified key
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, must be non-negative and no larger than ("value".length - offset)
        Throws:
        RocksDBException - thrown if errors happens in underlying native library.
        java.lang.IndexOutOfBoundsException - if an offset or length is out of bounds
      • put

        public void put​(ColumnFamilyHandle columnFamilyHandle,
                        byte[] key,
                        byte[] value)
                 throws RocksDBException
        Set the database entry for "key" to "value" in the specified column family.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the specified key to be inserted.
        value - the value associated with the specified key. throws IllegalArgumentException if column family is not present
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • put

        public void put​(ColumnFamilyHandle columnFamilyHandle,
                        byte[] key,
                        int offset,
                        int len,
                        byte[] value,
                        int vOffset,
                        int vLen)
                 throws RocksDBException
        Set the database entry for "key" to "value" in the specified column family.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - The specified key to be inserted
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        value - the value associated with the specified key
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, must be non-negative and no larger than ("value".length - offset)
        Throws:
        RocksDBException - thrown if errors happens in underlying native library.
        java.lang.IndexOutOfBoundsException - if an offset or length is out of bounds
      • put

        public void put​(WriteOptions writeOpts,
                        byte[] key,
                        byte[] value)
                 throws RocksDBException
        Set the database entry for "key" to "value".
        Parameters:
        writeOpts - WriteOptions instance.
        key - the specified key to be inserted.
        value - the value associated with the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • put

        public void put​(WriteOptions writeOpts,
                        byte[] key,
                        int offset,
                        int len,
                        byte[] value,
                        int vOffset,
                        int vLen)
                 throws RocksDBException
        Set the database entry for "key" to "value".
        Parameters:
        writeOpts - WriteOptions instance.
        key - The specified key to be inserted
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        value - the value associated with the specified key
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, must be non-negative and no larger than ("value".length - offset)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IndexOutOfBoundsException - if an offset or length is out of bounds
      • put

        public void put​(ColumnFamilyHandle columnFamilyHandle,
                        WriteOptions writeOpts,
                        byte[] key,
                        byte[] value)
                 throws RocksDBException
        Set the database entry for "key" to "value" for the specified column family.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        writeOpts - WriteOptions instance.
        key - the specified key to be inserted.
        value - the value associated with the specified key. throws IllegalArgumentException if column family is not present
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        See Also:
        IllegalArgumentException
      • put

        public void put​(ColumnFamilyHandle columnFamilyHandle,
                        WriteOptions writeOpts,
                        java.nio.ByteBuffer key,
                        java.nio.ByteBuffer value)
                 throws RocksDBException
        Set the database entry for "key" to "value" for the specified column family.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        writeOpts - WriteOptions instance.
        key - the specified key to be inserted. Position and limit is used. Supports direct buffer only.
        value - the value associated with the specified key. Position and limit is used. Supports direct buffer only. throws IllegalArgumentException if column family is not present
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        See Also:
        IllegalArgumentException
      • put

        public void put​(WriteOptions writeOpts,
                        java.nio.ByteBuffer key,
                        java.nio.ByteBuffer value)
                 throws RocksDBException
        Set the database entry for "key" to "value".
        Parameters:
        writeOpts - WriteOptions instance.
        key - the specified key to be inserted. Position and limit is used. Supports direct buffer only.
        value - the value associated with the specified key. Position and limit is used. Supports direct buffer only. throws IllegalArgumentException if column family is not present
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        See Also:
        IllegalArgumentException
      • put

        public void put​(ColumnFamilyHandle columnFamilyHandle,
                        WriteOptions writeOpts,
                        byte[] key,
                        int offset,
                        int len,
                        byte[] value,
                        int vOffset,
                        int vLen)
                 throws RocksDBException
        Set the database entry for "key" to "value" for the specified column family.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        writeOpts - WriteOptions instance.
        key - The specified key to be inserted
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        value - the value associated with the specified key
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, must be non-negative and no larger than ("value".length - offset)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IndexOutOfBoundsException - if an offset or length is out of bounds
      • remove

        @Deprecated
        public void remove​(byte[] key)
                    throws RocksDBException
        Deprecated.
        Remove the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • delete

        public void delete​(byte[] key)
                    throws RocksDBException
        Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • delete

        public void delete​(byte[] key,
                           int offset,
                           int len)
                    throws RocksDBException
        Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        key - Key to delete within database
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • delete

        public void delete​(ColumnFamilyHandle columnFamilyHandle,
                           byte[] key)
                    throws RocksDBException
        Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • delete

        public void delete​(ColumnFamilyHandle columnFamilyHandle,
                           byte[] key,
                           int offset,
                           int len)
                    throws RocksDBException
        Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - Key to delete within database
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("value".length - offset)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • remove

        @Deprecated
        public void remove​(WriteOptions writeOpt,
                           byte[] key)
                    throws RocksDBException
        Remove the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        writeOpt - WriteOptions to be used with delete operation
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • delete

        public void delete​(WriteOptions writeOpt,
                           byte[] key)
                    throws RocksDBException
        Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        writeOpt - WriteOptions to be used with delete operation
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • delete

        public void delete​(WriteOptions writeOpt,
                           byte[] key,
                           int offset,
                           int len)
                    throws RocksDBException
        Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        writeOpt - WriteOptions to be used with delete operation
        key - Key to delete within database
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • delete

        public void delete​(ColumnFamilyHandle columnFamilyHandle,
                           WriteOptions writeOpt,
                           byte[] key)
                    throws RocksDBException
        Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        writeOpt - WriteOptions to be used with delete operation
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • delete

        public void delete​(ColumnFamilyHandle columnFamilyHandle,
                           WriteOptions writeOpt,
                           byte[] key,
                           int offset,
                           int len)
                    throws RocksDBException
        Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        writeOpt - WriteOptions to be used with delete operation
        key - Key to delete within database
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public int get​(ReadOptions opt,
                       java.nio.ByteBuffer key,
                       java.nio.ByteBuffer value)
                throws RocksDBException
        Get the value associated with the specified key within column family.
        Parameters:
        opt - ReadOptions instance.
        key - the key to retrieve the value. It is using position and limit. Supports direct buffer only.
        value - the out-value to receive the retrieved value. It is using position and limit. Limit is set according to value size. Supports direct buffer only.
        Returns:
        The size of the actual value that matches the specified key in byte. If the return value is greater than the length of value, then it indicates that the size of the input buffer value is insufficient and partial result will be returned. RocksDB.NOT_FOUND will be returned if the value not found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public int get​(ColumnFamilyHandle columnFamilyHandle,
                       ReadOptions opt,
                       java.nio.ByteBuffer key,
                       java.nio.ByteBuffer value)
                throws RocksDBException
        Get the value associated with the specified key within column family.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        opt - ReadOptions instance.
        key - the key to retrieve the value. It is using position and limit. Supports direct buffer only.
        value - the out-value to receive the retrieved value. It is using position and limit. Limit is set according to value size. Supports direct buffer only.
        Returns:
        The size of the actual value that matches the specified key in byte. If the return value is greater than the length of value, then it indicates that the size of the input buffer value is insufficient and partial result will be returned. RocksDB.NOT_FOUND will be returned if the value not found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • singleDelete

        @Experimental("Performance optimization for a very specific workload")
        public void singleDelete​(byte[] key)
                          throws RocksDBException
        Remove the database entry for key. Requires that the key exists and was not overwritten. It is not an error if the key did not exist in the database. If a key is overwritten (by calling put(byte[], byte[]) multiple times), then the result of calling SingleDelete() on this key is undefined. SingleDelete() only behaves correctly if there has been only one Put() for this key since the previous call to SingleDelete() for this key. This feature is currently an experimental performance optimization for a very specific workload. It is up to the caller to ensure that SingleDelete is only used for a key that is not deleted using Delete() or written using Merge(). Mixing SingleDelete operations with Deletes and Merges can result in undefined behavior.
        Parameters:
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • singleDelete

        @Experimental("Performance optimization for a very specific workload")
        public void singleDelete​(ColumnFamilyHandle columnFamilyHandle,
                                 byte[] key)
                          throws RocksDBException
        Remove the database entry for key. Requires that the key exists and was not overwritten. It is not an error if the key did not exist in the database. If a key is overwritten (by calling put(byte[], byte[]) multiple times), then the result of calling SingleDelete() on this key is undefined. SingleDelete() only behaves correctly if there has been only one Put() for this key since the previous call to SingleDelete() for this key. This feature is currently an experimental performance optimization for a very specific workload. It is up to the caller to ensure that SingleDelete is only used for a key that is not deleted using Delete() or written using Merge(). Mixing SingleDelete operations with Deletes and Merges can result in undefined behavior.
        Parameters:
        columnFamilyHandle - The column family to delete the key from
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • singleDelete

        @Experimental("Performance optimization for a very specific workload")
        public void singleDelete​(WriteOptions writeOpt,
                                 byte[] key)
                          throws RocksDBException
        Remove the database entry for key. Requires that the key exists and was not overwritten. It is not an error if the key did not exist in the database. If a key is overwritten (by calling put(byte[], byte[]) multiple times), then the result of calling SingleDelete() on this key is undefined. SingleDelete() only behaves correctly if there has been only one Put() for this key since the previous call to SingleDelete() for this key. This feature is currently an experimental performance optimization for a very specific workload. It is up to the caller to ensure that SingleDelete is only used for a key that is not deleted using Delete() or written using Merge(). Mixing SingleDelete operations with Deletes and Merges can result in undefined behavior. Note: consider setting WriteOptions.setSync(boolean) true.
        Parameters:
        writeOpt - Write options for the delete
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • singleDelete

        @Experimental("Performance optimization for a very specific workload")
        public void singleDelete​(ColumnFamilyHandle columnFamilyHandle,
                                 WriteOptions writeOpt,
                                 byte[] key)
                          throws RocksDBException
        Remove the database entry for key. Requires that the key exists and was not overwritten. It is not an error if the key did not exist in the database. If a key is overwritten (by calling put(byte[], byte[]) multiple times), then the result of calling SingleDelete() on this key is undefined. SingleDelete() only behaves correctly if there has been only one Put() for this key since the previous call to SingleDelete() for this key. This feature is currently an experimental performance optimization for a very specific workload. It is up to the caller to ensure that SingleDelete is only used for a key that is not deleted using Delete() or written using Merge(). Mixing SingleDelete operations with Deletes and Merges can result in undefined behavior. Note: consider setting WriteOptions.setSync(boolean) true.
        Parameters:
        columnFamilyHandle - The column family to delete the key from
        writeOpt - Write options for the delete
        key - Key to delete within database
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • deleteRange

        public void deleteRange​(byte[] beginKey,
                                byte[] endKey)
                         throws RocksDBException
        Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey". a non-OK status on error. It is not an error if no keys exist in the range ["beginKey", "endKey"). Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        beginKey - First key to delete within database (inclusive)
        endKey - Last key to delete within database (exclusive)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • deleteRange

        public void deleteRange​(ColumnFamilyHandle columnFamilyHandle,
                                byte[] beginKey,
                                byte[] endKey)
                         throws RocksDBException
        Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey". a non-OK status on error. It is not an error if no keys exist in the range ["beginKey", "endKey"). Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        beginKey - First key to delete within database (inclusive)
        endKey - Last key to delete within database (exclusive)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • deleteRange

        public void deleteRange​(WriteOptions writeOpt,
                                byte[] beginKey,
                                byte[] endKey)
                         throws RocksDBException
        Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey". a non-OK status on error. It is not an error if no keys exist in the range ["beginKey", "endKey"). Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        writeOpt - WriteOptions to be used with delete operation
        beginKey - First key to delete within database (inclusive)
        endKey - Last key to delete within database (exclusive)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • deleteRange

        public void deleteRange​(ColumnFamilyHandle columnFamilyHandle,
                                WriteOptions writeOpt,
                                byte[] beginKey,
                                byte[] endKey)
                         throws RocksDBException
        Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey". a non-OK status on error. It is not an error if no keys exist in the range ["beginKey", "endKey"). Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        writeOpt - WriteOptions to be used with delete operation
        beginKey - First key to delete within database (included)
        endKey - Last key to delete within database (excluded)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • merge

        public void merge​(byte[] key,
                          byte[] value)
                   throws RocksDBException
        Add merge operand for key/value pair.
        Parameters:
        key - the specified key to be merged.
        value - the value to be merged with the current value for the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • merge

        public void merge​(byte[] key,
                          int offset,
                          int len,
                          byte[] value,
                          int vOffset,
                          int vLen)
                   throws RocksDBException
        Add merge operand for key/value pair.
        Parameters:
        key - the specified key to be merged.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        value - the value to be merged with the current value for the specified key.
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, must be non-negative and must be non-negative and no larger than ("value".length - offset)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IndexOutOfBoundsException - if an offset or length is out of bounds
      • merge

        public void merge​(ColumnFamilyHandle columnFamilyHandle,
                          byte[] key,
                          byte[] value)
                   throws RocksDBException
        Add merge operand for key/value pair in a ColumnFamily.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the specified key to be merged.
        value - the value to be merged with the current value for the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • merge

        public void merge​(ColumnFamilyHandle columnFamilyHandle,
                          byte[] key,
                          int offset,
                          int len,
                          byte[] value,
                          int vOffset,
                          int vLen)
                   throws RocksDBException
        Add merge operand for key/value pair in a ColumnFamily.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the specified key to be merged.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        value - the value to be merged with the current value for the specified key.
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, must be must be non-negative and no larger than ("value".length - offset)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IndexOutOfBoundsException - if an offset or length is out of bounds
      • merge

        public void merge​(WriteOptions writeOpts,
                          byte[] key,
                          byte[] value)
                   throws RocksDBException
        Add merge operand for key/value pair.
        Parameters:
        writeOpts - WriteOptions for this write.
        key - the specified key to be merged.
        value - the value to be merged with the current value for the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • merge

        public void merge​(WriteOptions writeOpts,
                          byte[] key,
                          int offset,
                          int len,
                          byte[] value,
                          int vOffset,
                          int vLen)
                   throws RocksDBException
        Add merge operand for key/value pair.
        Parameters:
        writeOpts - WriteOptions for this write.
        key - the specified key to be merged.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("value".length - offset)
        value - the value to be merged with the current value for the specified key.
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, must be non-negative and no larger than ("value".length - offset)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IndexOutOfBoundsException - if an offset or length is out of bounds
      • delete

        public void delete​(WriteOptions writeOpt,
                           java.nio.ByteBuffer key)
                    throws RocksDBException
        Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        writeOpt - WriteOptions to be used with delete operation
        key - Key to delete within database. It is using position and limit. Supports direct buffer only.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • delete

        public void delete​(ColumnFamilyHandle columnFamilyHandle,
                           WriteOptions writeOpt,
                           java.nio.ByteBuffer key)
                    throws RocksDBException
        Delete the database entry (if any) for "key". Returns OK on success, and a non-OK status on error. It is not an error if "key" did not exist in the database.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        writeOpt - WriteOptions to be used with delete operation
        key - Key to delete within database. It is using position and limit. Supports direct buffer only.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • merge

        public void merge​(ColumnFamilyHandle columnFamilyHandle,
                          WriteOptions writeOpts,
                          byte[] key,
                          byte[] value)
                   throws RocksDBException
        Add merge operand for key/value pair.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        writeOpts - WriteOptions for this write.
        key - the specified key to be merged.
        value - the value to be merged with the current value for the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • merge

        public void merge​(ColumnFamilyHandle columnFamilyHandle,
                          WriteOptions writeOpts,
                          byte[] key,
                          int offset,
                          int len,
                          byte[] value,
                          int vOffset,
                          int vLen)
                   throws RocksDBException
        Add merge operand for key/value pair.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        writeOpts - WriteOptions for this write.
        key - the specified key to be merged.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        value - the value to be merged with the current value for the specified key.
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, must be non-negative and no larger than ("value".length - offset)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IndexOutOfBoundsException - if an offset or length is out of bounds
      • write

        public void write​(WriteOptions writeOpts,
                          WriteBatch updates)
                   throws RocksDBException
        Apply the specified updates to the database.
        Parameters:
        writeOpts - WriteOptions instance
        updates - WriteBatch instance
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • write

        public void write​(WriteOptions writeOpts,
                          WriteBatchWithIndex updates)
                   throws RocksDBException
        Apply the specified updates to the database.
        Parameters:
        writeOpts - WriteOptions instance
        updates - WriteBatchWithIndex instance
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public int get​(byte[] key,
                       byte[] value)
                throws RocksDBException
        Get the value associated with the specified key within column family*
        Parameters:
        key - the key to retrieve the value.
        value - the out-value to receive the retrieved value.
        Returns:
        The size of the actual value that matches the specified key in byte. If the return value is greater than the length of value, then it indicates that the size of the input buffer value is insufficient and partial result will be returned. RocksDB.NOT_FOUND will be returned if the value not found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public int get​(byte[] key,
                       int offset,
                       int len,
                       byte[] value,
                       int vOffset,
                       int vLen)
                throws RocksDBException
        Get the value associated with the specified key within column family*
        Parameters:
        key - the key to retrieve the value.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        value - the out-value to receive the retrieved value.
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "value".length
        vLen - the length of the "value" array to be used, must be non-negative and and no larger than ("value".length - offset)
        Returns:
        The size of the actual value that matches the specified key in byte. If the return value is greater than the length of value, then it indicates that the size of the input buffer value is insufficient and partial result will be returned. RocksDB.NOT_FOUND will be returned if the value not found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public int get​(ColumnFamilyHandle columnFamilyHandle,
                       byte[] key,
                       byte[] value)
                throws RocksDBException,
                       java.lang.IllegalArgumentException
        Get the value associated with the specified key within column family.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the key to retrieve the value.
        value - the out-value to receive the retrieved value.
        Returns:
        The size of the actual value that matches the specified key in byte. If the return value is greater than the length of value, then it indicates that the size of the input buffer value is insufficient and partial result will be returned. RocksDB.NOT_FOUND will be returned if the value not found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IllegalArgumentException
      • get

        public int get​(ColumnFamilyHandle columnFamilyHandle,
                       byte[] key,
                       int offset,
                       int len,
                       byte[] value,
                       int vOffset,
                       int vLen)
                throws RocksDBException,
                       java.lang.IllegalArgumentException
        Get the value associated with the specified key within column family.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the key to retrieve the value.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative an no larger than ("key".length - offset)
        value - the out-value to receive the retrieved value.
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, must be non-negative and no larger than ("value".length - offset)
        Returns:
        The size of the actual value that matches the specified key in byte. If the return value is greater than the length of value, then it indicates that the size of the input buffer value is insufficient and partial result will be returned. RocksDB.NOT_FOUND will be returned if the value not found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IllegalArgumentException
      • get

        public int get​(ReadOptions opt,
                       byte[] key,
                       byte[] value)
                throws RocksDBException
        Get the value associated with the specified key.
        Parameters:
        opt - ReadOptions instance.
        key - the key to retrieve the value.
        value - the out-value to receive the retrieved value.
        Returns:
        The size of the actual value that matches the specified key in byte. If the return value is greater than the length of value, then it indicates that the size of the input buffer value is insufficient and partial result will be returned. RocksDB.NOT_FOUND will be returned if the value not found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public int get​(ReadOptions opt,
                       byte[] key,
                       int offset,
                       int len,
                       byte[] value,
                       int vOffset,
                       int vLen)
                throws RocksDBException
        Get the value associated with the specified key.
        Parameters:
        opt - ReadOptions instance.
        key - the key to retrieve the value.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        value - the out-value to receive the retrieved value.
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, must be non-negative and no larger than ("value".length - offset)
        Returns:
        The size of the actual value that matches the specified key in byte. If the return value is greater than the length of value, then it indicates that the size of the input buffer value is insufficient and partial result will be returned. RocksDB.NOT_FOUND will be returned if the value not found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public int get​(ColumnFamilyHandle columnFamilyHandle,
                       ReadOptions opt,
                       byte[] key,
                       byte[] value)
                throws RocksDBException
        Get the value associated with the specified key within column family.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        opt - ReadOptions instance.
        key - the key to retrieve the value.
        value - the out-value to receive the retrieved value.
        Returns:
        The size of the actual value that matches the specified key in byte. If the return value is greater than the length of value, then it indicates that the size of the input buffer value is insufficient and partial result will be returned. RocksDB.NOT_FOUND will be returned if the value not found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public int get​(ColumnFamilyHandle columnFamilyHandle,
                       ReadOptions opt,
                       byte[] key,
                       int offset,
                       int len,
                       byte[] value,
                       int vOffset,
                       int vLen)
                throws RocksDBException
        Get the value associated with the specified key within column family.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        opt - ReadOptions instance.
        key - the key to retrieve the value.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and and no larger than ("key".length - offset)
        value - the out-value to receive the retrieved value.
        vOffset - the offset of the "value" array to be used, must be non-negative and no longer than "key".length
        vLen - the length of the "value" array to be used, and must be non-negative and no larger than ("value".length - offset)
        Returns:
        The size of the actual value that matches the specified key in byte. If the return value is greater than the length of value, then it indicates that the size of the input buffer value is insufficient and partial result will be returned. RocksDB.NOT_FOUND will be returned if the value not found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public byte[] get​(byte[] key)
                   throws RocksDBException
        The simplified version of get which returns a new byte array storing the value associated with the specified input key if any. null will be returned if the specified key is not found.
        Parameters:
        key - the key retrieve the value.
        Returns:
        a byte array storing the value associated with the input key if any. null if it does not find the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public byte[] get​(byte[] key,
                          int offset,
                          int len)
                   throws RocksDBException
        The simplified version of get which returns a new byte array storing the value associated with the specified input key if any. null will be returned if the specified key is not found.
        Parameters:
        key - the key retrieve the value.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        Returns:
        a byte array storing the value associated with the input key if any. null if it does not find the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public byte[] get​(ColumnFamilyHandle columnFamilyHandle,
                          byte[] key)
                   throws RocksDBException
        The simplified version of get which returns a new byte array storing the value associated with the specified input key if any. null will be returned if the specified key is not found.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the key retrieve the value.
        Returns:
        a byte array storing the value associated with the input key if any. null if it does not find the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public byte[] get​(ColumnFamilyHandle columnFamilyHandle,
                          byte[] key,
                          int offset,
                          int len)
                   throws RocksDBException
        The simplified version of get which returns a new byte array storing the value associated with the specified input key if any. null will be returned if the specified key is not found.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the key retrieve the value.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        Returns:
        a byte array storing the value associated with the input key if any. null if it does not find the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public byte[] get​(ReadOptions opt,
                          byte[] key)
                   throws RocksDBException
        The simplified version of get which returns a new byte array storing the value associated with the specified input key if any. null will be returned if the specified key is not found.
        Parameters:
        key - the key retrieve the value.
        opt - Read options.
        Returns:
        a byte array storing the value associated with the input key if any. null if it does not find the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public byte[] get​(ReadOptions opt,
                          byte[] key,
                          int offset,
                          int len)
                   throws RocksDBException
        The simplified version of get which returns a new byte array storing the value associated with the specified input key if any. null will be returned if the specified key is not found.
        Parameters:
        key - the key retrieve the value.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        opt - Read options.
        Returns:
        a byte array storing the value associated with the input key if any. null if it does not find the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public byte[] get​(ColumnFamilyHandle columnFamilyHandle,
                          ReadOptions opt,
                          byte[] key)
                   throws RocksDBException
        The simplified version of get which returns a new byte array storing the value associated with the specified input key if any. null will be returned if the specified key is not found.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the key retrieve the value.
        opt - Read options.
        Returns:
        a byte array storing the value associated with the input key if any. null if it does not find the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • get

        public byte[] get​(ColumnFamilyHandle columnFamilyHandle,
                          ReadOptions opt,
                          byte[] key,
                          int offset,
                          int len)
                   throws RocksDBException
        The simplified version of get which returns a new byte array storing the value associated with the specified input key if any. null will be returned if the specified key is not found.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - the key retrieve the value.
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than ("key".length - offset)
        opt - Read options.
        Returns:
        a byte array storing the value associated with the input key if any. null if it does not find the specified key.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • multiGet

        @Deprecated
        public java.util.Map<byte[],​byte[]> multiGet​(java.util.List<byte[]> keys)
                                                    throws RocksDBException
        Deprecated.
        Consider multiGetAsList(List) instead.
        Returns a map of keys for which values were found in DB.
        Parameters:
        keys - List of keys for which values need to be retrieved.
        Returns:
        Map where key of map is the key passed by user and value for map entry is the corresponding value in DB.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • multiGet

        @Deprecated
        public java.util.Map<byte[],​byte[]> multiGet​(java.util.List<ColumnFamilyHandle> columnFamilyHandleList,
                                                           java.util.List<byte[]> keys)
                                                    throws RocksDBException,
                                                           java.lang.IllegalArgumentException
        Deprecated.
        Consider multiGetAsList(List, List) instead.
        Returns a map of keys for which values were found in DB.

        Note: Every key needs to have a related column family name in columnFamilyHandleList.

        Parameters:
        columnFamilyHandleList - List containing ColumnFamilyHandle instances.
        keys - List of keys for which values need to be retrieved.
        Returns:
        Map where key of map is the key passed by user and value for map entry is the corresponding value in DB.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IllegalArgumentException - thrown if the size of passed keys is not equal to the amount of passed column family handles.
      • multiGet

        @Deprecated
        public java.util.Map<byte[],​byte[]> multiGet​(ReadOptions opt,
                                                           java.util.List<byte[]> keys)
                                                    throws RocksDBException
        Deprecated.
        Returns a map of keys for which values were found in DB.
        Parameters:
        opt - Read options.
        keys - of keys for which values need to be retrieved.
        Returns:
        Map where key of map is the key passed by user and value for map entry is the corresponding value in DB.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • multiGet

        @Deprecated
        public java.util.Map<byte[],​byte[]> multiGet​(ReadOptions opt,
                                                           java.util.List<ColumnFamilyHandle> columnFamilyHandleList,
                                                           java.util.List<byte[]> keys)
                                                    throws RocksDBException
        Deprecated.
        Returns a map of keys for which values were found in DB.

        Note: Every key needs to have a related column family name in columnFamilyHandleList.

        Parameters:
        opt - Read options.
        columnFamilyHandleList - List containing ColumnFamilyHandle instances.
        keys - of keys for which values need to be retrieved.
        Returns:
        Map where key of map is the key passed by user and value for map entry is the corresponding value in DB.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IllegalArgumentException - thrown if the size of passed keys is not equal to the amount of passed column family handles.
      • multiGetAsList

        public java.util.List<byte[]> multiGetAsList​(java.util.List<byte[]> keys)
                                              throws RocksDBException
        Takes a list of keys, and returns a list of values for the given list of keys. List will contain null for keys which could not be found.
        Parameters:
        keys - List of keys for which values need to be retrieved.
        Returns:
        List of values for the given list of keys. List will contain null for keys which could not be found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • multiGetAsList

        public java.util.List<byte[]> multiGetAsList​(java.util.List<ColumnFamilyHandle> columnFamilyHandleList,
                                                     java.util.List<byte[]> keys)
                                              throws RocksDBException,
                                                     java.lang.IllegalArgumentException
        Returns a list of values for the given list of keys. List will contain null for keys which could not be found.

        Note: Every key needs to have a related column family name in columnFamilyHandleList.

        Parameters:
        columnFamilyHandleList - List containing ColumnFamilyHandle instances.
        keys - List of keys for which values need to be retrieved.
        Returns:
        List of values for the given list of keys. List will contain null for keys which could not be found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IllegalArgumentException - thrown if the size of passed keys is not equal to the amount of passed column family handles.
      • multiGetAsList

        public java.util.List<byte[]> multiGetAsList​(ReadOptions opt,
                                                     java.util.List<byte[]> keys)
                                              throws RocksDBException
        Returns a list of values for the given list of keys. List will contain null for keys which could not be found.
        Parameters:
        opt - Read options.
        keys - of keys for which values need to be retrieved.
        Returns:
        List of values for the given list of keys. List will contain null for keys which could not be found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • multiGetAsList

        public java.util.List<byte[]> multiGetAsList​(ReadOptions opt,
                                                     java.util.List<ColumnFamilyHandle> columnFamilyHandleList,
                                                     java.util.List<byte[]> keys)
                                              throws RocksDBException
        Returns a list of values for the given list of keys. List will contain null for keys which could not be found.

        Note: Every key needs to have a related column family name in columnFamilyHandleList.

        Parameters:
        opt - Read options.
        columnFamilyHandleList - List containing ColumnFamilyHandle instances.
        keys - of keys for which values need to be retrieved.
        Returns:
        List of values for the given list of keys. List will contain null for keys which could not be found.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
        java.lang.IllegalArgumentException - thrown if the size of passed keys is not equal to the amount of passed column family handles.
      • keyMayExist

        public boolean keyMayExist​(byte[] key,
                                   Holder<byte[]> valueHolder)
        If the key definitely does not exist in the database, then this method returns false, otherwise it returns true if the key might exist. That is to say that this method is probabilistic and may return false positives, but never a true negative. If the caller wants to obtain value when the key is found in memory, then valueHolder must be set. This check is potentially lighter-weight than invoking get(byte[]). One way to make this lighter weight is to avoid doing any IOs.
        Parameters:
        key - byte array of a key to search for
        valueHolder - non-null to retrieve the value if it is found, or null if the value is not needed. If non-null, upon return of the function, the value will be set if it could be retrieved.
        Returns:
        false if the key definitely does not exist in the database, otherwise true.
      • keyMayExist

        public boolean keyMayExist​(byte[] key,
                                   int offset,
                                   int len,
                                   Holder<byte[]> valueHolder)
        If the key definitely does not exist in the database, then this method returns false, otherwise it returns true if the key might exist. That is to say that this method is probabilistic and may return false positives, but never a true negative. If the caller wants to obtain value when the key is found in memory, then valueHolder must be set. This check is potentially lighter-weight than invoking get(byte[], int, int). One way to make this lighter weight is to avoid doing any IOs.
        Parameters:
        key - byte array of a key to search for
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than "key".length
        valueHolder - non-null to retrieve the value if it is found, or null if the value is not needed. If non-null, upon return of the function, the value will be set if it could be retrieved.
        Returns:
        false if the key definitely does not exist in the database, otherwise true.
      • keyMayExist

        public boolean keyMayExist​(ColumnFamilyHandle columnFamilyHandle,
                                   byte[] key,
                                   Holder<byte[]> valueHolder)
        If the key definitely does not exist in the database, then this method returns false, otherwise it returns true if the key might exist. That is to say that this method is probabilistic and may return false positives, but never a true negative. If the caller wants to obtain value when the key is found in memory, then valueHolder must be set. This check is potentially lighter-weight than invoking get(ColumnFamilyHandle,byte[]). One way to make this lighter weight is to avoid doing any IOs.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - byte array of a key to search for
        valueHolder - non-null to retrieve the value if it is found, or null if the value is not needed. If non-null, upon return of the function, the value will be set if it could be retrieved.
        Returns:
        false if the key definitely does not exist in the database, otherwise true.
      • keyMayExist

        public boolean keyMayExist​(ColumnFamilyHandle columnFamilyHandle,
                                   byte[] key,
                                   int offset,
                                   int len,
                                   Holder<byte[]> valueHolder)
        If the key definitely does not exist in the database, then this method returns false, otherwise it returns true if the key might exist. That is to say that this method is probabilistic and may return false positives, but never a true negative. If the caller wants to obtain value when the key is found in memory, then valueHolder must be set. This check is potentially lighter-weight than invoking get(ColumnFamilyHandle, byte[], int, int). One way to make this lighter weight is to avoid doing any IOs.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        key - byte array of a key to search for
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than "key".length
        valueHolder - non-null to retrieve the value if it is found, or null if the value is not needed. If non-null, upon return of the function, the value will be set if it could be retrieved.
        Returns:
        false if the key definitely does not exist in the database, otherwise true.
      • keyMayExist

        public boolean keyMayExist​(ReadOptions readOptions,
                                   byte[] key,
                                   Holder<byte[]> valueHolder)
        If the key definitely does not exist in the database, then this method returns false, otherwise it returns true if the key might exist. That is to say that this method is probabilistic and may return false positives, but never a true negative. If the caller wants to obtain value when the key is found in memory, then valueHolder must be set. This check is potentially lighter-weight than invoking get(ReadOptions, byte[]). One way to make this lighter weight is to avoid doing any IOs.
        Parameters:
        readOptions - ReadOptions instance
        key - byte array of a key to search for
        valueHolder - non-null to retrieve the value if it is found, or null if the value is not needed. If non-null, upon return of the function, the value will be set if it could be retrieved.
        Returns:
        false if the key definitely does not exist in the database, otherwise true.
      • keyMayExist

        public boolean keyMayExist​(ReadOptions readOptions,
                                   byte[] key,
                                   int offset,
                                   int len,
                                   Holder<byte[]> valueHolder)
        If the key definitely does not exist in the database, then this method returns false, otherwise it returns true if the key might exist. That is to say that this method is probabilistic and may return false positives, but never a true negative. If the caller wants to obtain value when the key is found in memory, then valueHolder must be set. This check is potentially lighter-weight than invoking get(ReadOptions, byte[], int, int). One way to make this lighter weight is to avoid doing any IOs.
        Parameters:
        readOptions - ReadOptions instance
        key - byte array of a key to search for
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than "key".length
        valueHolder - non-null to retrieve the value if it is found, or null if the value is not needed. If non-null, upon return of the function, the value will be set if it could be retrieved.
        Returns:
        false if the key definitely does not exist in the database, otherwise true.
      • keyMayExist

        public boolean keyMayExist​(ColumnFamilyHandle columnFamilyHandle,
                                   ReadOptions readOptions,
                                   byte[] key,
                                   Holder<byte[]> valueHolder)
        If the key definitely does not exist in the database, then this method returns false, otherwise it returns true if the key might exist. That is to say that this method is probabilistic and may return false positives, but never a true negative. If the caller wants to obtain value when the key is found in memory, then valueHolder must be set. This check is potentially lighter-weight than invoking get(ColumnFamilyHandle, ReadOptions, byte[]). One way to make this lighter weight is to avoid doing any IOs.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        readOptions - ReadOptions instance
        key - byte array of a key to search for
        valueHolder - non-null to retrieve the value if it is found, or null if the value is not needed. If non-null, upon return of the function, the value will be set if it could be retrieved.
        Returns:
        false if the key definitely does not exist in the database, otherwise true.
      • keyMayExist

        public boolean keyMayExist​(ColumnFamilyHandle columnFamilyHandle,
                                   ReadOptions readOptions,
                                   byte[] key,
                                   int offset,
                                   int len,
                                   Holder<byte[]> valueHolder)
        If the key definitely does not exist in the database, then this method returns false, otherwise it returns true if the key might exist. That is to say that this method is probabilistic and may return false positives, but never a true negative. If the caller wants to obtain value when the key is found in memory, then valueHolder must be set. This check is potentially lighter-weight than invoking get(ColumnFamilyHandle, ReadOptions, byte[], int, int). One way to make this lighter weight is to avoid doing any IOs.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        readOptions - ReadOptions instance
        key - byte array of a key to search for
        offset - the offset of the "key" array to be used, must be non-negative and no larger than "key".length
        len - the length of the "key" array to be used, must be non-negative and no larger than "key".length
        valueHolder - non-null to retrieve the value if it is found, or null if the value is not needed. If non-null, upon return of the function, the value will be set if it could be retrieved.
        Returns:
        false if the key definitely does not exist in the database, otherwise true.
      • newIterator

        public RocksIterator newIterator()

        Return a heap-allocated iterator over the contents of the database. The result of newIterator() is initially invalid (caller must call one of the Seek methods on the iterator before using it).

        Caller should close the iterator when it is no longer needed. The returned iterator should be closed before this db is closed.

        Returns:
        instance of iterator object.
      • newIterator

        public RocksIterator newIterator​(ReadOptions readOptions)

        Return a heap-allocated iterator over the contents of the database. The result of newIterator() is initially invalid (caller must call one of the Seek methods on the iterator before using it).

        Caller should close the iterator when it is no longer needed. The returned iterator should be closed before this db is closed.

        Parameters:
        readOptions - ReadOptions instance.
        Returns:
        instance of iterator object.
      • newIterator

        public RocksIterator newIterator​(ColumnFamilyHandle columnFamilyHandle)

        Return a heap-allocated iterator over the contents of a ColumnFamily. The result of newIterator() is initially invalid (caller must call one of the Seek methods on the iterator before using it).

        Caller should close the iterator when it is no longer needed. The returned iterator should be closed before this db is closed.

        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        Returns:
        instance of iterator object.
      • newIterator

        public RocksIterator newIterator​(ColumnFamilyHandle columnFamilyHandle,
                                         ReadOptions readOptions)

        Return a heap-allocated iterator over the contents of a ColumnFamily. The result of newIterator() is initially invalid (caller must call one of the Seek methods on the iterator before using it).

        Caller should close the iterator when it is no longer needed. The returned iterator should be closed before this db is closed.

        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance
        readOptions - ReadOptions instance.
        Returns:
        instance of iterator object.
      • newIterators

        public java.util.List<RocksIterator> newIterators​(java.util.List<ColumnFamilyHandle> columnFamilyHandleList)
                                                   throws RocksDBException
        Returns iterators from a consistent database state across multiple column families. Iterators are heap allocated and need to be deleted before the db is deleted
        Parameters:
        columnFamilyHandleList - List containing ColumnFamilyHandle instances.
        Returns:
        List containing RocksIterator instances
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • newIterators

        public java.util.List<RocksIterator> newIterators​(java.util.List<ColumnFamilyHandle> columnFamilyHandleList,
                                                          ReadOptions readOptions)
                                                   throws RocksDBException
        Returns iterators from a consistent database state across multiple column families. Iterators are heap allocated and need to be deleted before the db is deleted
        Parameters:
        columnFamilyHandleList - List containing ColumnFamilyHandle instances.
        readOptions - ReadOptions instance.
        Returns:
        List containing RocksIterator instances
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • getSnapshot

        public Snapshot getSnapshot()

        Return a handle to the current DB state. Iterators created with this handle will all observe a stable snapshot of the current DB state. The caller must call ReleaseSnapshot(result) when the snapshot is no longer needed.

        nullptr will be returned if the DB fails to take a snapshot or does not support snapshot.

        Returns:
        Snapshot Snapshot instance
      • releaseSnapshot

        public void releaseSnapshot​(Snapshot snapshot)
        Release a previously acquired snapshot. The caller must not use "snapshot" after this call.
        Parameters:
        snapshot - Snapshot instance
      • getProperty

        public java.lang.String getProperty​(ColumnFamilyHandle columnFamilyHandle,
                                            java.lang.String property)
                                     throws RocksDBException
        DB implements can export properties about their state via this method on a per column family level.

        If property is a valid property understood by this DB implementation, fills value with its current value and returns true. Otherwise returns false.

        Valid property names include:

        • "rocksdb.num-files-at-level<N>" - return the number of files at level <N>, where <N> is an ASCII representation of a level number (e.g. "0").
        • "rocksdb.stats" - returns a multi-line string that describes statistics about the internal operation of the DB.
        • "rocksdb.sstables" - returns a multi-line string that describes all of the sstables that make up the db contents.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance, or null for the default column family.
        property - to be fetched. See above for examples
        Returns:
        property value
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • getProperty

        public java.lang.String getProperty​(java.lang.String property)
                                     throws RocksDBException
        DB implementations can export properties about their state via this method. If "property" is a valid property understood by this DB implementation, fills "*value" with its current value and returns true. Otherwise returns false.

        Valid property names include:

        • "rocksdb.num-files-at-level<N>" - return the number of files at level <N>, where <N> is an ASCII representation of a level number (e.g. "0").
        • "rocksdb.stats" - returns a multi-line string that describes statistics about the internal operation of the DB.
        • "rocksdb.sstables" - returns a multi-line string that describes all of the sstables that make up the db contents.
        Parameters:
        property - to be fetched. See above for examples
        Returns:
        property value
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • getMapProperty

        public java.util.Map<java.lang.String,​java.lang.String> getMapProperty​(java.lang.String property)
                                                                              throws RocksDBException
        Gets a property map.
        Parameters:
        property - to be fetched.
        Returns:
        the property map
        Throws:
        RocksDBException - if an error happens in the underlying native code.
      • getMapProperty

        public java.util.Map<java.lang.String,​java.lang.String> getMapProperty​(ColumnFamilyHandle columnFamilyHandle,
                                                                                     java.lang.String property)
                                                                              throws RocksDBException
        Gets a property map.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance, or null for the default column family.
        property - to be fetched.
        Returns:
        the property map
        Throws:
        RocksDBException - if an error happens in the underlying native code.
      • getLongProperty

        public long getLongProperty​(java.lang.String property)
                             throws RocksDBException

        Similar to GetProperty(), but only works for a subset of properties whose return value is a numerical value. Return the value as long.

        Note: As the returned property is of type uint64_t on C++ side the returning value can be negative because Java supports in Java 7 only signed long values.

        Java 7: To mitigate the problem of the non existent unsigned long tpye, values should be encapsulated using BigInteger to reflect the correct value. The correct behavior is guaranteed if 2^64 is added to negative values.

        Java 8: In Java 8 the value should be treated as unsigned long using provided methods of type Long.

        Parameters:
        property - to be fetched.
        Returns:
        numerical property value.
        Throws:
        RocksDBException - if an error happens in the underlying native code.
      • getLongProperty

        public long getLongProperty​(ColumnFamilyHandle columnFamilyHandle,
                                    java.lang.String property)
                             throws RocksDBException

        Similar to GetProperty(), but only works for a subset of properties whose return value is a numerical value. Return the value as long.

        Note: As the returned property is of type uint64_t on C++ side the returning value can be negative because Java supports in Java 7 only signed long values.

        Java 7: To mitigate the problem of the non existent unsigned long tpye, values should be encapsulated using BigInteger to reflect the correct value. The correct behavior is guaranteed if 2^64 is added to negative values.

        Java 8: In Java 8 the value should be treated as unsigned long using provided methods of type Long.

        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance, or null for the default column family
        property - to be fetched.
        Returns:
        numerical property value
        Throws:
        RocksDBException - if an error happens in the underlying native code.
      • getAggregatedLongProperty

        public long getAggregatedLongProperty​(java.lang.String property)
                                       throws RocksDBException

        Return sum of the getLongProperty of all the column families

        Note: As the returned property is of type uint64_t on C++ side the returning value can be negative because Java supports in Java 7 only signed long values.

        Java 7: To mitigate the problem of the non existent unsigned long tpye, values should be encapsulated using BigInteger to reflect the correct value. The correct behavior is guaranteed if 2^64 is added to negative values.

        Java 8: In Java 8 the value should be treated as unsigned long using provided methods of type Long.

        Parameters:
        property - to be fetched.
        Returns:
        numerical property value
        Throws:
        RocksDBException - if an error happens in the underlying native code.
      • getApproximateSizes

        public long[] getApproximateSizes​(ColumnFamilyHandle columnFamilyHandle,
                                          java.util.List<Range> ranges,
                                          SizeApproximationFlag... sizeApproximationFlags)
        Get the approximate file system space used by keys in each range. Note that the returned sizes measure file system space usage, so if the user data compresses by a factor of ten, the returned sizes will be one-tenth the size of the corresponding user data size. If sizeApproximationFlags defines whether the returned size should include the recently written data in the mem-tables (if the mem-table type supports it), data serialized to disk, or both.
        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance, or null for the default column family
        ranges - the ranges over which to approximate sizes
        sizeApproximationFlags - flags to determine what to include in the approximation.
        Returns:
        the sizes
      • getApproximateSizes

        public long[] getApproximateSizes​(java.util.List<Range> ranges,
                                          SizeApproximationFlag... sizeApproximationFlags)
        Get the approximate file system space used by keys in each range for the default column family. Note that the returned sizes measure file system space usage, so if the user data compresses by a factor of ten, the returned sizes will be one-tenth the size of the corresponding user data size. If sizeApproximationFlags defines whether the returned size should include the recently written data in the mem-tables (if the mem-table type supports it), data serialized to disk, or both.
        Parameters:
        ranges - the ranges over which to approximate sizes
        sizeApproximationFlags - flags to determine what to include in the approximation.
        Returns:
        the sizes.
      • compactRange

        @Deprecated
        public void compactRange​(byte[] begin,
                                 byte[] end,
                                 boolean changeLevel,
                                 int targetLevel,
                                 int targetPathId)
                          throws RocksDBException

        Range compaction of database.

        Note: After the database has been compacted, all data will have been pushed down to the last level containing any data.

        Compaction outputs should be placed in options.db_paths [target_path_id]. Behavior is undefined if target_path_id is out of range.

        See also

        Parameters:
        begin - start of key range (included in range)
        end - end of key range (excluded from range)
        changeLevel - reduce level after compaction
        targetLevel - target level to compact to
        targetPathId - the target path id of output path
        Throws:
        RocksDBException - thrown if an error occurs within the native part of the library.
      • compactRange

        public void compactRange​(ColumnFamilyHandle columnFamilyHandle,
                                 byte[] begin,
                                 byte[] end,
                                 CompactRangeOptions compactRangeOptions)
                          throws RocksDBException

        Range compaction of column family.

        Note: After the database has been compacted, all data will have been pushed down to the last level containing any data.

        Parameters:
        columnFamilyHandle - ColumnFamilyHandle instance.
        begin - start of key range (included in range)
        end - end of key range (excluded from range)
        compactRangeOptions - options for the compaction
        Throws:
        RocksDBException - thrown if an error occurs within the native part of the library.
      • setOptions

        public void setOptions​(MutableColumnFamilyOptions mutableColumnFamilyOptions)
                        throws RocksDBException
        Change the options for the default column family handle.
        Parameters:
        mutableColumnFamilyOptions - the options.
        Throws:
        RocksDBException - if an error occurs whilst setting the options
      • setDBOptions

        public void setDBOptions​(MutableDBOptions mutableDBoptions)
                          throws RocksDBException
        Set the options for the column family handle.
        Parameters:
        mutableDBoptions - the options.
        Throws:
        RocksDBException - if an error occurs whilst setting the options
      • compactFiles

        public java.util.List<java.lang.String> compactFiles​(CompactionOptions compactionOptions,
                                                             java.util.List<java.lang.String> inputFileNames,
                                                             int outputLevel,
                                                             int outputPathId,
                                                             CompactionJobInfo compactionJobInfo)
                                                      throws RocksDBException
        Takes a list of files specified by file names and compacts them to the specified level. Note that the behavior is different from compactRange(ColumnFamilyHandle, byte[], byte[]) in that CompactFiles() performs the compaction job using the CURRENT thread.
        Parameters:
        compactionOptions - compaction options
        inputFileNames - the name of the files to compact
        outputLevel - the level to which they should be compacted
        outputPathId - the id of the output path, or -1
        compactionJobInfo - the compaction job info, this parameter will be updated with the info from compacting the files, can just be null if you don't need it.
        Returns:
        the list of compacted files
        Throws:
        RocksDBException - if an error occurs during compaction
      • compactFiles

        public java.util.List<java.lang.String> compactFiles​(CompactionOptions compactionOptions,
                                                             ColumnFamilyHandle columnFamilyHandle,
                                                             java.util.List<java.lang.String> inputFileNames,
                                                             int outputLevel,
                                                             int outputPathId,
                                                             CompactionJobInfo compactionJobInfo)
                                                      throws RocksDBException
        Takes a list of files specified by file names and compacts them to the specified level. Note that the behavior is different from compactRange(ColumnFamilyHandle, byte[], byte[]) in that CompactFiles() performs the compaction job using the CURRENT thread.
        Parameters:
        compactionOptions - compaction options
        columnFamilyHandle - columnFamilyHandle, or null for the default column family
        inputFileNames - the name of the files to compact
        outputLevel - the level to which they should be compacted
        outputPathId - the id of the output path, or -1
        compactionJobInfo - the compaction job info, this parameter will be updated with the info from compacting the files, can just be null if you don't need it.
        Returns:
        the list of compacted files
        Throws:
        RocksDBException - if an error occurs during compaction
      • cancelAllBackgroundWork

        public void cancelAllBackgroundWork​(boolean wait)
        This function will cancel all currently running background processes.
        Parameters:
        wait - if true, wait for all background work to be cancelled before returning.
      • pauseBackgroundWork

        public void pauseBackgroundWork()
                                 throws RocksDBException
        This function will wait until all currently running background processes finish. After it returns, no background process will be run until continueBackgroundWork() is called
        Throws:
        RocksDBException - if an error occurs when pausing background work
      • enableAutoCompaction

        public void enableAutoCompaction​(java.util.List<ColumnFamilyHandle> columnFamilyHandles)
                                  throws RocksDBException
        Enable automatic compactions for the given column families if they were previously disabled. The function will first set the ColumnFamilyOptions.disableAutoCompactions() option for each column family to false, after which it will schedule a flush/compaction. NOTE: Setting disableAutoCompactions to 'false' through setOptions(ColumnFamilyHandle, MutableColumnFamilyOptions) does NOT schedule a flush/compaction afterwards, and only changes the parameter itself within the column family option.
        Parameters:
        columnFamilyHandles - the column family handles
        Throws:
        RocksDBException - if an error occurs whilst enabling auto-compaction
      • numberLevels

        public int numberLevels()
        Number of levels used for this DB.
        Returns:
        the number of levels
      • numberLevels

        public int numberLevels​(ColumnFamilyHandle columnFamilyHandle)
        Number of levels used for a column family in this DB.
        Parameters:
        columnFamilyHandle - the column family handle, or null for the default column family
        Returns:
        the number of levels
      • maxMemCompactionLevel

        public int maxMemCompactionLevel()
        Maximum level to which a new compacted memtable is pushed if it does not create overlap.
        Returns:
        the maximum level
      • maxMemCompactionLevel

        public int maxMemCompactionLevel​(ColumnFamilyHandle columnFamilyHandle)
        Maximum level to which a new compacted memtable is pushed if it does not create overlap.
        Parameters:
        columnFamilyHandle - the column family handle
        Returns:
        the maximum level
      • level0StopWriteTrigger

        public int level0StopWriteTrigger()
        Number of files in level-0 that would stop writes.
        Returns:
        the number of files
      • level0StopWriteTrigger

        public int level0StopWriteTrigger​(ColumnFamilyHandle columnFamilyHandle)
        Number of files in level-0 that would stop writes.
        Parameters:
        columnFamilyHandle - the column family handle
        Returns:
        the number of files
      • getName

        public java.lang.String getName()
        Get DB name -- the exact same name that was provided as an argument to as path to open(Options, String).
        Returns:
        the DB name
      • getEnv

        public Env getEnv()
        Get the Env object from the DB
        Returns:
        the env
      • flush

        public void flush​(FlushOptions flushOptions)
                   throws RocksDBException

        Flush all memory table data.

        Note: it must be ensured that the FlushOptions instance is not GC'ed before this method finishes. If the wait parameter is set to false, flush processing is asynchronous.

        Parameters:
        flushOptions - FlushOptions instance.
        Throws:
        RocksDBException - thrown if an error occurs within the native part of the library.
      • flush

        public void flush​(FlushOptions flushOptions,
                          ColumnFamilyHandle columnFamilyHandle)
                   throws RocksDBException

        Flush all memory table data.

        Note: it must be ensured that the FlushOptions instance is not GC'ed before this method finishes. If the wait parameter is set to false, flush processing is asynchronous.

        Parameters:
        flushOptions - FlushOptions instance.
        columnFamilyHandle - ColumnFamilyHandle instance.
        Throws:
        RocksDBException - thrown if an error occurs within the native part of the library.
      • flush

        public void flush​(FlushOptions flushOptions,
                          java.util.List<ColumnFamilyHandle> columnFamilyHandles)
                   throws RocksDBException
        Flushes multiple column families. If atomic flush is not enabled, this is equivalent to calling flush(FlushOptions, ColumnFamilyHandle) multiple times. If atomic flush is enabled, this will flush all column families specified up to the latest sequence number at the time when flush is requested.
        Parameters:
        flushOptions - FlushOptions instance.
        columnFamilyHandles - column family handles.
        Throws:
        RocksDBException - thrown if an error occurs within the native part of the library.
      • flushWal

        public void flushWal​(boolean sync)
                      throws RocksDBException
        Flush the WAL memory buffer to the file. If sync is true, it calls syncWal() afterwards.
        Parameters:
        sync - true to also fsync to disk.
        Throws:
        RocksDBException - if an error occurs whilst flushing
      • getLatestSequenceNumber

        public long getLatestSequenceNumber()

        The sequence number of the most recent transaction.

        Returns:
        sequence number of the most recent transaction.
      • setPreserveDeletesSequenceNumber

        public boolean setPreserveDeletesSequenceNumber​(long sequenceNumber)
        Instructs DB to preserve deletes with sequence numbers >= sequenceNumber. Has no effect if DBOptions#preserveDeletes() is set to false. This function assumes that user calls this function with monotonically increasing seqnums (otherwise we can't guarantee that a particular delete hasn't been already processed).
        Parameters:
        sequenceNumber - the minimum sequence number to preserve
        Returns:
        true if the value was successfully updated, false if user attempted to call if with sequenceNumber <= current value.
      • disableFileDeletions

        public void disableFileDeletions()
                                  throws RocksDBException

        Prevent file deletions. Compactions will continue to occur, but no obsolete files will be deleted. Calling this multiple times have the same effect as calling it once.

        Throws:
        RocksDBException - thrown if operation was not performed successfully.
      • enableFileDeletions

        public void enableFileDeletions​(boolean force)
                                 throws RocksDBException

        Allow compactions to delete obsolete files. If force == true, the call to EnableFileDeletions() will guarantee that file deletions are enabled after the call, even if DisableFileDeletions() was called multiple times before.

        If force == false, EnableFileDeletions will only enable file deletion after it's been called at least as many times as DisableFileDeletions(), enabling the two methods to be called by two threads concurrently without synchronization -- i.e., file deletions will be enabled only after both threads call EnableFileDeletions()

        Parameters:
        force - boolean value described above.
        Throws:
        RocksDBException - thrown if operation was not performed successfully.
      • getLiveFiles

        public RocksDB.LiveFiles getLiveFiles​(boolean flushMemtable)
                                       throws RocksDBException
        Retrieve the list of all files in the database. In case you have multiple column families, even if flushMemtable is true, you still need to call getSortedWalFiles() after getLiveFiles(boolean) to compensate for new data that arrived to already-flushed column families while other column families were flushing. NOTE: Calling getLiveFiles(boolean) followed by getSortedWalFiles() can generate a lossless backup.
        Parameters:
        flushMemtable - set to true to flush before recoding the live files. Setting to false is useful when we don't want to wait for flush which may have to wait for compaction to complete taking an indeterminate time.
        Returns:
        the live files
        Throws:
        RocksDBException - if an error occurs whilst retrieving the list of live files
      • getSortedWalFiles

        public java.util.List<LogFile> getSortedWalFiles()
                                                  throws RocksDBException
        Retrieve the sorted list of all wal files with earliest file first.
        Returns:
        the log files
        Throws:
        RocksDBException - if an error occurs whilst retrieving the list of sorted WAL files
      • getUpdatesSince

        public TransactionLogIterator getUpdatesSince​(long sequenceNumber)
                                               throws RocksDBException

        Returns an iterator that is positioned at a write-batch containing seq_number. If the sequence number is non existent, it returns an iterator at the first available seq_no after the requested seq_no.

        Must set WAL_ttl_seconds or WAL_size_limit_MB to large values to use this api, else the WAL files will get cleared aggressively and the iterator might keep getting invalid before an update is read.

        Parameters:
        sequenceNumber - sequence number offset
        Returns:
        TransactionLogIterator instance.
        Throws:
        RocksDBException - if iterator cannot be retrieved from native-side.
      • deleteFile

        public void deleteFile​(java.lang.String name)
                        throws RocksDBException
        Delete the file name from the db directory and update the internal state to reflect that. Supports deletion of sst and log files only. 'name' must be path relative to the db directory. eg. 000001.sst, /archive/000003.log
        Parameters:
        name - the file name
        Throws:
        RocksDBException - if an error occurs whilst deleting the file
      • getLiveFilesMetaData

        public java.util.List<LiveFileMetaData> getLiveFilesMetaData()
        Gets a list of all table files metadata.
        Returns:
        table files metadata.
      • getColumnFamilyMetaData

        public ColumnFamilyMetaData getColumnFamilyMetaData​(ColumnFamilyHandle columnFamilyHandle)
        Obtains the meta data of the specified column family of the DB.
        Parameters:
        columnFamilyHandle - the column family
        Returns:
        the column family metadata
      • getColumnFamilyMetaData

        public ColumnFamilyMetaData getColumnFamilyMetaData()
        Obtains the meta data of the default column family of the DB.
        Returns:
        the column family metadata
      • ingestExternalFile

        public void ingestExternalFile​(java.util.List<java.lang.String> filePathList,
                                       IngestExternalFileOptions ingestExternalFileOptions)
                                throws RocksDBException
        ingestExternalFile will load a list of external SST files (1) into the DB We will try to find the lowest possible level that the file can fit in, and ingest the file into this level (2). A file that have a key range that overlap with the memtable key range will require us to Flush the memtable first before ingesting the file. (1) External SST files can be created using SstFileWriter (2) We will try to ingest the files to the lowest possible level even if the file compression doesn't match the level compression
        Parameters:
        filePathList - The list of files to ingest
        ingestExternalFileOptions - the options for the ingestion
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • ingestExternalFile

        public void ingestExternalFile​(ColumnFamilyHandle columnFamilyHandle,
                                       java.util.List<java.lang.String> filePathList,
                                       IngestExternalFileOptions ingestExternalFileOptions)
                                throws RocksDBException
        ingestExternalFile will load a list of external SST files (1) into the DB We will try to find the lowest possible level that the file can fit in, and ingest the file into this level (2). A file that have a key range that overlap with the memtable key range will require us to Flush the memtable first before ingesting the file. (1) External SST files can be created using SstFileWriter (2) We will try to ingest the files to the lowest possible level even if the file compression doesn't match the level compression
        Parameters:
        columnFamilyHandle - The column family for the ingested files
        filePathList - The list of files to ingest
        ingestExternalFileOptions - the options for the ingestion
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • getDefaultColumnFamily

        public ColumnFamilyHandle getDefaultColumnFamily()
        Gets the handle for the default column family
        Returns:
        The handle of the default column family
      • getPropertiesOfAllTables

        public java.util.Map<java.lang.String,​TableProperties> getPropertiesOfAllTables​(ColumnFamilyHandle columnFamilyHandle)
                                                                                       throws RocksDBException
        Get the properties of all tables.
        Parameters:
        columnFamilyHandle - the column family handle, or null for the default column family.
        Returns:
        the properties
        Throws:
        RocksDBException - if an error occurs whilst getting the properties
      • getPropertiesOfAllTables

        public java.util.Map<java.lang.String,​TableProperties> getPropertiesOfAllTables()
                                                                                       throws RocksDBException
        Get the properties of all tables in the default column family.
        Returns:
        the properties
        Throws:
        RocksDBException - if an error occurs whilst getting the properties
      • getPropertiesOfTablesInRange

        public java.util.Map<java.lang.String,​TableProperties> getPropertiesOfTablesInRange​(ColumnFamilyHandle columnFamilyHandle,
                                                                                                  java.util.List<Range> ranges)
                                                                                           throws RocksDBException
        Get the properties of tables in range.
        Parameters:
        columnFamilyHandle - the column family handle, or null for the default column family.
        ranges - the ranges over which to get the table properties
        Returns:
        the properties
        Throws:
        RocksDBException - if an error occurs whilst getting the properties
      • getPropertiesOfTablesInRange

        public java.util.Map<java.lang.String,​TableProperties> getPropertiesOfTablesInRange​(java.util.List<Range> ranges)
                                                                                           throws RocksDBException
        Get the properties of tables in range for the default column family.
        Parameters:
        ranges - the ranges over which to get the table properties
        Returns:
        the properties
        Throws:
        RocksDBException - if an error occurs whilst getting the properties
      • suggestCompactRange

        public Range suggestCompactRange​(ColumnFamilyHandle columnFamilyHandle)
                                  throws RocksDBException
        Suggest the range to compact.
        Parameters:
        columnFamilyHandle - the column family handle, or null for the default column family.
        Returns:
        the suggested range.
        Throws:
        RocksDBException - if an error occurs whilst suggesting the range
      • suggestCompactRange

        public Range suggestCompactRange()
                                  throws RocksDBException
        Suggest the range to compact for the default column family.
        Returns:
        the suggested range.
        Throws:
        RocksDBException - if an error occurs whilst suggesting the range
      • promoteL0

        public void promoteL0​(ColumnFamilyHandle columnFamilyHandle,
                              int targetLevel)
                       throws RocksDBException
        Promote L0.
        Parameters:
        columnFamilyHandle - the column family handle, or null for the default column family.
        targetLevel - the target level for L0
        Throws:
        RocksDBException - if an error occurs whilst promoting L0
      • promoteL0

        public void promoteL0​(int targetLevel)
                       throws RocksDBException
        Promote L0 for the default column family.
        Parameters:
        targetLevel - the target level for L0
        Throws:
        RocksDBException - if an error occurs whilst promoting L0
      • tryCatchUpWithPrimary

        public void tryCatchUpWithPrimary()
                                   throws RocksDBException
        Make the secondary instance catch up with the primary by tailing and replaying the MANIFEST and WAL of the primary. Column families created by the primary after the secondary instance starts will be ignored unless the secondary instance closes and restarts with the newly created column families. Column families that exist before secondary instance starts and dropped by the primary afterwards will be marked as dropped. However, as long as the secondary instance does not delete the corresponding column family handles, the data of the column family is still accessible to the secondary.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • deleteFilesInRanges

        public void deleteFilesInRanges​(ColumnFamilyHandle columnFamily,
                                        java.util.List<byte[]> ranges,
                                        boolean includeEnd)
                                 throws RocksDBException
        Delete files in multiple ranges at once. Delete files in a lot of ranges one at a time can be slow, use this API for better performance in that case.
        Parameters:
        columnFamily - - The column family for operation (null for default)
        includeEnd - - Whether ranges should include end
        ranges - - pairs of ranges (from1, to1, from2, to2, ...)
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • destroyDB

        public static void destroyDB​(java.lang.String path,
                                     Options options)
                              throws RocksDBException
        Static method to destroy the contents of the specified database. Be very careful using this method.
        Parameters:
        path - the path to the Rocksdb database.
        options - Options instance.
        Throws:
        RocksDBException - thrown if error happens in underlying native library.
      • storeOptionsInstance

        protected void storeOptionsInstance​(DBOptionsInterface options)