Class AbstractKVStore
- All Implemented Interfaces:
KVStore
- Direct Known Subclasses:
ArrayKVStore
,AtomicArrayKVStore
,AtomicKVDatabase
,BerkeleyKVTransaction
,LevelDBKVStore
,LMDBKVStore
,MemoryKVStore
,MutableView
,MVMapKVStore
,ReadOnlySpannerView
,SimpleKVTransaction
,XodusKVStore
KVStore
implementations.
This class provides a partial implementation via the following methods:
- A
get()
implementation based ongetAtLeast()
getAtLeast()
andgetAtMost()
implementations based ongetRange()
.- A
remove()
implementation that delegates toremoveRange()
. - A
removeRange()
implementation that delegates togetRange()
, iterating through the range of keys and removing them one-by-one viaIterator.remove()
. encodeCounter()
,encodeCounter()
, andadjustCounter()
implementations using normal reads and writes of values in big-endian encoding (does not provide any lock-free behavior).- A
put()
implementation throwingUnsupportedOperationException
A read-only KVStore
implementation is possible by implementing only
getRange()
, and a read-write implementation by also
implementing put()
. However, subclasses typically provide more efficient implementations
of the methods listed above.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
adjustCounter
(ByteData key, long amount) Adjust the counter at the given key by the given amount.long
decodeCounter
(ByteData value) Decode a counter value previously encoded byencodeCounter()
.encodeCounter
(long value) Encode a counter value into abyte[]
value suitable for use withdecodeCounter()
and/oradjustCounter()
.Get the value associated with the given key, if any.getAtLeast
(ByteData minKey, ByteData maxKey) Get the key/value pair having the smallest key greater than or equal to the given minimum, if any.Get the key/value pair having the largest key strictly less than the given maximum, if any.void
Set the value associated with the given key.void
Remove the key/value pair with the given key, if it exists.void
removeRange
(ByteData minKey, ByteData maxKey) Remove all key/value pairs whose keys are in a given range.
-
Constructor Details
-
AbstractKVStore
protected AbstractKVStore()
-
-
Method Details
-
get
Description copied from interface:KVStore
Get the value associated with the given key, if any. -
getAtLeast
Description copied from interface:KVStore
Get the key/value pair having the smallest key greater than or equal to the given minimum, if any.An optional (exclusive) maximum key may also be specified; if
maxKey
is null, there is no upper bound; ifmaxKey <= minKey
, null is always returned.If keys starting with
0xff
are not supported by this instance, andminKey
starts with0xff
, then this method returns null.- Specified by:
getAtLeast
in interfaceKVStore
- Parameters:
minKey
- minimum key (inclusive), or null for no minimum (get the smallest key)maxKey
- maximum key (exclusive), or null for no maximum (no upper bound)- Returns:
- smallest key/value pair with
key >= minKey
andkey < maxKey
, or null if none exists
-
getAtMost
Description copied from interface:KVStore
Get the key/value pair having the largest key strictly less than the given maximum, if any.An optional (inclusive) minimum key may also be specified; if
minKey
is null, there is no lower bound (equivalent to a lower bound of the empty byte array); ifminKey >= maxKey
, null is always returned.If keys starting with
0xff
are not supported by this instance, andmaxKey
starts with0xff
, then this method behaves as ifmaxKey
were null.- Specified by:
getAtMost
in interfaceKVStore
- Parameters:
maxKey
- maximum key (exclusive), or null for no maximum (get the largest key)minKey
- minimum key (inclusive), or null for no minimum (no lower bound)- Returns:
- largest key/value pair with
key < maxKey
andkey >= minKey
, or null if none exists
-
put
Description copied from interface:KVStore
Set the value associated with the given key. -
remove
Description copied from interface:KVStore
Remove the key/value pair with the given key, if it exists. -
removeRange
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
- Parameters:
minKey
- minimum key (inclusive), or null for no minimummaxKey
- maximum key (exclusive), or null for no maximum
- If
-
encodeCounter
Description copied from interface:KVStore
Encode a counter value into abyte[]
value suitable for use withdecodeCounter()
and/oradjustCounter()
.- Specified by:
encodeCounter
in interfaceKVStore
- Parameters:
value
- desired counter value- Returns:
- encoded counter value
-
decodeCounter
Description copied from interface:KVStore
Decode a counter value previously encoded byencodeCounter()
.- Specified by:
decodeCounter
in interfaceKVStore
- Parameters:
value
- encoded counter value- Returns:
- decoded counter value
-
adjustCounter
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
- Parameters:
key
- keyamount
- amount to adjust counter value by
-