Class 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 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.RocksDBException
        RocksDB.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 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