...
Code Block |
---|
void revert(String key, long record, long timestamp) |
...
Set
SET key AS value IN record
Code Block |
---|
//NOTE: cannot do automatic retry for this method, so caller must handle that
boolean set(String key, TObject value, long record){
AtomicOperation operation = AtomicOperation.start(store);
Set<TObject> values = operation.fetch(key, record);
for (TObject value : values){
operation.remove(key, value, record);
}
operation.add(key, value, record);
return operation.commit();
} |
Verify And Swap
See http://en.wikipedia.org/wiki/Compare-and-swap
Verify key AS value1 IN record AND SET AS SWAP WITH value2
Code Block |
---|
boolean verifyAndSet//NOTE: cannot do automatic retry for this method, so caller must handle that boolean verifyAndSwap(String key, TObject expected, long record, TObject replacement){ AtomicOperation operation = AtomicOperation.start(store); if(operation.verify(key, expected, record){ operation.remove(key, expected, record); operation.add(key, replacement, record); return operation.commit(); } else{ return false; } } |
Get And Increment
See http://en.wikipedia.org/wiki/Fetch-and-add
...
Warning |
---|
The first value for key in record (get returns the first value of a fetch) must be a Number, otherwise this method should throw an exception. TODO: how to handle floats and doubles? |
Code Block |
---|
Number getAndIncrement(String key,long record) |
...
{
while(true){
value = get(key, record);
if(verifyAndSet(key, value, record, value + 1){
return value;
}
}
} |