Table of Contents |
---|
Introduction
The Engine defines primitive operations to concurrently access/modify data while maintaining consistency. Since it is desirable to build more complex routines from these operations (while also maintaining consistency in concurrent environments), we must build an AtomicOperation protocol at the Engine level, which ConcourseServer can use to safely provide complex routines to the client.
The AtomicOperation Protocol
- AtomicOperation is a BufferedStore that transports to the Engine (or a Transaction)
- AtomicOperation uses just in time locking so it never block other operations before it goes to commit
- When committing, AtomicOperation grabs locks to create a fence around the resources on which it will operate. It does not release these locks until it is done committing
- AtomicOperation listens for version changes to the resources that it intends to lock. If it is notified about a version change it fails immediately.
Note |
---|
TODO: may have to move durability up from Transaction to AtomicOperation |
Atomic Operations Built Into ConcourseServer
ConcourseServer uses the AtomicOperation protocol to build out more complex routines
Revert
Revert key IN record TO timestamp
Code Block |
---|
void revert(String key, long record, long timestamp) |
Clear
CLEAR key IN record
Code Block |
---|
//NOTE: cannot do automatic retry for this method, so caller must handle that boolean clear(String key, long record){ AtomicOperation operation = AtomicOperation.start(store); Set<TObject> values = operation.fetch(key, record); for (TObject value : values){ operation.remove(key, value, record); } return operation.commit(); } |
Set
SET key AS value IN record
Code Block |
---|
//NOTE: cannot do automatic retry for this method, so caller must handle that //NOTE: CANNOT use the clear() method but must do removes in terms of the atomic operation!! boolean set(String key, TObject value, long record){ AtomicOperation operation = AtomicOperation.start(store); Set<TObject> values = operation.fetch(key, record); for (TObject valuev : values){ operation.remove(key, valuev, record); } operation.add(key, value, record); return operation.commit(); } |
...
Code Block |
---|
Number getAndIncrement(String key,long record){ while(true){ value = get(key, record); if(verifyAndSetverifyAndSwap(key, value, record, value + 1){ return value; } } } |