public class SnapshotRocksDBKVStore extends RocksDBKVStore implements CloseableKVStore
KVStore
view of a RocksDB 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 and Description |
---|
SnapshotRocksDBKVStore(org.rocksdb.RocksDB db)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
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.
|
decodeCounter, encodeCounter, finalize, get, getDB, getRange, toString
getAtLeast, getAtMost
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
apply, decodeCounter, encodeCounter, get, getAtLeast, getAtMost, getRange, getRange, getRange, removeRange
public SnapshotRocksDBKVStore(org.rocksdb.RocksDB db)
db
- RocksDB database to snapshotNullPointerException
- if db
is nullpublic void close()
RocksDBKVStore
This closes any unclosed iterators returned from getRange()
.
This does not close the underlying RocksDB
or any associated WriteBatch
.
close
in interface CloseableKVStore
close
in interface Closeable
close
in interface AutoCloseable
close
in class RocksDBKVStore
public void put(byte[] key, byte[] value)
KVStore
put
in interface KVStore
put
in class RocksDBKVStore
key
- keyvalue
- valuepublic void remove(byte[] key)
KVStore
remove
in interface KVStore
remove
in class RocksDBKVStore
key
- keypublic void removeRange(byte[] minKey, byte[] maxKey)
KVStore
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:
minKey
starts with 0xff
, then no change occursmaxKey
starts with 0xff
, then this method behaves as if maxKey
were nullremoveRange
in interface KVStore
removeRange
in class AbstractKVStore
minKey
- minimum key (inclusive), or null for no minimummaxKey
- maximum key (exclusive), or null for no maximumpublic void adjustCounter(byte[] key, long amount)
KVStore
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.
adjustCounter
in interface KVStore
adjustCounter
in class RocksDBKVStore
key
- keyamount
- amount to adjust counter value byCopyright © 2022. All rights reserved.