Class SnapshotLevelDBKVStore

All Implemented Interfaces:
CloseableKVStore, KVStore, Closeable, AutoCloseable

public class SnapshotLevelDBKVStore extends LevelDBKVStore implements CloseableKVStore
Read-only KVStore view of a LevelDB Snapshot.

Instances must be close()'d when no longer needed to avoid leaking resources associated with iterators. This class ensures that the configured Snapshot is closed when this instance is closed.

All mutation operations throw UnsupportedOperationException.

  • Constructor Details

    • SnapshotLevelDBKVStore

      public SnapshotLevelDBKVStore(org.iq80.leveldb.DB db, boolean verifyChecksums)
      Constructor.
      Parameters:
      db - LevelDB database to snapshot
      verifyChecksums - whether to verify checksums on reads
      Throws:
      NullPointerException - if db is null
  • Method Details

    • close

      public void close()
      Description copied from class: LevelDBKVStore
      Close this instance.

      This closes any unclosed iterators returned from getRange(). This does not close the underlying DB or any associated WriteBatch.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface CloseableKVStore
      Overrides:
      close in class LevelDBKVStore
    • put

      public void put(byte[] key, byte[] value)
      Description copied from interface: KVStore
      Set the value associated with the given key.
      Specified by:
      put in interface KVStore
      Overrides:
      put in class LevelDBKVStore
      Parameters:
      key - key
      value - value
    • remove

      public void remove(byte[] key)
      Description copied from interface: KVStore
      Remove the key/value pair with the given key, if it exists.
      Specified by:
      remove in interface KVStore
      Overrides:
      remove in class LevelDBKVStore
      Parameters:
      key - key
    • removeRange

      public void removeRange(byte[] minKey, byte[] maxKey)
      Description copied from interface: KVStore
      Remove all key/value pairs whose keys are in a given range.

      The minKey must be less than or equal to maxKey; if they equal (and not null) then nothing happens; if they are both null then all entries are deleted.

      If keys starting with 0xff are not supported by this instance, then:

      • If minKey starts with 0xff, then no change occurs
      • If maxKey starts with 0xff, then this method behaves as if maxKey were null
      Specified by:
      removeRange in interface KVStore
      Overrides:
      removeRange in class AbstractKVStore
      Parameters:
      minKey - minimum key (inclusive), or null for no minimum
      maxKey - maximum key (exclusive), or null for no maximum
    • adjustCounter

      public void adjustCounter(byte[] key, long amount)
      Description copied from interface: KVStore
      Adjust the counter at the given key by the given amount.

      Ideally this operation should behave in a lock-free manner, so that concurrent transactions can invoke it without conflict. However, when lock-free behavior occurs (if at all) depends on the implementation.

      If there is no value associated with key, or key's value is not a valid counter encoding as would be acceptable to decodeCounter(), then how this operation affects key's value is undefined.

      Specified by:
      adjustCounter in interface KVStore
      Overrides:
      adjustCounter in class AbstractKVStore
      Parameters:
      key - key
      amount - amount to adjust counter value by