Class KeyValueStorageRocksDB
- java.lang.Object
-
- org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorageRocksDB
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,KeyValueStorage
public class KeyValueStorageRocksDB extends java.lang.Object implements KeyValueStorage
RocksDB based implementation of the KeyValueStorage.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorage
KeyValueStorage.Batch, KeyValueStorage.CloseableIterator<T>
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static KeyValueStorageFactory
factory
-
Constructor Summary
Constructors Constructor Description KeyValueStorageRocksDB(java.lang.String basePath, java.lang.String subPath, KeyValueStorageFactory.DbConfigType dbConfigType, ServerConfiguration conf)
KeyValueStorageRocksDB(java.lang.String basePath, java.lang.String subPath, KeyValueStorageFactory.DbConfigType dbConfigType, ServerConfiguration conf, boolean readOnly)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
compact()
Compact storage full range.void
compact(byte[] firstKey, byte[] lastKey)
Compact storage within a specified range.long
count()
(package private) org.rocksdb.RocksDB
db()
void
delete(byte[] key)
byte[]
get(byte[] key)
Get the value associated with the given key.int
get(byte[] key, byte[] value)
Get the value associated with the given key.java.util.Map.Entry<byte[],byte[]>
getCeil(byte[] key)
Get the entry whose key is bigger or equal the supplied key.(package private) java.util.List<org.rocksdb.ColumnFamilyDescriptor>
getColumnFamilyDescriptors()
java.lang.String
getDBPath()
Get storage path.java.util.Map.Entry<byte[],byte[]>
getFloor(byte[] key)
Get the entry whose key is the biggest and it's lesser than the supplied key.(package private) org.rocksdb.RocksObject
getOptions()
KeyValueStorage.CloseableIterator<java.util.Map.Entry<byte[],byte[]>>
iterator()
Return an iterator object that can be used to sequentially scan through all the entries in the database.KeyValueStorage.CloseableIterator<byte[]>
keys()
Get an iterator over to scan sequentially through all the keys in the database.KeyValueStorage.CloseableIterator<byte[]>
keys(byte[] firstKey, byte[] lastKey)
Get an iterator over to scan sequentially through all the keys within a specified range.KeyValueStorage.Batch
newBatch()
void
put(byte[] key, byte[] value)
void
sync()
Commit all pending write to durable storage.
-
-
-
Field Detail
-
factory
static KeyValueStorageFactory factory
-
-
Constructor Detail
-
KeyValueStorageRocksDB
public KeyValueStorageRocksDB(java.lang.String basePath, java.lang.String subPath, KeyValueStorageFactory.DbConfigType dbConfigType, ServerConfiguration conf) throws java.io.IOException
- Throws:
java.io.IOException
-
KeyValueStorageRocksDB
public KeyValueStorageRocksDB(java.lang.String basePath, java.lang.String subPath, KeyValueStorageFactory.DbConfigType dbConfigType, ServerConfiguration conf, boolean readOnly) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
put
public void put(byte[] key, byte[] value) throws java.io.IOException
- Specified by:
put
in interfaceKeyValueStorage
- Throws:
java.io.IOException
-
get
public byte[] get(byte[] key) throws java.io.IOException
Description copied from interface:KeyValueStorage
Get the value associated with the given key.- Specified by:
get
in interfaceKeyValueStorage
- Parameters:
key
- the key to lookup- Returns:
- the value or null if the key was not found
- Throws:
java.io.IOException
-
get
public int get(byte[] key, byte[] value) throws java.io.IOException
Description copied from interface:KeyValueStorage
Get the value associated with the given key.This method will use the provided array store the value
- Specified by:
get
in interfaceKeyValueStorage
- Parameters:
key
- the key to lookupvalue
- an array where to store the result- Returns:
- -1 if the entry was not found or the length of the value
- Throws:
java.io.IOException
- if the value array could not hold the result
-
getFloor
public java.util.Map.Entry<byte[],byte[]> getFloor(byte[] key) throws java.io.IOException
Description copied from interface:KeyValueStorage
Get the entry whose key is the biggest and it's lesser than the supplied key.For example if the db contains :
{ 1 : 'a', 2 : 'b', 3 : 'c' }
Then:
getFloor(3) --> (2, 'b')
- Specified by:
getFloor
in interfaceKeyValueStorage
- Parameters:
key
- the non-inclusive upper limit key- Returns:
- the entry before or null if there's no entry before key
- Throws:
java.io.IOException
-
getCeil
public java.util.Map.Entry<byte[],byte[]> getCeil(byte[] key) throws java.io.IOException
Description copied from interface:KeyValueStorage
Get the entry whose key is bigger or equal the supplied key.- Specified by:
getCeil
in interfaceKeyValueStorage
- Returns:
- Throws:
java.io.IOException
-
delete
public void delete(byte[] key) throws java.io.IOException
- Specified by:
delete
in interfaceKeyValueStorage
- Throws:
java.io.IOException
-
getDBPath
public java.lang.String getDBPath()
Description copied from interface:KeyValueStorage
Get storage path.- Specified by:
getDBPath
in interfaceKeyValueStorage
-
compact
public void compact(byte[] firstKey, byte[] lastKey) throws java.io.IOException
Description copied from interface:KeyValueStorage
Compact storage within a specified range.- Specified by:
compact
in interfaceKeyValueStorage
- Parameters:
firstKey
- the first key in the range (included)lastKey
- the last key in the range (not included)- Throws:
java.io.IOException
-
compact
public void compact() throws java.io.IOException
Description copied from interface:KeyValueStorage
Compact storage full range.- Specified by:
compact
in interfaceKeyValueStorage
- Throws:
java.io.IOException
-
sync
public void sync() throws java.io.IOException
Description copied from interface:KeyValueStorage
Commit all pending write to durable storage.- Specified by:
sync
in interfaceKeyValueStorage
- Throws:
java.io.IOException
-
keys
public KeyValueStorage.CloseableIterator<byte[]> keys()
Description copied from interface:KeyValueStorage
Get an iterator over to scan sequentially through all the keys in the database.- Specified by:
keys
in interfaceKeyValueStorage
- Returns:
-
keys
public KeyValueStorage.CloseableIterator<byte[]> keys(byte[] firstKey, byte[] lastKey)
Description copied from interface:KeyValueStorage
Get an iterator over to scan sequentially through all the keys within a specified range.- Specified by:
keys
in interfaceKeyValueStorage
- Parameters:
firstKey
- the first key in the range (included)lastKey
- the lastKey in the range (not included)
-
iterator
public KeyValueStorage.CloseableIterator<java.util.Map.Entry<byte[],byte[]>> iterator()
Description copied from interface:KeyValueStorage
Return an iterator object that can be used to sequentially scan through all the entries in the database.- Specified by:
iterator
in interfaceKeyValueStorage
-
count
public long count() throws java.io.IOException
- Specified by:
count
in interfaceKeyValueStorage
- Returns:
- the number of keys.
- Throws:
java.io.IOException
-
newBatch
public KeyValueStorage.Batch newBatch()
- Specified by:
newBatch
in interfaceKeyValueStorage
-
db
org.rocksdb.RocksDB db()
-
getColumnFamilyDescriptors
java.util.List<org.rocksdb.ColumnFamilyDescriptor> getColumnFamilyDescriptors()
-
getOptions
org.rocksdb.RocksObject getOptions()
-
-