public class Tx extends Object implements ITx
A 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 IsolatedFusedView
s. 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.
Modifier and Type | Field and Description |
---|---|
protected static String |
IS_COMPLETE |
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 String |
NOT_ACTIVE |
protected static String |
NOT_COMMITTED |
protected static String |
NOT_PREPARED |
READ_COMMITTED, UNISOLATED
Constructor and Description |
---|
Tx(AbstractLocalTransactionManager localTransactionManager,
IResourceManager resourceManager,
long startTime,
long readsOnCommitTime)
Create a transaction reading from the most recent committed state not
later than the specified startTime.
|
Modifier and Type | Method and Description |
---|---|
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 |
getReadsOnCommitTime()
The timestamp of the commit point against which this transaction is
reading.
|
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.
|
boolean |
isReadOnly()
Return
true iff this is a read-only transaction. |
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.
|
boolean |
validateWriteSets()
Invoked when a writable transaction prepares in order to validate its
write sets (one per isolated index).
|
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
.
public Tx(AbstractLocalTransactionManager localTransactionManager, IResourceManager resourceManager, long startTime, long readsOnCommitTime)
Note: For an IBigdataFederation
, a transaction does not start
execution on all IDataService
s 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 identifierreadsOnCommitTime
- The timestamp of the commit point against which this
transaction is reading.public long getRevisionTime()
mergeOntoGlobalState(long)
public long getReadsOnCommitTime()
ITxState0
Note: This is not currently available on a cluster. In that context, we
wind up with the same timestamp for #startTime
and
#readsOnCommitTime
which causes cache pollution for things which
cache based on #readsOnCommitTime
.
getReadsOnCommitTime
in interface ITxState0
public boolean isReadOnly()
ITxState
true
iff this is a read-only transaction.isReadOnly
in interface ITxState
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()
.public final boolean equals(ITx o)
o
- Another transaction object.public final long getStartTimestamp()
ITxState0
getStartTimestamp
in interface ITxState0
TODO Rename since the sign indicates read-only vs read-write and
hence it can not be directly interpreted as a commitTime? (e.g.,
getTxId()).
public final String toString()
public final boolean isActive()
Note: The value is valid as of the instant that the run state is inspected. The caller must hold a lock if they want to act based on non-final run states.
public final boolean isPrepared()
Note: This is a transient state. Once the transaction has prepared it
will transition to either COMMIT or ABORT and this method will no longer
report true
.
Note: The value is valid as of the instant that the run state is inspected. The caller must hold a lock if they want to act based on non-final run states.
isPrepared
in interface ITxState
public final boolean isComplete()
Note: The value is valid as of the instant that the run state is inspected. The caller must hold a lock if they want to act based on non-final run states.
isComplete
in interface ITxState
public final boolean isCommitted()
Note: The value is valid as of the instant that the run state is inspected. The caller must hold a lock if they want to act based on non-final run states.
isCommitted
in interface ITxState
public final boolean isAborted()
Note: The value is valid as of the instant that the run state is inspected. The caller must hold a lock if they want to act based on non-final run states.
public 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
.UnsupportedOperationException
- if the transaction is read-only.protected void releaseResources()
public boolean validateWriteSets()
protected void mergeOntoGlobalState(long revisionTime)
revisionTime
- public ILocalBTreeView getIndex(String name)
getIndex
in interface ITx
name
- 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 ITx
public final String[] getDirtyResource()
ITx
getDirtyResource
in interface ITx
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.