Class GammaTxn
- java.lang.Object
-
- org.multiverse.stms.gamma.transactions.GammaTxn
-
- All Implemented Interfaces:
Txn
,MultiverseConstants
,GammaConstants
- Direct Known Subclasses:
FatFixedLengthGammaTxn
,FatMonoGammaTxn
,FatVariableLengthGammaTxn
,LeanFixedLengthGammaTxn
,LeanMonoGammaTxn
public abstract class GammaTxn extends Object implements GammaConstants, Txn
Abstract GammaTxn to be used by all the concrete GammaTxn implementations.- Author:
- Peter Veentjer.
-
-
Field Summary
Fields Modifier and Type Field Description boolean
abortOnly
int
attempt
boolean
commitConflict
GammaTxnConfig
config
boolean
evaluatingCommute
boolean
hasWrites
ArrayList<TxnListener>
listeners
GammaObjectPool
pool
long
remainingTimeoutNs
RetryLatch
retryListener
boolean
richmansMansConflictScan
int
status
int
transactionType
-
Fields inherited from interface org.multiverse.stms.gamma.GammaConstants
FAILURE, MASK_CONFLICT, MASK_SUCCESS, MASK_UNREGISTERED, REGISTRATION_DONE, REGISTRATION_NONE, REGISTRATION_NOT_NEEDED, TRANLOCAL_COMMUTING, TRANLOCAL_CONSTRUCTING, TRANLOCAL_READ, TRANLOCAL_WRITE, TRANSACTIONTYPE_FAT_FIXED_LENGTH, TRANSACTIONTYPE_FAT_MONO, TRANSACTIONTYPE_FAT_VARIABLE_LENGTH, TRANSACTIONTYPE_LEAN_FIXED_LENGTH, TRANSACTIONTYPE_LEAN_MONO, TX_ABORTED, TX_ACTIVE, TX_COMMITTED, TX_PREPARED, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_INT, TYPE_LONG, TYPE_REF, VERSION_UNCOMMITTED
-
Fields inherited from interface org.multiverse.MultiverseConstants
LOCKMODE_EXCLUSIVE, LOCKMODE_NONE, LOCKMODE_READ, LOCKMODE_WRITE, SHAKE_BUGS, SPIN_YIELD, TRACING_ENABLED
-
-
Constructor Summary
Constructors Constructor Description GammaTxn(GammaTxnConfig config, int transactionType)
-
Method Summary
-
-
-
Field Detail
-
pool
public final GammaObjectPool pool
-
status
public int status
-
config
public GammaTxnConfig config
-
attempt
public int attempt
-
remainingTimeoutNs
public long remainingTimeoutNs
-
hasWrites
public boolean hasWrites
-
transactionType
public final int transactionType
-
richmansMansConflictScan
public boolean richmansMansConflictScan
-
abortOnly
public boolean abortOnly
-
retryListener
public final RetryLatch retryListener
-
listeners
public ArrayList<TxnListener> listeners
-
commitConflict
public boolean commitConflict
-
evaluatingCommute
public boolean evaluatingCommute
-
-
Constructor Detail
-
GammaTxn
public GammaTxn(GammaTxnConfig config, int transactionType)
-
-
Method Detail
-
notifyListeners
protected void notifyListeners(TxnEvent event)
-
newRetryError
protected RetryError newRetryError()
-
isLean
public final boolean isLean()
-
abortIfAlive
public final void abortIfAlive()
-
abortPrepareOnAbortOnly
public AbortOnlyException abortPrepareOnAbortOnly()
-
abortCommitOnAbortOnly
public AbortOnlyException abortCommitOnAbortOnly()
-
abortOnReadWriteConflict
public final ReadWriteConflict abortOnReadWriteConflict(GammaObject object)
-
failAbortOnAlreadyCommitted
public DeadTxnException failAbortOnAlreadyCommitted()
-
abortOpenForReadOrWriteOnExplicitLockingDetected
public SpeculativeConfigurationError abortOpenForReadOrWriteOnExplicitLockingDetected(BaseGammaTxnRef ref)
-
abortOpenForReadOnNonRefTypeDetected
public SpeculativeConfigurationError abortOpenForReadOnNonRefTypeDetected(BaseGammaTxnRef ref)
-
abortOpenForReadOnBadStm
public final StmMismatchException abortOpenForReadOnBadStm(GammaObject o)
-
abortOpenForReadOnNullLockMode
public IllegalTxnStateException abortOpenForReadOnNullLockMode(BaseGammaTxnRef object)
-
abortOpenForReadOnBadStatus
public final IllegalTxnStateException abortOpenForReadOnBadStatus(GammaObject object)
-
abortOpenForWriteOnReadonly
public final ReadonlyException abortOpenForWriteOnReadonly(GammaObject object)
-
abortRetryOnNoRetryPossible
public final IllegalTxnStateException abortRetryOnNoRetryPossible()
-
abortRetryOnNoBlockingAllowed
public final RetryNotAllowedException abortRetryOnNoBlockingAllowed()
-
abortRetryOnBadStatus
public final IllegalTxnStateException abortRetryOnBadStatus()
-
abortOpenForConstructionOnBadReference
public final IllegalArgumentException abortOpenForConstructionOnBadReference(GammaObject ref)
-
abortOpenForConstructionOnBadStatus
public final IllegalTxnStateException abortOpenForConstructionOnBadStatus(GammaObject o)
-
abortOpenForConstructionOnBadStm
public final StmMismatchException abortOpenForConstructionOnBadStm(GammaObject o)
-
abortOpenForConstructionOnReadonly
public ReadonlyException abortOpenForConstructionOnReadonly(GammaObject o)
-
abortOpenForConstructionRequired
public SpeculativeConfigurationError abortOpenForConstructionRequired(BaseGammaTxnRef ref)
-
abortCommuteOnCommuteDetected
public SpeculativeConfigurationError abortCommuteOnCommuteDetected(BaseGammaTxnRef ref)
-
abortCommuteOnBadStatus
public IllegalTxnStateException abortCommuteOnBadStatus(GammaObject object, Function function)
-
abortCommuteOnBadStm
public StmMismatchException abortCommuteOnBadStm(GammaObject object)
-
abortCommuteOnReadonly
public ReadonlyException abortCommuteOnReadonly(GammaObject object)
-
abortCommuteOnNullFunction
public NullPointerException abortCommuteOnNullFunction(GammaObject object)
-
abortLocateOnBadStatus
public final IllegalTxnStateException abortLocateOnBadStatus(GammaObject object)
-
abortLocateOnNullArgument
public final NullPointerException abortLocateOnNullArgument()
-
abortRegisterOnListenerRequired
public SpeculativeConfigurationError abortRegisterOnListenerRequired()
-
abortPrepareOnBadStatus
public final IllegalTxnStateException abortPrepareOnBadStatus()
-
abortCommitOnBadStatus
public final IllegalTxnStateException abortCommitOnBadStatus()
-
abortOnOpenForConstructionWhileEvaluatingCommute
public TxnExecutionException abortOnOpenForConstructionWhileEvaluatingCommute(GammaObject o)
-
abortOnOpenForReadWhileEvaluatingCommute
public TxnExecutionException abortOnOpenForReadWhileEvaluatingCommute(GammaObject o)
-
abortOnOpenForCommuteWhileEvaluatingCommute
public TxnExecutionException abortOnOpenForCommuteWhileEvaluatingCommute(GammaObject o)
-
abortEnsureOnBadStatus
public IllegalTxnStateException abortEnsureOnBadStatus(BaseGammaTxnRef o)
-
abortOnTransactionTooSmall
public final SpeculativeConfigurationError abortOnTransactionTooSmall(int minimalSize)
-
abortOnRichmanConflictScanDetected
public final SpeculativeConfigurationError abortOnRichmanConflictScanDetected()
-
abortEnsureOnEnsureDetected
public SpeculativeConfigurationError abortEnsureOnEnsureDetected(GammaObject o)
-
abortAcquireOnNullLockMode
public final NullPointerException abortAcquireOnNullLockMode(GammaObject o)
-
hasWrites
public final boolean hasWrites()
-
commit
public abstract void commit()
Description copied from interface:Txn
Commits this Txn. If the Txn is:- active: it is prepared for commit and then committed
- prepared: it is committed. Once it is prepared, the commit is guaranteed to succeed.
- aborted: a DeadTxnException is thrown
- committed: the call is ignored
Txn will always be aborted if the commit does not succeed.
Commit will not throw a
ReadWriteConflict
after the transaction is prepared. So if prepared successfully, a commit will always succeed.If there are TxnListeners (either normal ones or permanent ones) and they thrown a
RuntimeException
orError
, this will be re-thrown. If a listener fails after the prepare/commit the transaction still is committed.
-
abort
public abstract void abort()
Description copied from interface:Txn
Aborts this Txn. This means that the changes made in this transaction are not committed. It depends on the implementation if this operation is simple (ditching objects for example), or if changes need to be rolled back. If an exception is thrown while executing the abort, the transaction is still aborted. And example of such a situation is a pre-abort task that fails. So the transaction always is aborted (unless it is committed).If the Txn already is aborted, the call is ignored.
-
locate
public abstract Tranlocal locate(BaseGammaTxnRef o)
-
getConfig
public final GammaTxnConfig getConfig()
Description copied from interface:Txn
Returns the TxnConfig used by this Txn.Because the Txn can be reused, the TxnConfig used by this Txn doesn't need to be constant.
-
getAttempt
public final int getAttempt()
Description copied from interface:Txn
Gets the current attempt (so the number of tries this transaction already had). Value will always be equal or larger than 1 (the first attempt returns 1). The maximum number of attempts for retrying is determined based on theTxnConfig.getMaxRetries()
- Specified by:
getAttempt
in interfaceTxn
- Returns:
- the current attempt.
-
getRemainingTimeoutNs
public final long getRemainingTimeoutNs()
Description copied from interface:Txn
Gets the remaining timeout in nanoseconds. Long.MAX_VALUE indicates that no timeout is used.The remaining timeout only is decreased if a transaction blocks on a retry or when doing a backoff.
- Specified by:
getRemainingTimeoutNs
in interfaceTxn
- Returns:
- the remaining timeout.
-
isAbortOnly
public boolean isAbortOnly()
Description copied from interface:Txn
Checks if this Txn is abort only (so will always fail when committing or preparing).This method is not threadsafe, so can only be called by the thread that used the transaction.
- Specified by:
isAbortOnly
in interfaceTxn
- Returns:
- true if abort only, false otherwise.
-
setAbortOnly
public final void setAbortOnly()
Description copied from interface:Txn
Signals that the only possible outcome of the Txn is one that aborts. When the transaction prepares or commits it checks if the transaction is marked as abort only. If so, it will automatically aborted and anAbortOnlyException
is thrown.This method is not threadsafe, so can only be called by the thread that used the transaction.
- Specified by:
setAbortOnly
in interfaceTxn
-
register
public void register(TxnListener listener)
Description copied from interface:Txn
Registers a TxnListener. Every time a transaction is retried, the listener needs to be registered again if you want the task to be executed again. If you want a permanent listener, have a look at theTxnFactoryBuilder.addPermanentListener(org.multiverse.api.lifecycle.TxnListener)
.If a TxnListener is added more than once, it is executed more than once. No checks are made. The permanent listeners are executed in the order they are added.
If a TxnListener throws an Error/RuntimeException and the transaction still is alive, it is aborted. For compensating and deferred actions this is not an issue, but for the PrePrepare state or the state it could since the transaction is aborted.
-
hardReset
public abstract void hardReset()
Does a hard reset of an aborted/committed transaction. This means that it is made ready to be used by another transaction configuration.
-
softReset
public abstract boolean softReset()
Does a soft reset of an aborted/committed transaction. This method is called when the execution of a transaction fails, but needs to be retried again.- Returns:
- if another attempt can be made, false otherwise.
-
getRefTranlocal
public abstract Tranlocal getRefTranlocal(BaseGammaTxnRef ref)
Gets the Tranlocal for a specific AbstractGammaTxnRef. This method doesn't care about the state of a transaction.- Parameters:
ref
- the AbstractGammaTxnRef- Returns:
- the found Tranlocal or null if not found.
-
isAlive
public final boolean isAlive()
-
awaitUpdate
public final void awaitUpdate()
-
copyForSpeculativeFailure
public final void copyForSpeculativeFailure(GammaTxn failingTx)
-
init
public final void init(GammaTxnConfig config)
-
isReadConsistent
public abstract boolean isReadConsistent(Tranlocal justAdded)
-
getStatus
public final TxnStatus getStatus()
Description copied from interface:Txn
Returns the status of this Txn.
-
skipPrepare
public final boolean skipPrepare()
-
initLocalConflictCounter
public abstract void initLocalConflictCounter()
Initializes the local conflict counter if the transaction has a need for it. It should only be initialized if there are no reads.
-
-