Class RocksDB
- java.lang.Object
-
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRocksDB.CountAndSizestatic classRocksDB.LiveFilesstatic classRocksDB.Version
-
Field Summary
Fields Modifier and Type Field Description static byte[]DEFAULT_COLUMN_FAMILYstatic intNOT_FOUNDprotected DBOptionsInterfaceoptions_-
Fields inherited from class org.rocksdb.RocksObject
nativeHandle_
-
Fields inherited from class org.rocksdb.AbstractImmutableNativeReference
owningHandle_
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedRocksDB(long nativeHandle)Private constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcancelAllBackgroundWork(boolean wait)This function will cancel all currently running background processes.voidclose()This is similar tocloseE()except that it silently ignores any errors.voidcloseE()This is similar toclose()except that it throws an exception if any error occurs.java.util.List<java.lang.String>compactFiles(CompactionOptions compactionOptions, java.util.List<java.lang.String> inputFileNames, int outputLevel, int outputPathId, CompactionJobInfo compactionJobInfo)Takes a list of files specified by file names and compacts them to the specified level.java.util.List<java.lang.String>compactFiles(CompactionOptions compactionOptions, ColumnFamilyHandle columnFamilyHandle, java.util.List<java.lang.String> inputFileNames, int outputLevel, int outputPathId, CompactionJobInfo compactionJobInfo)Takes a list of files specified by file names and compacts them to the specified level.voidcompactRange()Range compaction of database.voidcompactRange(boolean changeLevel, int targetLevel, int targetPathId)Deprecated.voidcompactRange(byte[] begin, byte[] end)Range compaction of database.voidcompactRange(byte[] begin, byte[] end, boolean changeLevel, int targetLevel, int targetPathId)Deprecated.voidcompactRange(ColumnFamilyHandle columnFamilyHandle)Range compaction of column family.voidcompactRange(ColumnFamilyHandle columnFamilyHandle, boolean changeLevel, int targetLevel, int targetPathId)Deprecated.voidcompactRange(ColumnFamilyHandle columnFamilyHandle, byte[] begin, byte[] end)Range compaction of column family.voidcompactRange(ColumnFamilyHandle columnFamilyHandle, byte[] begin, byte[] end, boolean changeLevel, int targetLevel, int targetPathId)Deprecated.voidcompactRange(ColumnFamilyHandle columnFamilyHandle, byte[] begin, byte[] end, CompactRangeOptions compactRangeOptions)Range compaction of column family.voidcontinueBackgroundWork()Resumes background work which was suspended by previously callingpauseBackgroundWork()java.util.List<ColumnFamilyHandle>createColumnFamilies(java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors)Bulk create column families with the same column family options.java.util.List<ColumnFamilyHandle>createColumnFamilies(ColumnFamilyOptions columnFamilyOptions, java.util.List<byte[]> columnFamilyNames)Bulk create column families with the same column family options.ColumnFamilyHandlecreateColumnFamily(ColumnFamilyDescriptor columnFamilyDescriptor)Creates a new column family with the name columnFamilyName and allocates a ColumnFamilyHandle within an internal structure.voiddelete(byte[] key)Delete the database entry (if any) for "key".voiddelete(byte[] key, int offset, int len)Delete the database entry (if any) for "key".voiddelete(ColumnFamilyHandle columnFamilyHandle, byte[] key)Delete the database entry (if any) for "key".voiddelete(ColumnFamilyHandle columnFamilyHandle, byte[] key, int offset, int len)Delete the database entry (if any) for "key".voiddelete(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpt, byte[] key)Delete the database entry (if any) for "key".voiddelete(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpt, byte[] key, int offset, int len)Delete the database entry (if any) for "key".voiddelete(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpt, java.nio.ByteBuffer key)Delete the database entry (if any) for "key".voiddelete(WriteOptions writeOpt, byte[] key)Delete the database entry (if any) for "key".voiddelete(WriteOptions writeOpt, byte[] key, int offset, int len)Delete the database entry (if any) for "key".voiddelete(WriteOptions writeOpt, java.nio.ByteBuffer key)Delete the database entry (if any) for "key".voiddeleteFile(java.lang.String name)Delete the file name from the db directory and update the internal state to reflect that.voiddeleteFilesInRanges(ColumnFamilyHandle columnFamily, java.util.List<byte[]> ranges, boolean includeEnd)Delete files in multiple ranges at once.voiddeleteRange(byte[] beginKey, byte[] endKey)Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey".voiddeleteRange(ColumnFamilyHandle columnFamilyHandle, byte[] beginKey, byte[] endKey)Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey".voiddeleteRange(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpt, byte[] beginKey, byte[] endKey)Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey".voiddeleteRange(WriteOptions writeOpt, byte[] beginKey, byte[] endKey)Removes the database entries in the range ["beginKey", "endKey"), i.e., including "beginKey" and excluding "endKey".voiddestroyColumnFamilyHandle(ColumnFamilyHandle columnFamilyHandle)Deletes native column family handle of givenColumnFamilyHandleJava object and removes reference fromownedColumnFamilyHandles.static voiddestroyDB(java.lang.String path, Options options)Static method to destroy the contents of the specified database.voiddisableFileDeletions()Prevent file deletions.protected voiddisposeInternal(long handle)voiddropColumnFamilies(java.util.List<ColumnFamilyHandle> columnFamilies)voiddropColumnFamily(ColumnFamilyHandle columnFamilyHandle)Drops the column family specified bycolumnFamilyHandle.voidenableAutoCompaction(java.util.List<ColumnFamilyHandle> columnFamilyHandles)Enable automatic compactions for the given column families if they were previously disabled.voidenableFileDeletions(boolean force)Allow compactions to delete obsolete files.voidendTrace()Stop tracing DB operations.voidflush(FlushOptions flushOptions)Flush all memory table data.voidflush(FlushOptions flushOptions, java.util.List<ColumnFamilyHandle> columnFamilyHandles)Flushes multiple column families.voidflush(FlushOptions flushOptions, ColumnFamilyHandle columnFamilyHandle)Flush all memory table data.voidflushWal(boolean sync)Flush the WAL memory buffer to the file.byte[]get(byte[] key)The simplified version of get which returns a new byte array storing the value associated with the specified input key if any.intget(byte[] key, byte[] value)Get the value associated with the specified key within column family*byte[]get(byte[] key, int offset, int len)The simplified version of get which returns a new byte array storing the value associated with the specified input key if any.intget(byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Get the value associated with the specified key within column family*byte[]get(ColumnFamilyHandle columnFamilyHandle, byte[] key)The simplified version of get which returns a new byte array storing the value associated with the specified input key if any.intget(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)Get the value associated with the specified key within column family.byte[]get(ColumnFamilyHandle columnFamilyHandle, byte[] key, int offset, int len)The simplified version of get which returns a new byte array storing the value associated with the specified input key if any.intget(ColumnFamilyHandle columnFamilyHandle, byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Get the value associated with the specified key within column family.byte[]get(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt, byte[] key)The simplified version of get which returns a new byte array storing the value associated with the specified input key if any.intget(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt, byte[] key, byte[] value)Get the value associated with the specified key within column family.byte[]get(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt, byte[] key, int offset, int len)The simplified version of get which returns a new byte array storing the value associated with the specified input key if any.intget(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt, byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Get the value associated with the specified key within column family.intget(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt, java.nio.ByteBuffer key, java.nio.ByteBuffer value)Get the value associated with the specified key within column family.byte[]get(ReadOptions opt, byte[] key)The simplified version of get which returns a new byte array storing the value associated with the specified input key if any.intget(ReadOptions opt, byte[] key, byte[] value)Get the value associated with the specified key.byte[]get(ReadOptions opt, byte[] key, int offset, int len)The simplified version of get which returns a new byte array storing the value associated with the specified input key if any.intget(ReadOptions opt, byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Get the value associated with the specified key.intget(ReadOptions opt, java.nio.ByteBuffer key, java.nio.ByteBuffer value)Get the value associated with the specified key within column family.longgetAggregatedLongProperty(java.lang.String property)Return sum of the getLongProperty of all the column familiesRocksDB.CountAndSizegetApproximateMemTableStats(ColumnFamilyHandle columnFamilyHandle, Range range)This method is similar togetApproximateSizes(ColumnFamilyHandle, List, SizeApproximationFlag...), except that it returns approximate number of records and size in memtables.RocksDB.CountAndSizegetApproximateMemTableStats(Range range)This method is similar togetApproximateSizes(ColumnFamilyHandle, List, SizeApproximationFlag...), except that it returns approximate number of records and size in memtables.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.long[]getApproximateSizes(ColumnFamilyHandle columnFamilyHandle, java.util.List<Range> ranges, SizeApproximationFlag... sizeApproximationFlags)Get the approximate file system space used by keys in each range.ColumnFamilyMetaDatagetColumnFamilyMetaData()Obtains the meta data of the default column family of the DB.ColumnFamilyMetaDatagetColumnFamilyMetaData(ColumnFamilyHandle columnFamilyHandle)Obtains the meta data of the specified column family of the DB.ColumnFamilyHandlegetDefaultColumnFamily()Gets the handle for the default column familyEnvgetEnv()Get the Env object from the DBlonggetLatestSequenceNumber()The sequence number of the most recent transaction.RocksDB.LiveFilesgetLiveFiles()Retrieve the list of all files in the database after flushing the memtable.RocksDB.LiveFilesgetLiveFiles(boolean flushMemtable)Retrieve the list of all files in the database.java.util.List<LiveFileMetaData>getLiveFilesMetaData()Gets a list of all table files metadata.longgetLongProperty(java.lang.String property)Similar to GetProperty(), but only works for a subset of properties whose return value is a numerical value.longgetLongProperty(ColumnFamilyHandle columnFamilyHandle, java.lang.String property)Similar to GetProperty(), but only works for a subset of properties whose return value is a numerical value.java.util.Map<java.lang.String,java.lang.String>getMapProperty(java.lang.String property)Gets a property map.java.util.Map<java.lang.String,java.lang.String>getMapProperty(ColumnFamilyHandle columnFamilyHandle, java.lang.String property)Gets a property map.java.lang.StringgetName()Get DB name -- the exact same name that was provided as an argument to as path toopen(Options, String).java.util.Map<java.lang.String,TableProperties>getPropertiesOfAllTables()Get the properties of all tables in the default column family.java.util.Map<java.lang.String,TableProperties>getPropertiesOfAllTables(ColumnFamilyHandle columnFamilyHandle)Get the properties of all tables.java.util.Map<java.lang.String,TableProperties>getPropertiesOfTablesInRange(java.util.List<Range> ranges)Get the properties of tables in range for the default column family.java.util.Map<java.lang.String,TableProperties>getPropertiesOfTablesInRange(ColumnFamilyHandle columnFamilyHandle, java.util.List<Range> ranges)Get the properties of tables in range.java.lang.StringgetProperty(java.lang.String property)DB implementations can export properties about their state via this method.java.lang.StringgetProperty(ColumnFamilyHandle columnFamilyHandle, java.lang.String property)DB implements can export properties about their state via this method on a per column family level.SnapshotgetSnapshot()Return a handle to the current DB state.java.util.List<LogFile>getSortedWalFiles()Retrieve the sorted list of all wal files with earliest file first.TransactionLogIteratorgetUpdatesSince(long sequenceNumber)Returns an iterator that is positioned at a write-batch containing seq_number.voidingestExternalFile(java.util.List<java.lang.String> filePathList, IngestExternalFileOptions ingestExternalFileOptions)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).voidingestExternalFile(ColumnFamilyHandle columnFamilyHandle, java.util.List<java.lang.String> filePathList, IngestExternalFileOptions ingestExternalFileOptions)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).booleankeyMayExist(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.booleankeyMayExist(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.booleankeyMayExist(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.booleankeyMayExist(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.booleankeyMayExist(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.booleankeyMayExist(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.booleankeyMayExist(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.booleankeyMayExist(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.intlevel0StopWriteTrigger()Number of files in level-0 that would stop writes.intlevel0StopWriteTrigger(ColumnFamilyHandle columnFamilyHandle)Number of files in level-0 that would stop writes.static java.util.List<byte[]>listColumnFamilies(Options options, java.lang.String path)Static method to determine all available column families for a rocksdb database identified by pathstatic voidloadLibrary()Loads the necessary library files.static voidloadLibrary(java.util.List<java.lang.String> paths)Tries to load the necessary library files from the given list of directories.intmaxMemCompactionLevel()Maximum level to which a new compacted memtable is pushed if it does not create overlap.intmaxMemCompactionLevel(ColumnFamilyHandle columnFamilyHandle)Maximum level to which a new compacted memtable is pushed if it does not create overlap.voidmerge(byte[] key, byte[] value)Add merge operand for key/value pair.voidmerge(byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Add merge operand for key/value pair.voidmerge(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)Add merge operand for key/value pair in a ColumnFamily.voidmerge(ColumnFamilyHandle columnFamilyHandle, byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Add merge operand for key/value pair in a ColumnFamily.voidmerge(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpts, byte[] key, byte[] value)Add merge operand for key/value pair.voidmerge(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpts, byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Add merge operand for key/value pair.voidmerge(WriteOptions writeOpts, byte[] key, byte[] value)Add merge operand for key/value pair.voidmerge(WriteOptions writeOpts, byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Add merge operand for key/value pair.java.util.Map<byte[],byte[]>multiGet(java.util.List<byte[]> keys)Deprecated.ConsidermultiGetAsList(List)instead.java.util.Map<byte[],byte[]>multiGet(java.util.List<ColumnFamilyHandle> columnFamilyHandleList, java.util.List<byte[]> keys)Deprecated.ConsidermultiGetAsList(List, List)instead.java.util.Map<byte[],byte[]>multiGet(ReadOptions opt, java.util.List<byte[]> keys)Deprecated.ConsidermultiGetAsList(ReadOptions, List)instead.java.util.Map<byte[],byte[]>multiGet(ReadOptions opt, java.util.List<ColumnFamilyHandle> columnFamilyHandleList, java.util.List<byte[]> keys)Deprecated.ConsidermultiGetAsList(ReadOptions, List, List)instead.java.util.List<byte[]>multiGetAsList(java.util.List<byte[]> keys)Takes a list of keys, and returns a list of values for the given list of keys.java.util.List<byte[]>multiGetAsList(java.util.List<ColumnFamilyHandle> columnFamilyHandleList, java.util.List<byte[]> keys)Returns a list of values for the given list of keys.java.util.List<byte[]>multiGetAsList(ReadOptions opt, java.util.List<byte[]> keys)Returns a list of values for the given list of keys.java.util.List<byte[]>multiGetAsList(ReadOptions opt, java.util.List<ColumnFamilyHandle> columnFamilyHandleList, java.util.List<byte[]> keys)Returns a list of values for the given list of keys.RocksIteratornewIterator()Return a heap-allocated iterator over the contents of the database.RocksIteratornewIterator(ColumnFamilyHandle columnFamilyHandle)Return a heap-allocated iterator over the contents of a ColumnFamily.RocksIteratornewIterator(ColumnFamilyHandle columnFamilyHandle, ReadOptions readOptions)Return a heap-allocated iterator over the contents of a ColumnFamily.RocksIteratornewIterator(ReadOptions readOptions)Return a heap-allocated iterator over the contents of the database.java.util.List<RocksIterator>newIterators(java.util.List<ColumnFamilyHandle> columnFamilyHandleList)Returns iterators from a consistent database state across multiple column families.java.util.List<RocksIterator>newIterators(java.util.List<ColumnFamilyHandle> columnFamilyHandleList, ReadOptions readOptions)Returns iterators from a consistent database state across multiple column families.intnumberLevels()Number of levels used for this DB.intnumberLevels(ColumnFamilyHandle columnFamilyHandle)Number of levels used for a column family in this DB.static RocksDBopen(java.lang.String path)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.static RocksDBopen(java.lang.String path, java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors, java.util.List<ColumnFamilyHandle> columnFamilyHandles)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.static RocksDBopen(DBOptions options, java.lang.String path, java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors, java.util.List<ColumnFamilyHandle> columnFamilyHandles)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.static RocksDBopen(Options options, java.lang.String path)The factory constructor of RocksDB that opens a RocksDB instance given the path to the database using the specified options and db path.static RocksDBopenAsSecondary(DBOptions options, java.lang.String path, java.lang.String secondaryPath, java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors, java.util.List<ColumnFamilyHandle> columnFamilyHandles)Open DB as secondary instance with column families.static RocksDBopenAsSecondary(Options options, java.lang.String path, java.lang.String secondaryPath)Open DB as secondary instance with only the default column family.static RocksDBopenReadOnly(java.lang.String path)The factory constructor of RocksDB that opens a RocksDB instance in Read-Only mode given the path to the database using the default options.static RocksDBopenReadOnly(java.lang.String path, java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors, java.util.List<ColumnFamilyHandle> columnFamilyHandles)The factory constructor of RocksDB that opens a RocksDB instance in Read-Only mode given the path to the database using the default options.static RocksDBopenReadOnly(DBOptions options, java.lang.String path, java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors, java.util.List<ColumnFamilyHandle> columnFamilyHandles)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.static RocksDBopenReadOnly(DBOptions options, java.lang.String path, java.util.List<ColumnFamilyDescriptor> columnFamilyDescriptors, java.util.List<ColumnFamilyHandle> columnFamilyHandles, boolean errorIfWalFileExists)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.static RocksDBopenReadOnly(Options options, java.lang.String path)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.static RocksDBopenReadOnly(Options options, java.lang.String path, boolean errorIfWalFileExists)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.voidpauseBackgroundWork()This function will wait until all currently running background processes finish.voidpromoteL0(int targetLevel)Promote L0 for the default column family.voidpromoteL0(ColumnFamilyHandle columnFamilyHandle, int targetLevel)Promote L0.voidput(byte[] key, byte[] value)Set the database entry for "key" to "value".voidput(byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Set the database entry for "key" to "value".voidput(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)Set the database entry for "key" to "value" in the specified column family.voidput(ColumnFamilyHandle columnFamilyHandle, byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Set the database entry for "key" to "value" in the specified column family.voidput(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpts, byte[] key, byte[] value)Set the database entry for "key" to "value" for the specified column family.voidput(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpts, byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Set the database entry for "key" to "value" for the specified column family.voidput(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpts, java.nio.ByteBuffer key, java.nio.ByteBuffer value)Set the database entry for "key" to "value" for the specified column family.voidput(WriteOptions writeOpts, byte[] key, byte[] value)Set the database entry for "key" to "value".voidput(WriteOptions writeOpts, byte[] key, int offset, int len, byte[] value, int vOffset, int vLen)Set the database entry for "key" to "value".voidput(WriteOptions writeOpts, java.nio.ByteBuffer key, java.nio.ByteBuffer value)Set the database entry for "key" to "value".voidreleaseSnapshot(Snapshot snapshot)Release a previously acquired snapshot.voidremove(byte[] key)Deprecated.Usedelete(byte[])voidremove(ColumnFamilyHandle columnFamilyHandle, byte[] key)Deprecated.voidremove(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpt, byte[] key)Deprecated.voidremove(WriteOptions writeOpt, byte[] key)Deprecated.voidresetStats()Reset internal stats for DB and all column families.static RocksDB.VersionrocksdbVersion()voidsetDBOptions(MutableDBOptions mutableDBoptions)Set the options for the column family handle.voidsetOptions(ColumnFamilyHandle columnFamilyHandle, MutableColumnFamilyOptions mutableColumnFamilyOptions)Change the options for the column family handle.voidsetOptions(MutableColumnFamilyOptions mutableColumnFamilyOptions)Change the options for the default column family handle.booleansetPreserveDeletesSequenceNumber(long sequenceNumber)Instructs DB to preserve deletes with sequence numbers >= sequenceNumber.voidsingleDelete(byte[] key)Remove the database entry forkey.voidsingleDelete(ColumnFamilyHandle columnFamilyHandle, byte[] key)Remove the database entry forkey.voidsingleDelete(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpt, byte[] key)Remove the database entry forkey.voidsingleDelete(WriteOptions writeOpt, byte[] key)Remove the database entry forkey.voidstartTrace(TraceOptions traceOptions, AbstractTraceWriter traceWriter)Trace DB operations.protected voidstoreOptionsInstance(DBOptionsInterface options)RangesuggestCompactRange()Suggest the range to compact for the default column family.RangesuggestCompactRange(ColumnFamilyHandle columnFamilyHandle)Suggest the range to compact.voidsyncWal()Sync the WAL.voidtryCatchUpWithPrimary()Make the secondary instance catch up with the primary by tailing and replaying the MANIFEST and WAL of the primary.voidverifyChecksum()Verify checksumvoidwrite(WriteOptions writeOpts, WriteBatch updates)Apply the specified updates to the database.voidwrite(WriteOptions writeOpts, WriteBatchWithIndex updates)Apply the specified updates to the database.-
Methods inherited from class org.rocksdb.RocksObject
disposeInternal, getNativeHandle
-
Methods inherited from class org.rocksdb.AbstractImmutableNativeReference
disOwnNativeHandle, isOwningHandle
-
Methods inherited from class org.rocksdb.AbstractNativeReference
dispose, finalize
-
-
-
-
Field Detail
-
DEFAULT_COLUMN_FAMILY
public static final byte[] DEFAULT_COLUMN_FAMILY
-
NOT_FOUND
public static final int NOT_FOUND
- See Also:
- Constant Field Values
-
options_
protected DBOptionsInterface options_
-
-
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.
-
rocksdbVersion
public static RocksDB.Version rocksdbVersion()
-
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
RocksDBinstance on success, null if the specifiedRocksDBcan 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 descriptorscolumnFamilyHandles- will be filled with ColumnFamilyHandle instances on open.- Returns:
- a
RocksDBinstance on success, null if the specifiedRocksDBcan 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-Optionsinstance.path- the path to the rocksdb.- Returns:
- a
RocksDBinstance on success, null if the specifiedRocksDBcan 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-DBOptionsinstance.path- the path to the rocksdb.columnFamilyDescriptors- list of column family descriptorscolumnFamilyHandles- will be filled with ColumnFamilyHandle instances on open.- Returns:
- a
RocksDBinstance on success, null if the specifiedRocksDBcan 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
RocksDBinstance on success, null if the specifiedRocksDBcan 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-Optionsinstance.path- the path to the RocksDB.- Returns:
- a
RocksDBinstance on success, null if the specifiedRocksDBcan 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-Optionsinstance.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
RocksDBinstance on success, null if the specifiedRocksDBcan 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 descriptorscolumnFamilyHandles- will be filled with ColumnFamilyHandle instances on open.- Returns:
- a
RocksDBinstance on success, null if the specifiedRocksDBcan 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-DBOptionsinstance.path- the path to the RocksDB.columnFamilyDescriptors- list of column family descriptorscolumnFamilyHandles- will be filled with ColumnFamilyHandle instances on open.- Returns:
- a
RocksDBinstance on success, null if the specifiedRocksDBcan 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-DBOptionsinstance.path- the path to the RocksDB.columnFamilyDescriptors- list of column family descriptorscolumnFamilyHandles- 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
RocksDBinstance on success, null if the specifiedRocksDBcan 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 calltryCatchUpWithPrimary()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
RocksDBinstance on success, null if the specifiedRocksDBcan 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 calltryCatchUpWithPrimary()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 descriptorscolumnFamilyHandles- will be filled with ColumnFamilyHandle instances on open.- Returns:
- a
RocksDBinstance on success, null if the specifiedRocksDBcan not be opened. - Throws:
RocksDBException- thrown if error happens in underlying native library.
-
closeE
public void closeE() throws RocksDBExceptionThis is similar toclose()except that it throws an exception if any error occurs. This will not fsync the WAL files. If syncing is required, the caller must first callsyncWal()orwrite(WriteOptions, WriteBatch)using an empty write batch withWriteOptions.setSync(boolean)set to true. See alsoclose().- Throws:
RocksDBException- if an error occurs whilst closing.
-
close
public void close()
This is similar tocloseE()except that it silently ignores any errors. This will not fsync the WAL files. If syncing is required, the caller must first callsyncWal()orwrite(WriteOptions, WriteBatch)using an empty write batch withWriteOptions.setSync(boolean)set to true. See alsoclose().- Specified by:
closein interfacejava.lang.AutoCloseable- Overrides:
closein classAbstractImmutableNativeReference
-
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 databasepath- 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:
ColumnFamilyHandleinstance.- 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 bycolumnFamilyHandle. This call only records a drop record in the manifest and prevents the column family from flushing and compacting.- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstance- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
dropColumnFamilies
public void dropColumnFamilies(java.util.List<ColumnFamilyHandle> columnFamilies) throws RocksDBException
- Throws:
RocksDBException
-
destroyColumnFamilyHandle
public void destroyColumnFamilyHandle(ColumnFamilyHandle columnFamilyHandle)
Deletes native column family handle of givenColumnFamilyHandleJava object and removes reference fromownedColumnFamilyHandles.- Parameters:
columnFamilyHandle- column family handle object.
-
put
public void put(byte[] key, byte[] value) throws RocksDBExceptionSet 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 RocksDBExceptionSet the database entry for "key" to "value".- Parameters:
key- The specified key to be insertedoffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- 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 keyvOffset- the offset of the "value" array to be used, must be non-negative and no longer than "key".lengthvLen- 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-ColumnFamilyHandleinstancekey- 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-ColumnFamilyHandleinstancekey- The specified key to be insertedoffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- 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 keyvOffset- the offset of the "value" array to be used, must be non-negative and no longer than "key".lengthvLen- 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-WriteOptionsinstance.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-WriteOptionsinstance.key- The specified key to be insertedoffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- 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 keyvOffset- the offset of the "value" array to be used, must be non-negative and no longer than "key".lengthvLen- 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-ColumnFamilyHandleinstancewriteOpts-WriteOptionsinstance.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-ColumnFamilyHandleinstancewriteOpts-WriteOptionsinstance.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-WriteOptionsinstance.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-ColumnFamilyHandleinstancewriteOpts-WriteOptionsinstance.key- The specified key to be insertedoffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- 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 keyvOffset- the offset of the "value" array to be used, must be non-negative and no longer than "key".lengthvLen- 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 RocksDBExceptionDeprecated.Usedelete(byte[])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 RocksDBExceptionDelete 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 RocksDBExceptionDelete 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 databaseoffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- 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.
-
remove
@Deprecated public void remove(ColumnFamilyHandle columnFamilyHandle, 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:
columnFamilyHandle-ColumnFamilyHandleinstancekey- Key to delete within database- 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-ColumnFamilyHandleinstancekey- 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-ColumnFamilyHandleinstancekey- Key to delete within databaseoffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- 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
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:
writeOpt- WriteOptions to be used with delete operationkey- 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 operationkey- 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 operationkey- Key to delete within databaseoffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- 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.
-
remove
@Deprecated public void remove(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpt, 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:
columnFamilyHandle-ColumnFamilyHandleinstancewriteOpt- WriteOptions to be used with delete operationkey- 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) 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-ColumnFamilyHandleinstancewriteOpt- WriteOptions to be used with delete operationkey- 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-ColumnFamilyHandleinstancewriteOpt- WriteOptions to be used with delete operationkey- Key to delete within databaseoffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- 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-ReadOptionsinstance.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
keyin byte. If the return value is greater than the length ofvalue, then it indicates that the size of the input buffervalueis 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-ColumnFamilyHandleinstanceopt-ReadOptionsinstance.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
keyin byte. If the return value is greater than the length ofvalue, then it indicates that the size of the input buffervalueis 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 forkey. 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 callingput(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 forkey. 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 callingput(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 fromkey- 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 forkey. 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 callingput(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 settingWriteOptions.setSync(boolean)true.- Parameters:
writeOpt- Write options for the deletekey- 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 forkey. 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 callingput(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 settingWriteOptions.setSync(boolean)true.- Parameters:
columnFamilyHandle- The column family to delete the key fromwriteOpt- Write options for the deletekey- Key to delete within database- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
deleteRange
public void deleteRange(byte[] beginKey, byte[] endKey) throws RocksDBExceptionRemoves 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-ColumnFamilyHandleinstancebeginKey- 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 operationbeginKey- 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-ColumnFamilyHandleinstancewriteOpt- WriteOptions to be used with delete operationbeginKey- 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 RocksDBExceptionAdd 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 RocksDBExceptionAdd 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".lengthlen- 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".lengthvLen- 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-ColumnFamilyHandleinstancekey- 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-ColumnFamilyHandleinstancekey- 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".lengthlen- 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".lengthvLen- 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-WriteOptionsfor 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-WriteOptionsfor 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".lengthlen- 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".lengthvLen- 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 operationkey- 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-ColumnFamilyHandleinstancewriteOpt- WriteOptions to be used with delete operationkey- 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-ColumnFamilyHandleinstancewriteOpts-WriteOptionsfor 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-ColumnFamilyHandleinstancewriteOpts-WriteOptionsfor 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".lengthlen- 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".lengthvLen- 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 instanceupdates- 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 instanceupdates- WriteBatchWithIndex instance- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
get
public int get(byte[] key, byte[] value) throws RocksDBExceptionGet 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
keyin byte. If the return value is greater than the length ofvalue, then it indicates that the size of the input buffervalueis 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 RocksDBExceptionGet 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".lengthlen- 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".lengthvLen- 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
keyin byte. If the return value is greater than the length ofvalue, then it indicates that the size of the input buffervalueis 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-ColumnFamilyHandleinstancekey- 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
keyin byte. If the return value is greater than the length ofvalue, then it indicates that the size of the input buffervalueis 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-ColumnFamilyHandleinstancekey- 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".lengthlen- 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".lengthvLen- 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
keyin byte. If the return value is greater than the length ofvalue, then it indicates that the size of the input buffervalueis 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-ReadOptionsinstance.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
keyin byte. If the return value is greater than the length ofvalue, then it indicates that the size of the input buffervalueis 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-ReadOptionsinstance.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".lengthlen- 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".lengthvLen- 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
keyin byte. If the return value is greater than the length ofvalue, then it indicates that the size of the input buffervalueis 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-ColumnFamilyHandleinstanceopt-ReadOptionsinstance.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
keyin byte. If the return value is greater than the length ofvalue, then it indicates that the size of the input buffervalueis 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-ColumnFamilyHandleinstanceopt-ReadOptionsinstance.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".lengthlen- 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".lengthvLen- 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
keyin byte. If the return value is greater than the length ofvalue, then it indicates that the size of the input buffervalueis 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 RocksDBExceptionThe 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 RocksDBExceptionThe 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".lengthlen- 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-ColumnFamilyHandleinstancekey- 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-ColumnFamilyHandleinstancekey- the key retrieve the value.offset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- 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".lengthlen- 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-ColumnFamilyHandleinstancekey- 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-ColumnFamilyHandleinstancekey- the key retrieve the value.offset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- 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 RocksDBExceptionDeprecated.ConsidermultiGetAsList(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.ConsidermultiGetAsList(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-ListcontainingColumnFamilyHandleinstances.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.ConsidermultiGetAsList(ReadOptions, List)instead.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.ConsidermultiGetAsList(ReadOptions, 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:
opt- Read options.columnFamilyHandleList-ListcontainingColumnFamilyHandleinstances.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 RocksDBExceptionTakes 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-ListcontainingColumnFamilyHandleinstances.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-ListcontainingColumnFamilyHandleinstances.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, thenvalueHoldermust be set. This check is potentially lighter-weight than invokingget(byte[]). One way to make this lighter weight is to avoid doing any IOs.- Parameters:
key- byte array of a key to search forvalueHolder- 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, thevaluewill 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, thenvalueHoldermust be set. This check is potentially lighter-weight than invokingget(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 foroffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- the length of the "key" array to be used, must be non-negative and no larger than "key".lengthvalueHolder- 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, thevaluewill 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, thenvalueHoldermust be set. This check is potentially lighter-weight than invokingget(ColumnFamilyHandle,byte[]). One way to make this lighter weight is to avoid doing any IOs.- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancekey- byte array of a key to search forvalueHolder- 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, thevaluewill 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, thenvalueHoldermust be set. This check is potentially lighter-weight than invokingget(ColumnFamilyHandle, byte[], int, int). One way to make this lighter weight is to avoid doing any IOs.- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancekey- byte array of a key to search foroffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- the length of the "key" array to be used, must be non-negative and no larger than "key".lengthvalueHolder- 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, thevaluewill 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, thenvalueHoldermust be set. This check is potentially lighter-weight than invokingget(ReadOptions, byte[]). One way to make this lighter weight is to avoid doing any IOs.- Parameters:
readOptions-ReadOptionsinstancekey- byte array of a key to search forvalueHolder- 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, thevaluewill 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, thenvalueHoldermust be set. This check is potentially lighter-weight than invokingget(ReadOptions, byte[], int, int). One way to make this lighter weight is to avoid doing any IOs.- Parameters:
readOptions-ReadOptionsinstancekey- byte array of a key to search foroffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- the length of the "key" array to be used, must be non-negative and no larger than "key".lengthvalueHolder- 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, thevaluewill 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, thenvalueHoldermust be set. This check is potentially lighter-weight than invokingget(ColumnFamilyHandle, ReadOptions, byte[]). One way to make this lighter weight is to avoid doing any IOs.- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancereadOptions-ReadOptionsinstancekey- byte array of a key to search forvalueHolder- 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, thevaluewill 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, thenvalueHoldermust be set. This check is potentially lighter-weight than invokingget(ColumnFamilyHandle, ReadOptions, byte[], int, int). One way to make this lighter weight is to avoid doing any IOs.- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstancereadOptions-ReadOptionsinstancekey- byte array of a key to search foroffset- the offset of the "key" array to be used, must be non-negative and no larger than "key".lengthlen- the length of the "key" array to be used, must be non-negative and no larger than "key".lengthvalueHolder- 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, thevaluewill 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-ReadOptionsinstance.- 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-ColumnFamilyHandleinstance- 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-ColumnFamilyHandleinstancereadOptions-ReadOptionsinstance.- 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-ListcontainingColumnFamilyHandleinstances.- Returns:
ListcontainingRocksIteratorinstances- 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-ListcontainingColumnFamilyHandleinstances.readOptions-ReadOptionsinstance.- Returns:
ListcontainingRocksIteratorinstances- 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
Snapshotinstance
-
releaseSnapshot
public void releaseSnapshot(Snapshot snapshot)
Release a previously acquired snapshot. The caller must not use "snapshot" after this call.- Parameters:
snapshot-Snapshotinstance
-
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
propertyis a valid property understood by this DB implementation, fillsvaluewith 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-ColumnFamilyHandleinstance, 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 RocksDBExceptionDB 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 RocksDBExceptionGets 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-ColumnFamilyHandleinstance, 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 RocksDBExceptionSimilar 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_ton 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
BigIntegerto reflect the correct value. The correct behavior is guaranteed if2^64is 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_ton 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
BigIntegerto reflect the correct value. The correct behavior is guaranteed if2^64is 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-ColumnFamilyHandleinstance, or null for the default column familyproperty- to be fetched.- Returns:
- numerical property value
- Throws:
RocksDBException- if an error happens in the underlying native code.
-
resetStats
public void resetStats() throws RocksDBExceptionReset internal stats for DB and all column families. Note this doesn't resetOptions.statistics()as it is not owned by DB.- Throws:
RocksDBException- if an error occurs whilst reseting the stats
-
getAggregatedLongProperty
public long getAggregatedLongProperty(java.lang.String property) throws RocksDBExceptionReturn sum of the getLongProperty of all the column families
Note: As the returned property is of type
uint64_ton 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
BigIntegerto reflect the correct value. The correct behavior is guaranteed if2^64is 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. IfsizeApproximationFlagsdefines 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-ColumnFamilyHandleinstance, or null for the default column familyranges- the ranges over which to approximate sizessizeApproximationFlags- 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. IfsizeApproximationFlagsdefines 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 sizessizeApproximationFlags- flags to determine what to include in the approximation.- Returns:
- the sizes.
-
getApproximateMemTableStats
public RocksDB.CountAndSize getApproximateMemTableStats(ColumnFamilyHandle columnFamilyHandle, Range range)
This method is similar togetApproximateSizes(ColumnFamilyHandle, List, SizeApproximationFlag...), except that it returns approximate number of records and size in memtables.- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstance, or null for the default column familyrange- the ranges over which to get the memtable stats- Returns:
- the count and size for the range
-
getApproximateMemTableStats
public RocksDB.CountAndSize getApproximateMemTableStats(Range range)
This method is similar togetApproximateSizes(ColumnFamilyHandle, List, SizeApproximationFlag...), except that it returns approximate number of records and size in memtables.- Parameters:
range- the ranges over which to get the memtable stats- Returns:
- the count and size for the range
-
compactRange
public void compactRange() throws RocksDBExceptionRange compaction of database.
Note: After the database has been compacted, all data will have been pushed down to the last level containing any data.
See also
- Throws:
RocksDBException- thrown if an error occurs within the native part of the library.
-
compactRange
public void compactRange(ColumnFamilyHandle columnFamilyHandle) 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.
See also
- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstance, or null for the default column family.- Throws:
RocksDBException- thrown if an error occurs within the native part of the library.
-
compactRange
public void compactRange(byte[] begin, byte[] end) throws RocksDBExceptionRange compaction of database.
Note: After the database has been compacted, all data will have been pushed down to the last level containing any data.
See also
- Parameters:
begin- start of key range (included in range)end- end of key range (excluded from range)- Throws:
RocksDBException- thrown if an error occurs within the native part of the library.
-
compactRange
public void compactRange(ColumnFamilyHandle columnFamilyHandle, byte[] begin, byte[] end) 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.
See also
- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstance, or null for the default column family.begin- start of key range (included in range)end- end of key range (excluded from range)- Throws:
RocksDBException- thrown if an error occurs within the native part of the library.
-
compactRange
@Deprecated public void compactRange(boolean changeLevel, int targetLevel, int targetPathId) throws RocksDBExceptionDeprecated.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:
changeLevel- reduce level after compactiontargetLevel- target level to compact totargetPathId- the target path id of output path- Throws:
RocksDBException- thrown if an error occurs within the native part of the library.
-
compactRange
@Deprecated public void compactRange(ColumnFamilyHandle columnFamilyHandle, boolean changeLevel, int targetLevel, int targetPathId) throws RocksDBException
Deprecated.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.
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:
columnFamilyHandle-ColumnFamilyHandleinstance, or null for the default column family.changeLevel- reduce level after compactiontargetLevel- target level to compact totargetPathId- the target path id of output path- Throws:
RocksDBException- thrown if an error occurs within the native part of the library.
-
compactRange
@Deprecated public void compactRange(byte[] begin, byte[] end, boolean changeLevel, int targetLevel, int targetPathId) throws RocksDBExceptionDeprecated.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 compactiontargetLevel- target level to compact totargetPathId- the target path id of output path- Throws:
RocksDBException- thrown if an error occurs within the native part of the library.
-
compactRange
@Deprecated public void compactRange(ColumnFamilyHandle columnFamilyHandle, byte[] begin, byte[] end, boolean changeLevel, int targetLevel, int targetPathId) throws RocksDBException
Deprecated.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.
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:
columnFamilyHandle-ColumnFamilyHandleinstance.begin- start of key range (included in range)end- end of key range (excluded from range)changeLevel- reduce level after compactiontargetLevel- target level to compact totargetPathId- 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-ColumnFamilyHandleinstance.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(ColumnFamilyHandle columnFamilyHandle, MutableColumnFamilyOptions mutableColumnFamilyOptions) throws RocksDBException
Change the options for the column family handle.- Parameters:
columnFamilyHandle-ColumnFamilyHandleinstance, or null for the default column family.mutableColumnFamilyOptions- the options.- Throws:
RocksDBException- if an error occurs whilst setting the options
-
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 fromcompactRange(ColumnFamilyHandle, byte[], byte[])in that CompactFiles() performs the compaction job using the CURRENT thread.- Parameters:
compactionOptions- compaction optionsinputFileNames- the name of the files to compactoutputLevel- the level to which they should be compactedoutputPathId- the id of the output path, or -1compactionJobInfo- 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 fromcompactRange(ColumnFamilyHandle, byte[], byte[])in that CompactFiles() performs the compaction job using the CURRENT thread.- Parameters:
compactionOptions- compaction optionscolumnFamilyHandle- columnFamilyHandle, or null for the default column familyinputFileNames- the name of the files to compactoutputLevel- the level to which they should be compactedoutputPathId- the id of the output path, or -1compactionJobInfo- 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 RocksDBExceptionThis function will wait until all currently running background processes finish. After it returns, no background process will be run untilcontinueBackgroundWork()is called- Throws:
RocksDBException- if an error occurs when pausing background work
-
continueBackgroundWork
public void continueBackgroundWork() throws RocksDBExceptionResumes background work which was suspended by previously callingpauseBackgroundWork()- Throws:
RocksDBException- if an error occurs when resuming 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 theColumnFamilyOptions.disableAutoCompactions()option for each column family to false, after which it will schedule a flush/compaction. NOTE: Setting disableAutoCompactions to 'false' throughsetOptions(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 toopen(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-FlushOptionsinstance.- 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-FlushOptionsinstance.columnFamilyHandle-ColumnFamilyHandleinstance.- 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 callingflush(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-FlushOptionsinstance.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 RocksDBExceptionFlush the WAL memory buffer to the file. Ifsyncis true, it callssyncWal()afterwards.- Parameters:
sync- true to also fsync to disk.- Throws:
RocksDBException- if an error occurs whilst flushing
-
syncWal
public void syncWal() throws RocksDBExceptionSync the WAL. Note thatwrite(WriteOptions, WriteBatch)followed bysyncWal()is not exactly the same aswrite(WriteOptions, WriteBatch)withWriteOptions.sync()set to true; In the latter case the changes won't be visible until the sync is done. Currently only works ifOptions.allowMmapWrites()is set to false.- Throws:
RocksDBException- if an error occurs whilst syncing
-
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 RocksDBExceptionPrevent 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 RocksDBExceptionAllow 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() throws RocksDBException
Retrieve the list of all files in the database after flushing the memtable. SeegetLiveFiles(boolean).- Returns:
- the live files
- Throws:
RocksDBException- if an error occurs whilst retrieving the list of live files
-
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 ifflushMemtableis true, you still need to callgetSortedWalFiles()aftergetLiveFiles(boolean)to compensate for new data that arrived to already-flushed column families while other column families were flushing. NOTE: CallinggetLiveFiles(boolean)followed bygetSortedWalFiles()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:
TransactionLogIteratorinstance.- Throws:
RocksDBException- if iterator cannot be retrieved from native-side.
-
deleteFile
public void deleteFile(java.lang.String name) throws RocksDBExceptionDelete 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 RocksDBExceptioningestExternalFile 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 usingSstFileWriter(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 ingestingestExternalFileOptions- 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 usingSstFileWriter(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 filesfilePathList- The list of files to ingestingestExternalFileOptions- the options for the ingestion- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
verifyChecksum
public void verifyChecksum() throws RocksDBExceptionVerify checksum- Throws:
RocksDBException- if the checksum is not valid
-
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 RocksDBExceptionPromote L0 for the default column family.- Parameters:
targetLevel- the target level for L0- Throws:
RocksDBException- if an error occurs whilst promoting L0
-
startTrace
public void startTrace(TraceOptions traceOptions, AbstractTraceWriter traceWriter) throws RocksDBException
Trace DB operations. UseendTrace()to stop tracing.- Parameters:
traceOptions- the optionstraceWriter- the trace writer- Throws:
RocksDBException- if an error occurs whilst starting the trace
-
endTrace
public void endTrace() throws RocksDBExceptionStop tracing DB operations. SeestartTrace(TraceOptions, AbstractTraceWriter)- Throws:
RocksDBException- if an error occurs whilst ending the trace
-
tryCatchUpWithPrimary
public void tryCatchUpWithPrimary() throws RocksDBExceptionMake 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 endranges- - 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 RocksDBExceptionStatic method to destroy the contents of the specified database. Be very careful using this method.- Parameters:
path- the path to the Rocksdb database.options-Optionsinstance.- Throws:
RocksDBException- thrown if error happens in underlying native library.
-
storeOptionsInstance
protected void storeOptionsInstance(DBOptionsInterface options)
-
disposeInternal
protected void disposeInternal(long handle)
- Specified by:
disposeInternalin classRocksObject
-
-