|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.journal.Tx
public class Tx
A read-write transaction.
A transaction is a context in which the application can access and perform
operations on fully named indices. Writes on the named indices accessed by
the transaction are accumulated in a IsolatedFusedViews. In order to
commit, the write set of the transaction must be validated against the then
current state of the corresponding unisolated indices and then merge down
onto those indices, applying the specified revisionTime. The
transaction MUST have an exclusive lock on the named indices on which it will
write from the that it begins validation until after the commit or abort of
the transaction. This is necessary in order to ensure that concurrent writers
can not invalidate the conditions under which validation is performed.
The write set of a transaction is written onto a TemporaryRawStore.
Therefore the size limit on the transaction write set is currently 2G, but
the transaction will be buffered in memory until the store exceeds its write
cache size and creates a backing file on the disk. The store is closed and
any backing file is deleted as soon as the transaction completes.
Each IsolatedFusedView is local to a transaction and is backed by the
temporary store for that transaction. This means that concurrent transactions
can execute without synchronization (real concurrency) up to the point where
they #prepare(). We do not need a read-lock on the indices isolated
by the transaction since they are historical states that will not
receive concurrent updates.
IndexSegments and Journals are required
to support the IsolatedFusedViews in use by a Tx. The
easiest way to do this is to name these by appending the transaction
identifier to the name of the index partition, e.g., name#partId#tx. At
that point the StoreManager will automatically track the
resources. This also simplifies access control (write locks) for the
isolated indices as the same WriteExecutorService will serve.
However, with this approach {split, move, join} operations will have to
be either deferred or issued against the isolated index partitions as
well as the unisolated index partitions.
Make writes on the tx thread-safe (Temporary mode Journal rather than TemporaryStore)., Modify the isolated indices use a delegation strategy so that I can trap attempts to access an isolated index once the transaction is no longer active? Define "active" as up to the point where a "commit" or "abort" is _requested_ for the tx. (Alternative, extend the close() model for an index to not permit the re-open of an isolated index after the tx commits and then just close the btree absorbing writes for the isolated index when we are releasing our various resources. The isolated index will thereafter be unusable, which is what we want.)
| Field Summary | |
|---|---|
protected static boolean |
INFO
|
protected static String |
IS_COMPLETE
|
protected AbstractLocalTransactionManager |
localTransactionManager
Used for some handshaking in the commit protocol. |
ReentrantLock |
lock
This Lock is used to obtain exclusive access during certain
operations, including creating the temporary store and isolating a view
of a named index. |
protected static org.apache.log4j.Logger |
log
|
protected static String |
NOT_ACTIVE
|
protected static String |
NOT_COMMITTED
|
protected static String |
NOT_PREPARED
|
protected IResourceManager |
resourceManager
Used to locate the named indices that the transaction isolates. |
protected long |
startTime
The start startTime assigned to this transaction. |
| Fields inherited from interface com.bigdata.journal.ITx |
|---|
READ_COMMITTED, UNISOLATED |
| Constructor Summary | |
|---|---|
Tx(AbstractLocalTransactionManager localTransactionManager,
IResourceManager resourceManager,
long startTime)
Create a transaction reading from the most recent committed state not later than the specified startTime. |
|
| Method Summary | |
|---|---|
boolean |
equals(ITx o)
True iff they are the same object or have the same start timestamp. |
String[] |
getDirtyResource()
Return an array of the resource(s) (the named indices) on which the transaction has written (the isolated index(s) that absorbed the writes for the transaction). |
ILocalBTreeView |
getIndex(String name)
Return a named index. |
long |
getRevisionTime()
The revisionTime assigned to the transaction when it was validated and merged down onto the global state. |
long |
getStartTimestamp()
The start time for the transaction as assigned by a centralized transaction manager service. |
int |
hashCode()
The hash code is based on the getStartTimestamp(). |
boolean |
isAborted()
A transaction is "aborted" iff it has successfully aborted. |
boolean |
isActive()
A transaction is "active" when it is created and remains active until it prepares or aborts. |
boolean |
isCommitted()
A transaction is "committed" iff it has successfully committed. |
boolean |
isComplete()
A transaction is "complete" once has either committed or aborted. |
boolean |
isEmptyWriteSet()
When true, the transaction has an empty write set. |
boolean |
isPrepared()
A transaction is "prepared" once it has been successfully validated and has fulfilled its pre-commit contract for a multi-stage commit protocol. |
protected void |
mergeOntoGlobalState(long revisionTime)
Invoked during commit processing to merge down the write set from each index isolated by this transactions onto the corresponding unisolated index on the database. |
void |
prepare(long revisionTime)
Validate the write set of the named indices isolated transaction and merge down that write set onto the corresponding unisolated indices but DOES NOT commit the data. |
protected void |
releaseResources()
This method must be invoked any time a transaction completes in order to release resources held by that transaction. |
void |
setRunState(RunState newval)
Change the RunState. |
String |
toString()
Returns a string representation of the transaction start time. |
protected boolean |
validateWriteSets()
Invoked when a writable transaction prepares in order to validate its write sets (one per isolated index). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final org.apache.log4j.Logger log
protected static final boolean INFO
protected static final String NOT_ACTIVE
protected static final String NOT_PREPARED
protected static final String NOT_COMMITTED
protected static final String IS_COMPLETE
public final ReentrantLock lock
Lock is used to obtain exclusive access during certain
operations, including creating the temporary store and isolating a view
of a named index. Exclusive access is required since multiple concurrent
operations MAY execute for the same transaction.
Note: This is exposed to the DataService.
protected final AbstractLocalTransactionManager localTransactionManager
protected final IResourceManager resourceManager
protected final long startTime
Note: Transaction startTime and revisionTimes are
assigned by the ITransactionService.
| Constructor Detail |
|---|
public Tx(AbstractLocalTransactionManager localTransactionManager,
IResourceManager resourceManager,
long startTime)
Note: For an IBigdataFederation, a transaction does not start
execution on all IDataServices at the same moment. Instead, the
transaction startTime is assigned by the ITransactionService and
then provided each time an ITx must be created for isolatation of
resources accessible on a IDataService.
transactionManager - The local (client-side) transaction manager.resourceManager - Provides access to named indices that are isolated by the
transaction.startTime - The transaction identifier| Method Detail |
|---|
public long getRevisionTime()
mergeOntoGlobalState(long)public void setRunState(RunState newval)
RunState.
newval - The new RunState.
IllegalArgumentException - if the argument is null.
IllegalStateException - if the state transition is not allowed.RunState.isTransitionAllowed(RunState)public final int hashCode()
getStartTimestamp().
hashCode in class Objectpublic final boolean equals(ITx o)
o - Another transaction object.public final long getStartTimestamp()
ITx
getStartTimestamp in interface ITxpublic final String toString()
toString in class Objectpublic final boolean isActive()
ITx
isActive in interface ITxpublic final boolean isPrepared()
ITx
isPrepared in interface ITxpublic final boolean isComplete()
ITx
isComplete in interface ITxpublic final boolean isCommitted()
ITx
isCommitted in interface ITxpublic final boolean isAborted()
ITx
isAborted in interface ITxpublic void prepare(long revisionTime)
RunState is NOT changed by this
method.
For a single-phase commit the caller MUST hold an exclusive lock on the unisolated indices on which this operation will write.
For a distributed transaction, the caller MUST hold a lock on the
WriteExecutorService for each IDataService on which the
transaction has written.
revisionTime - The revision time assigned by a centralized transaction
manager service -or- ZERO (0L) IFF the transaction is
read-only.
IllegalStateException - if the transaction is not active.
ValidationError - If the transaction can not be validated.
IllegalMonitorStateException - unless the caller holds the lock.protected void releaseResources()
protected boolean validateWriteSets()
protected void mergeOntoGlobalState(long revisionTime)
revisionTime - public ILocalBTreeView getIndex(String name)
getIndex in interface ITxname - The name of the index.
null if no index is registered
under that name.
IllegalStateException - if the transaction is not active.public final boolean isEmptyWriteSet()
ITx
isEmptyWriteSet in interface ITxpublic final String[] getDirtyResource()
ITx
getDirtyResource in interface ITx
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||