K
- the key typeV
- the value typepublic interface ReadOnlyKeyValueStore<K,V>
Please note that this contract defines the thread-safe read functionality only; it does not guarantee anything about whether the actual instance is writable by another thread, or whether it uses some locking mechanism under the hood. For this reason, making dependencies between the read and write operations on different StateStore instances can cause concurrency problems like deadlock.
Modifier and Type | Method and Description |
---|---|
KeyValueIterator<K,V> |
all()
Return an iterator over all keys in this store.
|
long |
approximateNumEntries()
Return an approximate count of key-value mappings in this store.
|
V |
get(K key)
Get the value corresponding to this key.
|
default <PS extends Serializer<P>,P> |
prefixScan(P prefix,
PS prefixKeySerializer)
Return an iterator over all keys with the specified prefix.
|
KeyValueIterator<K,V> |
range(K from,
K to)
Get an iterator over a given range of keys.
|
default KeyValueIterator<K,V> |
reverseAll()
Return a reverse iterator over all keys in this store.
|
default KeyValueIterator<K,V> |
reverseRange(K from,
K to)
Get a reverse iterator over a given range of keys.
|
V get(K key)
key
- The key to fetchNullPointerException
- If null is used for key.InvalidStateStoreException
- if the store is not initializedKeyValueIterator<K,V> range(K from, K to)
ConcurrentModificationException
s
and must not return null values.
Order is based on the serialized byte[] of the keys, not the 'logical' key order.from
- The first key that could be in the range, where iteration starts from.
A null value indicates that the range starts with the first element in the store.to
- The last key that could be in the range, where iteration ends.
A null value indicates that the range ends with the last element in the store.InvalidStateStoreException
- if the store is not initializeddefault KeyValueIterator<K,V> reverseRange(K from, K to)
ConcurrentModificationException
s
and must not return null values.
Order is based on the serialized byte[] of the keys, not the 'logical' key order.from
- The first key that could be in the range, where iteration ends.
A null value indicates that the range starts with the first element in the store.to
- The last key that could be in the range, where iteration starts from.
A null value indicates that the range ends with the last element in the store.InvalidStateStoreException
- if the store is not initializedKeyValueIterator<K,V> all()
ConcurrentModificationException
s
and must not return null values.
Order is not guaranteed as bytes lexicographical ordering might not represent key order.InvalidStateStoreException
- if the store is not initializeddefault KeyValueIterator<K,V> reverseAll()
ConcurrentModificationException
s
and must not return null values.
Order is not guaranteed as bytes lexicographical ordering might not represent key order.InvalidStateStoreException
- if the store is not initializeddefault <PS extends Serializer<P>,P> KeyValueIterator<K,V> prefixScan(P prefix, PS prefixKeySerializer)
ConcurrentModificationException
s
and must not return null values.
Since prefixScan()
relies on byte lexicographical ordering and not on the ordering of the key type, results for some types might be unexpected.
For example, if the key type is Integer
, and the store contains keys [1, 2, 11, 13],
then running store.prefixScan(1, new IntegerSerializer())
will return [1] and not [1,11,13].
In contrast, if the key type is String
the keys will be sorted [1, 11, 13, 2] in the store and store.prefixScan(1, new StringSerializer())
will return [1,11,13].
In both cases prefixScan()
starts the scan at 1 and stops at 2.PS
- Prefix Serializer typeP
- Prefix Type.prefix
- The prefix.prefixKeySerializer
- Serializer for the Prefix key typeInvalidStateStoreException
- if the store is not initializedlong approximateNumEntries()
The count is not guaranteed to be exact in order to accommodate stores where an exact count is expensive to calculate.
InvalidStateStoreException
- if the store is not initialized