Interface KeyValueStorage

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
KeyValueStorageRocksDB

public interface KeyValueStorage extends Closeable
Abstraction of a generic key-value local database.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Interface for a batch to be written in the storage.
    static interface 
    Iterator interface.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Compact storage full range.
    default void
    compact(byte[] firstKey, byte[] lastKey)
    Compact storage within a specified range.
    long
     
    void
    delete(byte[] key)
     
    byte[]
    get(byte[] key)
    Get the value associated with the given key.
    int
    get(byte[] key, byte[] value)
    Get the value associated with the given key.
    Map.Entry<byte[],byte[]>
    getCeil(byte[] key)
    Get the entry whose key is bigger or equal the supplied key.
    Get storage path.
    Map.Entry<byte[],byte[]>
    getFloor(byte[] key)
    Get the entry whose key is the biggest and it's lesser than the supplied key.
    Return an iterator object that can be used to sequentially scan through all the entries in the database.
    Get an iterator over to scan sequentially through all the keys in the database.
    keys(byte[] firstKey, byte[] lastKey)
    Get an iterator over to scan sequentially through all the keys within a specified range.
     
    void
    put(byte[] key, byte[] value)
     
    void
    Commit all pending write to durable storage.

    Methods inherited from interface java.io.Closeable

    close
  • Method Details

    • put

      void put(byte[] key, byte[] value) throws IOException
      Throws:
      IOException
    • get

      byte[] get(byte[] key) throws IOException
      Get the value associated with the given key.
      Parameters:
      key - the key to lookup
      Returns:
      the value or null if the key was not found
      Throws:
      IOException
    • get

      int get(byte[] key, byte[] value) throws IOException
      Get the value associated with the given key.

      This method will use the provided array store the value

      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:
      IOException - if the value array could not hold the result
    • getFloor

      Map.Entry<byte[],byte[]> getFloor(byte[] key) throws IOException
      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')
       
      Parameters:
      key - the non-inclusive upper limit key
      Returns:
      the entry before or null if there's no entry before key
      Throws:
      IOException
    • getCeil

      Map.Entry<byte[],byte[]> getCeil(byte[] key) throws IOException
      Get the entry whose key is bigger or equal the supplied key.
      Parameters:
      key -
      Returns:
      Throws:
      IOException
    • delete

      void delete(byte[] key) throws IOException
      Parameters:
      key -
      Throws:
      IOException
    • compact

      default void compact(byte[] firstKey, byte[] lastKey) throws IOException
      Compact storage within a specified range.
      Parameters:
      firstKey - the first key in the range (included)
      lastKey - the last key in the range (not included)
      Throws:
      IOException
    • compact

      default void compact() throws IOException
      Compact storage full range.
      Throws:
      IOException
    • getDBPath

      String getDBPath()
      Get storage path.
    • keys

      Get an iterator over to scan sequentially through all the keys in the database.
      Returns:
    • keys

      KeyValueStorage.CloseableIterator<byte[]> keys(byte[] firstKey, byte[] lastKey)
      Get an iterator over to scan sequentially through all the keys within a specified range.
      Parameters:
      firstKey - the first key in the range (included)
      lastKey - the lastKey in the range (not included)
    • iterator

      KeyValueStorage.CloseableIterator<Map.Entry<byte[],byte[]>> iterator()
      Return an iterator object that can be used to sequentially scan through all the entries in the database.
    • sync

      void sync() throws IOException
      Commit all pending write to durable storage.
      Throws:
      IOException
    • count

      long count() throws IOException
      Returns:
      the number of keys.
      Throws:
      IOException
    • newBatch