Chapter 13. Executing a Sequence of Operations

Table of Contents

Sequence Errors
Creating a Sequence
Executing a Sequence

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:

The rest of this chapter shows how to use OperationFactory and KVStore.execute() to create and run a sequence of operations.

Sequence Errors

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:

  1. 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.

  2. 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.