Class 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.
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • put

        public void put​(byte[] key,
                        byte[] value)
                 throws java.io.IOException
        Specified by:
        put in interface KeyValueStorage
        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 interface KeyValueStorage
        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 interface KeyValueStorage
        Parameters:
        key - the key to lookup
        value - 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 interface KeyValueStorage
        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 interface KeyValueStorage
        Returns:
        Throws:
        java.io.IOException
      • delete

        public void delete​(byte[] key)
                    throws java.io.IOException
        Specified by:
        delete in interface KeyValueStorage
        Throws:
        java.io.IOException
      • 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 interface KeyValueStorage
        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 interface KeyValueStorage
        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 interface KeyValueStorage
        Throws:
        java.io.IOException
      • 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 interface KeyValueStorage
        Parameters:
        firstKey - the first key in the range (included)
        lastKey - the lastKey in the range (not included)
      • count

        public long count()
                   throws java.io.IOException
        Specified by:
        count in interface KeyValueStorage
        Returns:
        the number of keys.
        Throws:
        java.io.IOException
      • db

        org.rocksdb.RocksDB db()
      • getColumnFamilyDescriptors

        java.util.List<org.rocksdb.ColumnFamilyDescriptor> getColumnFamilyDescriptors()
      • getOptions

        org.rocksdb.RocksObject getOptions()