Operations on a Tuple in a Space
Put operations always overwrite (and return) whatever was stored before them in the space. But when more than one application updates the same data concurrently, it can be necessary to use “compare and set” type operations.
ActiveSpaces has two compare and set operations:
- compareAndPut
- This is a conditional put operation to atomically change the values associated with a key from one value to another (or fail). It takes an old tuple, and a new tuple as inputs, and returns the current tuple (meaning the new tuple if the compare was a success and the current value stored in the space otherwise). You can pass NULL as an old tuple if you want to make sure your put is an insert rather than an overwrite.
ActiveSpace has two update operations:
- updateByKey
- This operation takes the key and the values as arguments. If the key is not present in the space, an error would be returned. On success, the previously stored tuple is returned.
- updateTuples
- This operations takes a SQL like update statement and applies that on all the matching tuples. The following statement would change the value field to new_change on meeting the criterion, key < 10. For example, set value = 'new_change' where key < 10.
For an example of code that works with tuples, see the documentation on the ASOperations example (ASOperations).
Copyright © Cloud Software Group, Inc. All rights reserved.