Table of Contents
You can execute a sequence of write operations as a single atomic unit so long as all the records that you are operating upon share the same major path components. By atomic unit, we mean all of the operations will execute successfully, or none of them will.
Also, the sequence is performed in isolation. This means that if you have a thread running a particularly long sequence, then another thread cannot intrude on the data in use by the sequence. The second thread will not be able see any of the modifications made by the long-running sequence until the sequence is complete. The second thread also will not be able to modify any of the data in use by the long-running sequence.
Be aware that sequences only support write operations. You can perform store puts and deletes, but you cannot perform store gets when using sequences.
When using a sequence of operations:
All of the keys in use by the sequence must share the same major path components.
Operations are placed into a list, but the operations are not necessarily executed in the order that they appear in the list. Instead, they are executed in an internally defined sequence that prevents deadlocks.
You cannot create two or more operations that operate on the same key. Doing so results in an exception, and the entire operation is aborted.
The rest of this chapter shows how to use
OperationFactory
and KVStore.execute()
to create and run a sequence of operations.
If any operation within the sequence experiences an error, then the entire operation is aborted. In this case, your data is left in the same state it would have been in if the sequence had never been run at all — no matter how much of the sequence was run before the error occurred.
Fundamentally, there are two reasons why a sequence might abort:
An internal operation results in an exception that is
considered a fault. For example, the operation throws a
DurabilityException
, or a
ConsistencyException
. Also, if
there is an internal failure due to message delivery or
a networking error.
An individual operation returns normally but is
unsuccessful as defined by the particular operation.
(For example, you attempt to delete a key that does not
exist). If this occurs AND you specified
true
for the
abortIfUnsuccessful
parameter when
the operation was created using the OperationFactory,
then an
OperationExecutionException
is
thrown. This exception contains information about the
failed operation.