Class GammaTxn
- All Implemented Interfaces:
Txn
,MultiverseConstants
,GammaConstants
- Direct Known Subclasses:
FatFixedLengthGammaTxn
,FatMonoGammaTxn
,FatVariableLengthGammaTxn
,LeanFixedLengthGammaTxn
,LeanMonoGammaTxn
-
Field Summary
FieldsModifier and TypeFieldDescriptionboolean
int
boolean
boolean
boolean
final GammaObjectPool
long
final RetryLatch
boolean
int
final int
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 -
Method Summary
Modifier and TypeMethodDescriptionabstract void
abort()
Aborts this Txn.final NullPointerException
final IllegalTxnStateException
abortCommuteOnBadStatus
(GammaObject object, Function function) abortCommuteOnBadStm
(GammaObject object) abortCommuteOnReadonly
(GammaObject object) final void
final IllegalTxnStateException
abortLocateOnBadStatus
(GammaObject object) final NullPointerException
final ReadWriteConflict
abortOnReadWriteConflict
(GammaObject object) abortOnTransactionTooSmall
(int minimalSize) final IllegalArgumentException
final IllegalTxnStateException
final StmMismatchException
final IllegalTxnStateException
final StmMismatchException
final ReadonlyException
final IllegalTxnStateException
private IllegalTxnStateException
private NullPointerException
final IllegalTxnStateException
final RetryNotAllowedException
final IllegalTxnStateException
final void
abstract void
commit()
Commits this Txn.final void
copyForSpeculativeFailure
(GammaTxn failingTx) final int
Gets the current attempt (so the number of tries this transaction already had).final GammaTxnConfig
Returns the TxnConfig used by this Txn.abstract Tranlocal
Gets the Tranlocal for a specific AbstractGammaTxnRef.final long
Gets the remaining timeout in nanoseconds.final TxnStatus
Returns the status of this Txn.abstract void
Does a hard reset of an aborted/committed transaction.final boolean
final void
init
(GammaTxnConfig config) abstract void
Initializes the local conflict counter if the transaction has a need for it.boolean
Checks if this Txn is abort only (so will always fail when committing or preparing).final boolean
isAlive()
final boolean
isLean()
abstract boolean
isReadConsistent
(Tranlocal justAdded) abstract Tranlocal
protected RetryError
protected void
notifyListeners
(TxnEvent event) void
register
(TxnListener listener) Registers a TxnListener.final void
Signals that the only possible outcome of the Txn is one that aborts.final boolean
abstract boolean
Does a soft reset of an aborted/committed transaction.
-
Field Details
-
pool
-
status
public int status -
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
-
listeners
-
commitConflict
public boolean commitConflict -
evaluatingCommute
public boolean evaluatingCommute
-
-
Constructor Details
-
GammaTxn
-
-
Method Details
-
notifyListeners
-
newRetryError
-
isLean
public final boolean isLean() -
abortIfAlive
public final void abortIfAlive() -
abortPrepareOnAbortOnly
-
abortCommitOnAbortOnly
-
abortOnReadWriteConflict
-
failAbortOnAlreadyCommitted
-
abortOpenForReadOrWriteOnExplicitLockingDetected
public SpeculativeConfigurationError abortOpenForReadOrWriteOnExplicitLockingDetected(BaseGammaTxnRef ref) -
abortOpenForReadOnNonRefTypeDetected
-
abortOpenForReadOnBadStm
-
abortOpenForReadOnNullLockMode
-
abortOpenForReadOnBadStatus
-
abortOpenForWriteOnReadonly
-
abortRetryOnNoRetryPossible
-
abortRetryOnNoBlockingAllowed
-
abortRetryOnBadStatus
-
abortOpenForConstructionOnBadReference
-
abortOpenForConstructionOnBadStatus
-
abortOpenForConstructionOnBadStm
-
abortOpenForConstructionOnReadonly
-
abortOpenForConstructionRequired
-
abortCommuteOnCommuteDetected
-
abortCommuteOnBadStatus
-
abortCommuteOnBadStm
-
abortCommuteOnReadonly
-
abortCommuteOnNullFunction
-
abortLocateOnBadStatus
-
abortLocateOnNullArgument
-
abortRegisterOnNullListener
-
abortRegisterOnBadStatus
-
abortRegisterOnListenerRequired
-
abortPrepareOnBadStatus
-
abortCommitOnBadStatus
-
abortOnOpenForConstructionWhileEvaluatingCommute
-
abortOnOpenForReadWhileEvaluatingCommute
-
abortOnOpenForCommuteWhileEvaluatingCommute
-
abortEnsureOnBadStatus
-
abortOnTransactionTooSmall
-
abortOnRichmanConflictScanDetected
-
abortEnsureOnEnsureDetected
-
abortAcquireOnNullLockMode
-
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
-
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
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
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
-
init
-
isReadConsistent
-
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.
-