fabric.store.db
Class MemoryDB

java.lang.Object
  extended by fabric.store.db.ObjectDB
      extended by fabric.store.db.MemoryDB

public class MemoryDB
extends ObjectDB

An in-memory implementation of the ObjectDB. This class assumes there will be no failures and hopefully will provide very high performance at the cost of no fault tolerance whatsoever. This class does have a simple facility for loading and saving the database to a file.

This class is not thread-safe. Only the TransactionManager should directly interact with this class. The TransactionManager 's thread safety ensures safe usage of this class.


Nested Class Summary
 
Nested classes/interfaces inherited from class fabric.store.db.ObjectDB
ObjectDB.PendingTransaction
 
Field Summary
 
Fields inherited from class fabric.store.db.ObjectDB
name, pendingByTid, rwLocks
 
Constructor Summary
MemoryDB(java.lang.String name)
          Opens the store contained in file "var/storeName" if it exists, or an empty store otherwise.
 
Method Summary
 void close()
          Gracefully shutdown the object database.
 void commit(long tid, RemoteWorker workerNode, NodePrincipal workerPrincipal, SubscriptionManager sm)
          Cause the objects prepared in transaction [tid] to be committed.
 boolean exists(long onum)
          Checks whether an object with the corresponding onum exists, in either prepared or committed form.
 void finishPrepare(long tid, NodePrincipal worker)
           Notifies the database that the given transaction is finished preparing.
protected  boolean isInitialized()
          Determines whether the object database has been initialized.
 long[] newOnums(int num)
           Return a set of onums that aren't currently occupied.
 SerializedObject read(long onum)
          Return the object stored at a particular onum.
 void rollback(long tid, NodePrincipal worker)
          Cause the objects prepared in transaction [tid] to be discarded.
protected  void setInitialized()
          Sets a flag to indicate that the object database has been initialized.
 
Methods inherited from class fabric.store.db.ObjectDB
abortPrepare, beginTransaction, cacheGroupContainer, ensureInit, getCachedGroupContainer, getName, getVersion, isPrepared, isWritten, notifyCommittedUpdate, registerRead, registerUpdate, unpin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryDB

public MemoryDB(java.lang.String name)
Opens the store contained in file "var/storeName" if it exists, or an empty store otherwise.

Parameters:
name - name of store to create database for.
Method Detail

finishPrepare

public void finishPrepare(long tid,
                          NodePrincipal worker)
Description copied from class: ObjectDB

Notifies the database that the given transaction is finished preparing. The transaction is not considered to be prepared until this is called. After calling this method, there should not be any further calls to registerRead() or registerUpdate() for the given transaction. This method MUST be called before calling commit().

Upon receiving this call, the object database should save the prepared transaction to stable storage so that it can be recovered in case of failure.

Specified by:
finishPrepare in class ObjectDB

commit

public void commit(long tid,
                   RemoteWorker workerNode,
                   NodePrincipal workerPrincipal,
                   SubscriptionManager sm)
            throws AccessException
Description copied from class: ObjectDB
Cause the objects prepared in transaction [tid] to be committed. The changes will hereafter be visible to read.

Specified by:
commit in class ObjectDB
Parameters:
tid - the transaction id
workerNode - the remote worker that is performing the commit
workerPrincipal - the principal requesting the commit
Throws:
AccessException - if the principal differs from the caller of prepare()

rollback

public void rollback(long tid,
                     NodePrincipal worker)
              throws AccessException
Description copied from class: ObjectDB
Cause the objects prepared in transaction [tid] to be discarded.

Specified by:
rollback in class ObjectDB
Parameters:
tid - the transaction id
worker - the principal requesting the rollback
Throws:
AccessException - if the principal differs from the caller of prepare()

read

public SerializedObject read(long onum)
Description copied from class: ObjectDB
Return the object stored at a particular onum.

Specified by:
read in class ObjectDB
Parameters:
onum - the identifier
Returns:
the object or null if no object exists at the given onum

exists

public boolean exists(long onum)
Description copied from class: ObjectDB
Checks whether an object with the corresponding onum exists, in either prepared or committed form.

Specified by:
exists in class ObjectDB
Parameters:
onum - the onum of to check
Returns:
true if an object exists for onum

newOnums

public long[] newOnums(int num)
Description copied from class: ObjectDB

Return a set of onums that aren't currently occupied. The ObjectDB may return the same onum more than once from this method, althogh doing so would encourage collisions. There is no assumption of unpredictability or randomness about the returned ids.

The returned onums should be packed in the lower 48 bits. We assume that the object database is never full, and can always provide new onums

Specified by:
newOnums in class ObjectDB
Parameters:
num - the number of onums to return
Returns:
num fresh onums

close

public void close()
           throws java.io.IOException
Description copied from class: ObjectDB
Gracefully shutdown the object database.

Specified by:
close in class ObjectDB
Throws:
java.io.IOException

isInitialized

protected boolean isInitialized()
Description copied from class: ObjectDB
Determines whether the object database has been initialized.

Specified by:
isInitialized in class ObjectDB

setInitialized

protected void setInitialized()
Description copied from class: ObjectDB
Sets a flag to indicate that the object database has been initialized.

Specified by:
setInitialized in class ObjectDB