Class SnapshotLevelDBKVStore
- All Implemented Interfaces:
CloseableKVStore
,KVStore
,Closeable
,AutoCloseable
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 Summary
ConstructorDescriptionSnapshotLevelDBKVStore
(org.iq80.leveldb.DB db, boolean verifyChecksums) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
adjustCounter
(byte[] key, long amount) Adjust the counter at the given key by the given amount.void
close()
Close this instance.void
put
(byte[] key, byte[] value) Set the value associated with the given key.void
remove
(byte[] key) Remove the key/value pair with the given key, if it exists.void
removeRange
(byte[] minKey, byte[] maxKey) Remove all key/value pairs whose keys are in a given range.Methods inherited from class io.permazen.kv.leveldb.LevelDBKVStore
finalize, get, getDB, getRange, toString
Methods inherited from class io.permazen.kv.AbstractKVStore
decodeCounter, encodeCounter, getAtLeast, getAtMost
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.permazen.kv.KVStore
apply, decodeCounter, encodeCounter, get, getAtLeast, getAtMost, getRange, getRange, getRange, removeRange
-
Constructor Details
-
SnapshotLevelDBKVStore
public SnapshotLevelDBKVStore(org.iq80.leveldb.DB db, boolean verifyChecksums) Constructor.- Parameters:
db
- LevelDB database to snapshotverifyChecksums
- whether to verify checksums on reads- Throws:
NullPointerException
- ifdb
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 underlyingDB
or any associatedWriteBatch
.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceCloseableKVStore
- Overrides:
close
in classLevelDBKVStore
-
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 interfaceKVStore
- Overrides:
put
in classLevelDBKVStore
- Parameters:
key
- keyvalue
- 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 interfaceKVStore
- Overrides:
remove
in classLevelDBKVStore
- 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 tomaxKey
; 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 with0xff
, then no change occurs - If
maxKey
starts with0xff
, then this method behaves as ifmaxKey
were null
- Specified by:
removeRange
in interfaceKVStore
- Overrides:
removeRange
in classAbstractKVStore
- Parameters:
minKey
- minimum key (inclusive), or null for no minimummaxKey
- maximum key (exclusive), or null for no maximum
- If
-
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
, orkey
's value is not a valid counter encoding as would be acceptable todecodeCounter()
, then how this operation affectskey
's value is undefined.- Specified by:
adjustCounter
in interfaceKVStore
- Overrides:
adjustCounter
in classAbstractKVStore
- Parameters:
key
- keyamount
- amount to adjust counter value by
-