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
  • Field Details

    • DEFAULT_CF

      public static final String 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

      public org.rocksdb.ColumnFamilyHandle getColumnFamilyHandle(String cfname)
    • createAndGetColumnFamilyHandle

      public org.rocksdb.ColumnFamilyHandle createAndGetColumnFamilyHandle(String cfname) throws org.rocksdb.RocksDBException
      Throws:
      org.rocksdb.RocksDBException
    • dropColumnFamily

      public void dropColumnFamily(String cfname) throws org.rocksdb.RocksDBException
      Removes all data belonging to the column family

      If 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

      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()
    • 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

      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 Lock from an fixed size array based on a hash of the key and performing the Lock.lock() operation on it.

      Parameters:
      dbKey -
    • unlock

      public void unlock(byte[] dbKey)
      Unlock the key previously locked by lock(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 stop

      Throws 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

      public static String cfName(byte[] cfb)
    • cfNameb

      public static byte[] cfNameb(String cfName)