Package org.yamcs.yarch.rocksdb
Class YRDB
java.lang.Object
org.yamcs.yarch.rocksdb.YRDB
wrapper around RocksDB that keeps track of column families. It also maintains a reference count and last access
timeused by the RdbFactory to close the database if not used for a while
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
cfName
(byte[] cfb) static byte[]
static String
cfNameToString
(byte[] cfname) void
compactRange
(String cfName, byte[] start, byte[] stop) Compact the given column family between start and stopvoid
compactRange
(org.rocksdb.ColumnFamilyHandle cfh) org.rocksdb.ColumnFamilyHandle
createAndGetColumnFamilyHandle
(String cfname) org.rocksdb.ColumnFamilyHandle
createColumnFamily
(String name) void
delete
(byte[] k) void
delete
(org.rocksdb.ColumnFamilyHandle cfh, byte[] k) void
disableAutoCompaction
(org.rocksdb.ColumnFamilyHandle cfh) void
dropColumnFamily
(String cfname) Removes all data belonging to the column familyvoid
enableAutoCompaction
(org.rocksdb.ColumnFamilyHandle cfh) byte[]
get
(byte[] k) RocksDB.get(org.rocksdb.ReadOptions, java.nio.ByteBuffer, java.nio.ByteBuffer)
byte[]
get
(org.rocksdb.ColumnFamilyHandle cfh, byte[] key) long
long
getApproxNumRecords
(org.rocksdb.ColumnFamilyHandle cfh) org.rocksdb.ColumnFamilyHandle
getColumnFamilyHandle
(String cfname) org.rocksdb.RocksDB
getDb()
org.rocksdb.ColumnFamilyHandle
getPath()
org.rocksdb.Snapshot
boolean
isOpen()
void
lock
(byte[] dbKey) Lock the key - that is if another thread called this method for that key, wait until someone calls the unlock on the same key.newDescendingPrefixIterator
(byte[] prefix) Returns an iterator that iterates in reverse over all elements with key starting with the prefixorg.rocksdb.RocksIterator
org.rocksdb.RocksIterator
newIterator
(org.rocksdb.ColumnFamilyHandle cfh) List<org.rocksdb.RocksIterator>
newIterators
(List<org.rocksdb.ColumnFamilyHandle> cfhList, boolean tailing) newPrefixIterator
(byte[] prefix) Returns an iterator that iterates over all elements with key starting with the prefixvoid
put
(byte[] k, byte[] v) void
put
(org.rocksdb.ColumnFamilyHandle cfh, byte[] k, byte[] v) void
put
(org.rocksdb.ColumnFamilyHandle cfh, org.rocksdb.WriteOptions writeOpt, byte[] k, byte[] v) void
releaseSnapshot
(org.rocksdb.Snapshot snapshot) void
unlock
(byte[] dbKey) Unlock the key previously locked bylock(byte[])
void
write
(org.rocksdb.WriteOptions writeOpts, org.rocksdb.WriteBatch writeBatch)
-
Field Details
-
DEFAULT_CF
-
-
Method Details
-
isOpen
public boolean isOpen()- Returns:
- true if the database is open
-
newIterators
public List<org.rocksdb.RocksIterator> newIterators(List<org.rocksdb.ColumnFamilyHandle> cfhList, boolean tailing) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
newIterator
public org.rocksdb.RocksIterator newIterator() throws org.rocksdb.RocksDBException- Throws:
org.rocksdb.RocksDBException
-
newIterator
public org.rocksdb.RocksIterator newIterator(org.rocksdb.ColumnFamilyHandle cfh) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
getDefaultColumnFamilyHandle
public org.rocksdb.ColumnFamilyHandle getDefaultColumnFamilyHandle() -
getColumnFamilyHandle
-
createAndGetColumnFamilyHandle
public org.rocksdb.ColumnFamilyHandle createAndGetColumnFamilyHandle(String cfname) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
dropColumnFamily
Removes all data belonging to the column familyIf the column family does not exist returns without doing anything
- Throws:
org.rocksdb.RocksDBException
-
get
public byte[] get(org.rocksdb.ColumnFamilyHandle cfh, byte[] key) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
get
public byte[] get(byte[] k) throws org.rocksdb.RocksDBException RocksDB.get(org.rocksdb.ReadOptions, java.nio.ByteBuffer, java.nio.ByteBuffer)
- Throws:
org.rocksdb.RocksDBException
-
createColumnFamily
public org.rocksdb.ColumnFamilyHandle createColumnFamily(String name) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
put
public void put(org.rocksdb.ColumnFamilyHandle cfh, byte[] k, byte[] v) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
put
public void put(byte[] k, byte[] v) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
put
public void put(org.rocksdb.ColumnFamilyHandle cfh, org.rocksdb.WriteOptions writeOpt, byte[] k, byte[] v) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
getColumnFamiliesAsStrings
-
getPath
-
getProperties
- Throws:
org.rocksdb.RocksDBException
-
cfNameToString
-
getDb
public org.rocksdb.RocksDB getDb() -
getApproxNumRecords
public long getApproxNumRecords() throws org.rocksdb.RocksDBException- Throws:
org.rocksdb.RocksDBException
-
getApproxNumRecords
public long getApproxNumRecords(org.rocksdb.ColumnFamilyHandle cfh) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
delete
public void delete(byte[] k) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
delete
public void delete(org.rocksdb.ColumnFamilyHandle cfh, byte[] k) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
newPrefixIterator
Returns an iterator that iterates over all elements with key starting with the prefix -
newDescendingPrefixIterator
Returns an iterator that iterates in reverse over all elements with key starting with the prefix -
lock
public void lock(byte[] dbKey) Lock the key - that is if another thread called this method for that key, wait until someone calls the unlock on the same key.The method is implemented by first selecting a
Lock
from an fixed size array based on a hash of the key and performing theLock.lock()
operation on it.- Parameters:
dbKey
-
-
unlock
public void unlock(byte[] dbKey) Unlock the key previously locked bylock(byte[])
- Parameters:
dbKey
-
-
write
public void write(org.rocksdb.WriteOptions writeOpts, org.rocksdb.WriteBatch writeBatch) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
getSnapshot
public org.rocksdb.Snapshot getSnapshot() -
releaseSnapshot
public void releaseSnapshot(org.rocksdb.Snapshot snapshot) -
compactRange
public void compactRange(String cfName, byte[] start, byte[] stop) throws org.rocksdb.RocksDBException Compact the given column family between start and stopThrows an
IllegalArgumentException
if there is no column family by the given name- Throws:
org.rocksdb.RocksDBException
-
disableAutoCompaction
public void disableAutoCompaction(org.rocksdb.ColumnFamilyHandle cfh) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
enableAutoCompaction
public void enableAutoCompaction(org.rocksdb.ColumnFamilyHandle cfh) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
compactRange
public void compactRange(org.rocksdb.ColumnFamilyHandle cfh) throws org.rocksdb.RocksDBException - Throws:
org.rocksdb.RocksDBException
-
cfName
-
cfNameb
-