KeyT
- Table Key Type.ValueT
- Table Value Type.@Beta
public interface KeyValueTable<KeyT,ValueT>
extends java.lang.AutoCloseable
A Key-Value Table is a distributed Key-Value Store that indexes Entries by Keys. It uses Table Segments (non-distributed
Key-Value Store backed by a single Pravega Segment) as the fundamental storage primitive and provides a unified view
of all Table Segments involved. Each TableKey
is hashed to a Table Partition which may be represented by one
or more Table Segments (depending on the Key-Value Table configuration chosen when it was created). Such partitioning
enables the Key-Value Table to be distributed across the Pravega cluster but also introduces some constraints for
certain operations (such as multi-key/entry atomic updates). See below for details.
Key Families are used to group related Keys together in the same Table Partition, which allows multiple keys/entries belonging to the same Key Family to be updated/removed atomically.
Types of Updates:
put(String, Object, Object)
or putAll(String, Iterable)
.
Version
matches the one that
is currently present on the server. Conditional inserts can be performed using putIfAbsent(String, Object, Object)
and will only succeed if the given Key does not already exist in the given Key Family. Conditional updates can be
performed using replace(String, Object, Object, Version)
.
remove(String, Object)
.
Version
matches the one that is currently
present on the server. Such removals can be performed using remove(String, Object, Version)
.
TableEntry.getKey()
TableKey.getVersion()
equals
Version.NOT_EXISTS
), some may be conditioned on specific versions and some may not have condition attached at
all (TableEntry.getKey()
TableKey.getVersion()
equals Version.NO_VERSION
). All the conditions
that are present in the update batch must be satisfied in order for the update batch to be accepted - the condition
checks and updates are performed atomically. Use replaceAll(String, Iterable)
for such an update.
TableKey.getVersion()
equals Version.NO_VERSION
). Although unusual, it is possible to have a removal
conditioned on a Key not existing (TableKey.getVersion()
equals Version.NOT_EXISTS
); such an update
will have no effect on that Key if it doesn't exist but it will prevent the rest of the removals from the same batch
from being applied - this can be used in scenarios where a set of Keys must be removed only if a particular Key is not
present. All the conditions that are present in the removal batch must be satisfied in order for the removal batch to
be accepted - the condition checks and updates are performed atomically. Use removeAll(String, Iterable)
for
such a removal.
Conditional Update Responses:
NoSuchKeyException
: the update or removal has been conditioned on a specific version (different from
Version.NOT_EXISTS
or Version.NO_VERSION
) but the Key does not exist in the KeyValueTable
.
BadKeyVersionException
: the update or removal has been conditioned on a specific version (different from
Version.NO_VERSION
but the Key exists in the KeyValueTable
with a different version.
Modifier and Type | Field and Description |
---|---|
static int |
MAXIMUM_SERIALIZED_KEY_LENGTH
The maximum serialization length of a Table Segment Key.
|
static int |
MAXIMUM_SERIALIZED_VALUE_LENGTH
The maximum serialized length of a Table Segment Value.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the
KeyValueTable . |
io.pravega.common.util.AsyncIterator<IteratorItem<TableEntry<KeyT,ValueT>>> |
entryIterator(@NonNull java.lang.String keyFamily,
int maxEntriesAtOnce,
IteratorState state)
Creates a new Iterator over all the
TableEntry instances in this KeyValueTable that belong to a
specific Key Family. |
java.util.concurrent.CompletableFuture<TableEntry<KeyT,ValueT>> |
get(java.lang.String keyFamily,
KeyT key)
Gets the latest value for the a Key that belong to a specific Key Family.
|
java.util.concurrent.CompletableFuture<java.util.List<TableEntry<KeyT,ValueT>>> |
getAll(java.lang.String keyFamily,
@NonNull java.lang.Iterable<KeyT> keys)
Gets the latest values for a set of Keys that do belong to the same Key Family.
|
KeyValueTableMap<KeyT,ValueT> |
getMapFor(java.lang.String keyFamily)
Exposes this
KeyValueTable instance as a Map . |
io.pravega.common.util.AsyncIterator<IteratorItem<TableKey<KeyT>>> |
keyIterator(@NonNull java.lang.String keyFamily,
int maxKeysAtOnce,
IteratorState state)
Creates a new Iterator over all the
TableKey s in this KeyValueTable that belong to a specific
Key Family. |
java.util.concurrent.CompletableFuture<Version> |
put(java.lang.String keyFamily,
KeyT key,
ValueT value)
Unconditionally inserts a new or updates an existing Entry in the
KeyValueTable . |
java.util.concurrent.CompletableFuture<java.util.List<Version>> |
putAll(@NonNull java.lang.String keyFamily,
@NonNull java.lang.Iterable<java.util.Map.Entry<KeyT,ValueT>> entries)
Unconditionally inserts new or updates existing
TableEntry instances that belong to the same Key Family
into this KeyValueTable . |
java.util.concurrent.CompletableFuture<Version> |
putIfAbsent(java.lang.String keyFamily,
KeyT key,
ValueT value)
Conditionally inserts a new Entry in the
KeyValueTable if the given Key is not already present. |
java.util.concurrent.CompletableFuture<java.lang.Void> |
remove(java.lang.String keyFamily,
KeyT key)
Unconditionally removes a Key from this Table Segment.
|
java.util.concurrent.CompletableFuture<java.lang.Void> |
remove(java.lang.String keyFamily,
KeyT key,
@NonNull Version version)
Conditionally Removes a Key from this Table Segment.
|
java.util.concurrent.CompletableFuture<java.lang.Void> |
removeAll(java.lang.String keyFamily,
@NonNull java.lang.Iterable<TableKey<KeyT>> keys)
Removes one or more
TableKey instances that belong to the same Key Family from this Table Segment. |
java.util.concurrent.CompletableFuture<Version> |
replace(java.lang.String keyFamily,
KeyT key,
ValueT value,
@NonNull Version version)
Conditionally updates an existing Entry in the
KeyValueTable if the given Key exists and its
version matches the given Version . |
java.util.concurrent.CompletableFuture<java.util.List<Version>> |
replaceAll(@NonNull java.lang.String keyFamily,
@NonNull java.lang.Iterable<TableEntry<KeyT,ValueT>> entries)
Inserts new or updates existing
TableEntry instances that belong to the same Key Family into this
KeyValueTable . |
static final int MAXIMUM_SERIALIZED_KEY_LENGTH
static final int MAXIMUM_SERIALIZED_VALUE_LENGTH
java.util.concurrent.CompletableFuture<Version> put(@Nullable java.lang.String keyFamily, @NonNull KeyT key, @NonNull ValueT value)
KeyValueTable
.keyFamily
- (Optional) The Key Family for the Entry. If null, this Entry will not be associated with any
Key Family.key
- The Key to insert or update.value
- The Value to be associated with the Key.Version
associated with the newly
inserted or updated entry.java.util.concurrent.CompletableFuture<Version> putIfAbsent(@Nullable java.lang.String keyFamily, @NonNull KeyT key, @NonNull ValueT value)
KeyValueTable
if the given Key is not already present.keyFamily
- (Optional) The Key Family for the Entry. If null, this Entry will not be associated with any
Key Family.key
- The Key to insert.value
- The Value to be associated with the Key.Version
associated with the newly
inserted or updated entry. Notable exceptions:
ConditionalTableUpdateException
If the Key is already present in the KeyValueTable
for the
provided Key Family.
See the KeyValueTable
doc for more details on Conditional Update Responses.
java.util.concurrent.CompletableFuture<java.util.List<Version>> putAll(@NonNull @NonNull java.lang.String keyFamily, @NonNull @NonNull java.lang.Iterable<java.util.Map.Entry<KeyT,ValueT>> entries)
TableEntry
instances that belong to the same Key Family
into this KeyValueTable
. All changes are performed atomically (either all or none will be accepted).keyFamily
- The Key Family for the all provided Table Entries.entries
- An Iterable
of Map.Entry
instances to insert or update.Version
instances which
represent the versions for the inserted/updated keys. The size of this list will be the same as the number of
items in entries and the versions will be in the same order as the entries.java.util.concurrent.CompletableFuture<Version> replace(@Nullable java.lang.String keyFamily, @NonNull KeyT key, @NonNull ValueT value, @NonNull @NonNull Version version)
KeyValueTable
if the given Key exists and its
version matches the given Version
.keyFamily
- (Optional) The Key Family for the Entry. If null, this Entry will not be associated with any
Key Family.key
- The Key to update.value
- The new Value to be associated with the Key.version
- A Version
representing the version that this Key must have in order to replace it.Version
associated with the
updated entry. Notable exceptions:
ConditionalTableUpdateException
If the Key is not present present in the KeyValueTable
for the
provided Key Family or it is and has a different Version
.
See the KeyValueTable
doc for more details on Conditional Update Responses.
java.util.concurrent.CompletableFuture<java.util.List<Version>> replaceAll(@NonNull @NonNull java.lang.String keyFamily, @NonNull @NonNull java.lang.Iterable<TableEntry<KeyT,ValueT>> entries)
TableEntry
instances that belong to the same Key Family into this
KeyValueTable
. All changes are performed atomically (either all or none will be accepted).keyFamily
- The Key Family for the all provided TableEntry
instances.entries
- An Iterable
of TableEntry
instances to insert or update. If for at least one
such entry, TableEntry.getKey()
TableKey.getVersion()
indicates a conditional
update, this will perform an atomic Conditional Update conditioned on the server-side versions
matching the provided ones (for all TableEntry
instances that have one); otherwise an
Unconditional Update will be performed.
See KeyValueTable
doc for more details on Types of Updates.Version
instances which
represent the versions for the inserted/updated keys. The size of this list will be the same as entries.size()
and the versions will be in the same order as the entries. Notable exceptions:
ConditionalTableUpdateException
If this is a Conditional Update and the condition was not satisfied.
See the KeyValueTable
doc for more details on Conditional Update Responses.
java.util.concurrent.CompletableFuture<java.lang.Void> remove(@Nullable java.lang.String keyFamily, @NonNull KeyT key)
keyFamily
- (Optional) The Key Family for the Key to remove.key
- The Key to remove.java.util.concurrent.CompletableFuture<java.lang.Void> remove(@Nullable java.lang.String keyFamily, @NonNull KeyT key, @NonNull @NonNull Version version)
keyFamily
- (Optional) The Key Family for the Key to remove.key
- The Key to remove.version
- A Version
representing the version that this Key must have in order to remove it.ConditionalTableUpdateException
If this is a Conditional Removal and the condition was not satisfied.
See the KeyValueTable
doc for more details on Conditional Update Responses.
java.util.concurrent.CompletableFuture<java.lang.Void> removeAll(@Nullable java.lang.String keyFamily, @NonNull @NonNull java.lang.Iterable<TableKey<KeyT>> keys)
TableKey
instances that belong to the same Key Family from this Table Segment.
All removals are performed atomically (either all keys or no key will be removed).keyFamily
- The Key Family for the TableKey
.keys
- An Iterable
of keys to remove. If for at least one such key, TableKey.getVersion()
indicates a conditional update, this will perform an atomic Conditional Remove conditioned on the
server-side versions matching the provided ones (for all TableKey
instances that have one);
otherwise an Unconditional Remove will be performed.
See KeyValueTable
doc for more details on Types of Updates.ConditionalTableUpdateException
If this is a Conditional Removal and the condition was not satisfied.
See the KeyValueTable
doc for more details on Conditional Update Responses.
java.util.concurrent.CompletableFuture<TableEntry<KeyT,ValueT>> get(@Nullable java.lang.String keyFamily, @NonNull KeyT key)
keyFamily
- (Optional) The Key Family for the Key to get.key
- The Key to get the value for.java.util.concurrent.CompletableFuture<java.util.List<TableEntry<KeyT,ValueT>>> getAll(@Nullable java.lang.String keyFamily, @NonNull @NonNull java.lang.Iterable<KeyT> keys)
keyFamily
- (Optional) The Key Family for all requested Keys.keys
- An Iterable
of Keys to get values for.TableEntry
instances for the
requested keys. The size of the list will be the same as keys.size() and the results will be in the same order
as the requested keys. Any keys which do not have a value will have a null entry at their index.io.pravega.common.util.AsyncIterator<IteratorItem<TableKey<KeyT>>> keyIterator(@NonNull @NonNull java.lang.String keyFamily, int maxKeysAtOnce, @Nullable IteratorState state)
TableKey
s in this KeyValueTable
that belong to a specific
Key Family.keyFamily
- The Key Family for which to iterate over keys.maxKeysAtOnce
- The maximum number of TableKey
s to return with each call to
AsyncIterator.getNext()
.state
- (Optional) An IteratorState
that represents a continuation token that can be used to
resume a previously interrupted iteration. This can be obtained by invoking
IteratorItem.getState()
. A null value will create an iterator that lists all keys.AsyncIterator
that can be used to iterate over all the Keys in this KeyValueTable
that
belong to a specific Key Family.io.pravega.common.util.AsyncIterator<IteratorItem<TableEntry<KeyT,ValueT>>> entryIterator(@NonNull @NonNull java.lang.String keyFamily, int maxEntriesAtOnce, @Nullable IteratorState state)
TableEntry
instances in this KeyValueTable
that belong to a
specific Key Family.keyFamily
- The Key Family for which to iterate over entries.maxEntriesAtOnce
- The maximum number of TableEntry
instances to return with each call to
AsyncIterator.getNext()
.state
- (Optional) An IteratorState
that represents a continuation token that can be used
to resume a previously interrupted iteration. This can be obtained by invoking
IteratorItem.getState()
. A null value will create an iterator that lists all entries.AsyncIterator
that can be used to iterate over all the Entries in this KeyValueTable
that belong to a specific Key Family.void close()
KeyValueTable
. No more updates, removals, retrievals or iterators may be performed using it.close
in interface java.lang.AutoCloseable
AutoCloseable.close()
KeyValueTableMap<KeyT,ValueT> getMapFor(@Nullable java.lang.String keyFamily)
KeyValueTable
instance as a Map
. Please refer to the KeyValueTableMap
documentation for special cases and limitations.
This is useful for integrating code that expects to deal with a Map
. Not all the KeyValueTable
functionality can be implemented using a Map
, however the Map
interface is fully implemented.
keyFamily
- (Optional) The Key Family to create the KeyValueTableMap
for. Any operations on the
returned KeyValueTableMap
will only affect this Key Family. If no Key Family is
provided (null), then certain KeyValueTableMap
APIs may not be supported. Refer to
KeyValueTableMap
documentation for more details.KeyValueTableMap
instance bound to this KeyValueTable
and Key Family.