Class GammaTxn

    • Field Detail

      • status

        public int status
      • 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
      • 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()
      • failAbortOnAlreadyCommitted

        public DeadTxnException failAbortOnAlreadyCommitted()
      • hasWrites

        public final boolean hasWrites()
      • commit

        public abstract void commit()
        Description copied from interface: Txn
        Commits this Txn. If the Txn is:
        1. active: it is prepared for commit and then committed
        2. prepared: it is committed. Once it is prepared, the commit is guaranteed to succeed.
        3. aborted: a DeadTxnException is thrown
        4. 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 or Error, this will be re-thrown. If a listener fails after the prepare/commit the transaction still is committed.

        Specified by:
        commit in interface Txn
      • 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.

        Specified by:
        abort in interface Txn
      • 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.

        Specified by:
        getConfig in interface Txn
        Returns:
        the TxnConfig.
      • 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 the TxnConfig.getMaxRetries()
        Specified by:
        getAttempt in interface Txn
        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 interface Txn
        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 interface Txn
        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 an AbortOnlyException is thrown.

        This method is not threadsafe, so can only be called by the thread that used the transaction.

        Specified by:
        setAbortOnly in interface Txn
      • 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 the TxnFactoryBuilder.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.

        Specified by:
        register in interface Txn
        Parameters:
        listener - the listener to add.
      • 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)
      • isReadConsistent

        public abstract boolean isReadConsistent​(Tranlocal justAdded)
      • getStatus

        public final TxnStatus getStatus()
        Description copied from interface: Txn
        Returns the status of this Txn.
        Specified by:
        getStatus in 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.