Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

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.

AtomicOperation

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

TODO: may have to move durability up from Transaction to AtomicOperation

Built-In Atomic Functions

All built-in atomic functions must be defined at the Server level and can only mutate using the engine recognized primitive operations defined in AtomicOperation.

Revert

Revert key IN record TO timestamp

void revert(String key, long record, long timestamp)

Clear

CLEAR key IN record

//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

//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 v : values){
		operation.remove(key, v, 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 SWAP WITH value2 

//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

GET key AS value in record AND INCREMENT

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?

Number getAndIncrement(String key,long record){
   while(true){
      value = get(key, record);
      if(verifyAndSwap(key, value, record, value + 1){
         return value;
      }
   }
}
  • No labels