Package org.yamcs.yarch.rocksdb
Class YRDB
- java.lang.Object
-
- org.yamcs.yarch.rocksdb.YRDB
-
public class YRDB extends Object
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
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringcfNameToString(byte[] cfname)org.rocksdb.ColumnFamilyHandlecreateColumnFamily(byte[] cfname)org.rocksdb.ColumnFamilyHandlecreateColumnFamily(String name)voiddelete(byte[] k)voiddropColumnFamily(org.rocksdb.ColumnFamilyHandle cfh)byte[]get(byte[] k)RocksDB.get(byte[], byte[])byte[]get(org.rocksdb.ColumnFamilyHandle cfh, byte[] key)longgetApproxNumRecords()longgetApproxNumRecords(org.rocksdb.ColumnFamilyHandle cfh)List<byte[]>getColumnFamilies()Collection<String>getColumnFamiliesAsStrings()org.rocksdb.ColumnFamilyHandlegetColumnFamilyHandle(byte[] cfname)org.rocksdb.ColumnFamilyHandlegetColumnFamilyHandle(String cfname)org.rocksdb.RocksDBgetDb()StringgetPath()StringgetProperties()booleanisOpen()voidlock(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.DbIteratornewDescendingPrefixIterator(byte[] prefix)Returns an iterator that iterates in reverse over all elements with key starting with the prefixorg.rocksdb.RocksIteratornewIterator()org.rocksdb.RocksIteratornewIterator(org.rocksdb.ColumnFamilyHandle cfh)List<org.rocksdb.RocksIterator>newIterators(List<org.rocksdb.ColumnFamilyHandle> cfhList, boolean tailing)DbIteratornewPrefixIterator(byte[] prefix)Returns an iterator that iterates over all elements with key starting with the prefixvoidput(byte[] k, byte[] v)voidput(org.rocksdb.ColumnFamilyHandle cfh, byte[] k, byte[] v)voidput(org.rocksdb.WriteOptions writeOpt, byte[] k, byte[] v)List<byte[]>scanPartitions(int size)scans and returns a list of all prefixes of specified sizevoidunlock(byte[] dbKey)Unlock the key previously locked bylock(byte[])voidwrite(org.rocksdb.WriteOptions writeOpts, org.rocksdb.WriteBatch writeBatch)
-
-
-
Method Detail
-
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
-
getColumnFamilyHandle
public org.rocksdb.ColumnFamilyHandle getColumnFamilyHandle(byte[] cfname)
-
getColumnFamilyHandle
public org.rocksdb.ColumnFamilyHandle getColumnFamilyHandle(String cfname)
-
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.RocksDBExceptionRocksDB.get(byte[], byte[])- Throws:
org.rocksdb.RocksDBException
-
createColumnFamily
public org.rocksdb.ColumnFamilyHandle createColumnFamily(byte[] cfname) throws org.rocksdb.RocksDBException- 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.WriteOptions writeOpt, byte[] k, byte[] v) throws org.rocksdb.RocksDBException- Throws:
org.rocksdb.RocksDBException
-
getColumnFamilies
public List<byte[]> getColumnFamilies()
-
getColumnFamiliesAsStrings
public Collection<String> getColumnFamiliesAsStrings()
-
getPath
public String getPath()
-
getProperties
public String getProperties() throws org.rocksdb.RocksDBException
- Throws:
org.rocksdb.RocksDBException
-
cfNameToString
public static String cfNameToString(byte[] cfname)
-
getDb
public org.rocksdb.RocksDB getDb()
-
dropColumnFamily
public void dropColumnFamily(org.rocksdb.ColumnFamilyHandle cfh) throws org.rocksdb.RocksDBException- Throws:
org.rocksdb.RocksDBException
-
scanPartitions
public List<byte[]> scanPartitions(int size) throws IOException
scans and returns a list of all prefixes of specified size- Parameters:
size-- Returns:
- list of partitions
- Throws:
IOException
-
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
-
newPrefixIterator
public DbIterator newPrefixIterator(byte[] prefix)
Returns an iterator that iterates over all elements with key starting with the prefix
-
newDescendingPrefixIterator
public DbIterator newDescendingPrefixIterator(byte[] prefix)
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
Lockfrom 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
-
-