Class IgniteTxManager

    • Constructor Detail

      • IgniteTxManager

        public IgniteTxManager()
    • Method Detail

      • rollbackTransactionsForCache

        public void rollbackTransactionsForCache​(int cacheId)
        Parameters:
        cacheId - Cache ID.
      • rollbackTransactionsForStoppingCache

        public void rollbackTransactionsForStoppingCache​(int cacheToStop)
        Parameters:
        cacheToStop - Cache to stop.
      • rollbackOnTopologyChange

        public void rollbackOnTopologyChange​(AffinityTopologyVersion topVer)
        Rollback transactions blocking partition map exchange.
        Parameters:
        topVer - Initial exchange version.
      • txOwnerDumpRequestsAllowed

        public boolean txOwnerDumpRequestsAllowed()
        Sets if dump requests from local node to near node are allowed, when long-running transaction is found. If allowed, the compute request to near node will be made to get thread dump of transaction owner thread.
        Returns:
        true if allowed, false otherwise.
      • longTransactionTimeDumpThreshold

        public long longTransactionTimeDumpThreshold()
        Threshold timeout for long transactions, if transaction exceeds it, it will be dumped in log with information about how much time did it spent in system time (time while aquiring locks, preparing, commiting, etc) and user time (time when client node runs some code while holding transaction and not waiting it). Equals 0 if not set. No transactions are dumped in log if this parameter is not set.
        Returns:
        Threshold timeout in milliseconds.
      • transactionTimeDumpSamplesCoefficient

        public double transactionTimeDumpSamplesCoefficient()
        The coefficient for samples of completed transactions that will be dumped in log.
      • transactionTimeDumpSamplesPerSecondLimit

        public int transactionTimeDumpSamplesPerSecondLimit()
        The limit of samples of completed transactions that will be dumped in log per second, if transactionTimeDumpSamplesCoefficient() is above 0.0. Must be integer value greater than 0.
      • salvageTx

        public void salvageTx​(IgniteInternalTx tx)
        Invalidates transaction.
        Parameters:
        tx - Transaction.
      • threadMapSize

        public int threadMapSize()
        Returns:
        Thread map size.
      • idMapSize

        public int idMapSize()
        Returns:
        ID map size.
      • completedVersionsSize

        public int completedVersionsSize()
        Returns:
        Committed versions size.
      • newTx

        public GridNearTxLocal newTx​(boolean implicit,
                                     boolean implicitSingle,
                                     @Nullable
                                     @Nullable GridCacheContext sysCacheCtx,
                                     TransactionConcurrency concurrency,
                                     TransactionIsolation isolation,
                                     long timeout,
                                     boolean storeEnabled,
                                     int txSize,
                                     @Nullable
                                     @Nullable String lb)
        Parameters:
        implicit - True if transaction is implicit.
        implicitSingle - Implicit-with-single-key flag.
        concurrency - Concurrency.
        isolation - Isolation.
        timeout - transaction timeout.
        txSize - Expected transaction size.
        lb - Label.
        Returns:
        New transaction.
      • onCreated

        @Nullable
        public <T extends IgniteInternalTx> T onCreated​(@Nullable
                                                        @Nullable GridCacheContext cacheCtx,
                                                        T tx)
        Parameters:
        cacheCtx - Cache context.
        tx - Created transaction.
        Returns:
        Started transaction.
      • finishLocalTxs

        public IgniteInternalFuture<Boolean> finishLocalTxs​(AffinityTopologyVersion topVer)
        Creates a future that will wait for all ongoing transactions that maybe affected by topology update to be finished. This set of transactions include
        Parameters:
        topVer - Topology version.
        Returns:
        Future that will be completed when all ongoing transactions are finished.
      • recoverLocalTxs

        public IgniteInternalFuture<Boolean> recoverLocalTxs​(AffinityTopologyVersion topVer,
                                                             ClusterNode node)
        Creates a future that will wait for all transactions with failed primary recovery.
        Parameters:
        topVer - Topology version.
        node - Failed node.
        Returns:
        Future that will be completed when all affected transactions are recovered.
      • finishAllTxs

        public IgniteInternalFuture<?> finishAllTxs​(IgniteInternalFuture<?> finishLocTxsFut,
                                                    AffinityTopologyVersion topVer)
        Creates a future that will wait for finishing all tx updates on backups after all local transactions are finished. NOTE: As we send finish request to backup nodes after transaction successfully completed on primary node it's important to ensure that all updates from primary to backup are finished or at least remote transaction has created on backup node.
        Parameters:
        finishLocTxsFut - Local transactions finish future.
        topVer - Topology version.
        Returns:
        Future that will be completed when all ongoing transactions are finished.
      • needWaitTransaction

        public boolean needWaitTransaction​(IgniteInternalTx tx,
                                           AffinityTopologyVersion topVer)
        Parameters:
        tx - Transaction.
        topVer - Exchange version.
        Returns:
        True if need wait transaction for exchange.
      • onStarted

        public boolean onStarted​(IgniteInternalTx tx)
        Transaction start callback (has to do with when any operation was performed on this transaction).
        Parameters:
        tx - Started transaction.
        Returns:
        True if transaction is not in completed set.
      • threadLocalTx

        public GridNearTxLocal threadLocalTx​(GridCacheContext cctx)
        Parameters:
        cctx - Cache context.
        Returns:
        Transaction for current thread.
      • tx

        public <T extends IgniteInternalTx> T tx()
        Returns:
        Transaction for current thread.
      • lockedTopologyVersion

        @Nullable
        public @Nullable AffinityTopologyVersion lockedTopologyVersion​(long threadId,
                                                                       IgniteInternalTx ignore)
        Parameters:
        threadId - Thread ID.
        ignore - Transaction to ignore.
        Returns:
        Not null topology version if current thread holds lock preventing topology change.
      • setTxTopologyHint

        public boolean setTxTopologyHint​(@Nullable
                                         @Nullable AffinityTopologyVersion topVer)
        Parameters:
        topVer - Locked topology version.
        Returns:
        True if topology hint was set.
      • userTx

        @Nullable
        public @Nullable GridNearTxLocal userTx()
        Returns:
        User transaction for current thread.
      • inUserTx

        public boolean inUserTx()
        Returns:
        True if current thread is currently within transaction.
      • nearTx

        @Nullable
        public <T extends IgniteInternalTx> T nearTx​(GridCacheVersion txId)
        Parameters:
        txId - Transaction ID.
        Returns:
        Transaction with given ID.
      • peekCompletedVersionsHistory

        public Boolean peekCompletedVersionsHistory​(GridCacheVersion xid)
        Peeks completed versions history map to find out whether transaction was committed or rolled back in the recent past.
        Parameters:
        xid - Transaction XID version.
        Returns:
        true if transaction was committed, false if transaction was rolled back, null if information is missed in history.
      • removeCommittedTx

        public void removeCommittedTx​(IgniteInternalTx tx)
        Parameters:
        tx - Tx to remove.
      • addCommittedTx

        public void addCommittedTx​(IgniteInternalTx tx)
        Parameters:
        tx - Committed transaction.
      • addRolledbackTx

        public boolean addRolledbackTx​(IgniteInternalTx tx)
        Parameters:
        tx - Committed transaction.
        Returns:
        If transaction was not already present in completed set.
      • addCommittedTx

        public boolean addCommittedTx​(IgniteInternalTx tx,
                                      GridCacheVersion xidVer,
                                      @Nullable
                                      @Nullable GridCacheVersion nearXidVer)
        Parameters:
        tx - Tx.
        xidVer - Completed transaction version.
        nearXidVer - Optional near transaction ID.
        Returns:
        If transaction was not already present in completed set.
      • addRolledbackTx

        public boolean addRolledbackTx​(IgniteInternalTx tx,
                                       GridCacheVersion xidVer)
        Parameters:
        tx - Tx.
        xidVer - Completed transaction version.
        Returns:
        If transaction was not already present in completed set.
      • removeTxReturn

        public void removeTxReturn​(GridCacheVersion xidVer)
        Parameters:
        xidVer - xidVer Completed transaction version.
      • rollbackTx

        public void rollbackTx​(IgniteInternalTx tx,
                               boolean clearThreadMap,
                               boolean skipCompletedVers)
        Rolls back a transaction.
        Parameters:
        tx - Transaction to rollback.
        clearThreadMap - True if need remove tx from thread map.
        skipCompletedVers - True if tx should skip adding itself to completed versions map on finish.
      • fastFinishTx

        public void fastFinishTx​(GridNearTxLocal tx,
                                 boolean commit,
                                 boolean clearThreadMap)
        Fast finish transaction. Can be used only if no locks were acquired.
        Parameters:
        tx - Transaction to finish.
        commit - True if transaction is committed, false if rolled back.
        clearThreadMap - True if need remove tx from thread map.
      • clearThreadMap

        public void clearThreadMap​(IgniteInternalTx tx)
        Parameters:
        tx - Transaction to clear.
      • enterNearTxSystemSection

        public void enterNearTxSystemSection()
        Enters system section for thread local near tx, if it is present. In this section system time for this transaction is counted.
      • leaveNearTxSystemSection

        public void leaveNearTxSystemSection()
        Leaves system section for thread local near tx, if it is present.
      • onOwnerChanged

        public boolean onOwnerChanged​(GridCacheEntryEx entry,
                                      GridCacheMvccCandidate owner)
        Callback invoked whenever a member of a transaction acquires lock ownership.
        Parameters:
        entry - Cache entry.
        owner - Candidate that won ownership.
        Returns:
        True if transaction was notified, false otherwise.
      • txContext

        public void txContext​(IgniteInternalTx tx)
        Parameters:
        tx - Committing transaction.
      • resetContext

        public void resetContext()
        Commit ended.
      • slowTxWarnTimeout

        public void slowTxWarnTimeout​(int slowTxWarnTimeout)
        Parameters:
        slowTxWarnTimeout - Slow tx warn timeout.
      • longOperationsDumpTimeout

        public long longOperationsDumpTimeout()
        Returns:
        Long operations dump timeout.
      • longOperationsDumpTimeout

        public void longOperationsDumpTimeout​(long longOpsDumpTimeout)
        Parameters:
        longOpsDumpTimeout - Long operations dump timeout.
      • txsPreparedOrCommitted

        @Nullable
        public @Nullable IgniteInternalFuture<Boolean> txsPreparedOrCommitted​(GridCacheVersion nearVer,
                                                                              int txNum)
        Checks if transactions with given near version ID was prepared or committed.
        Parameters:
        nearVer - Near version ID.
        txNum - Number of transactions.
        Returns:
        Future for flag indicating if transactions were prepared or committed or null for success future.
      • remoteTxFinishFuture

        public IgniteInternalFuture<?> remoteTxFinishFuture​(GridCacheVersion nearVer)
        Parameters:
        nearVer - Near version.
        Returns:
        Finish future for related remote transactions.
      • finishTxOnRecovery

        public void finishTxOnRecovery​(IgniteInternalTx tx,
                                       boolean commit)
        Commits or rolls back prepared transaction.
        Parameters:
        tx - Transaction.
        commit - Whether transaction should be committed or rolled back.
      • commitIfPrepared

        public IgniteInternalFuture<Boolean> commitIfPrepared​(IgniteInternalTx tx,
                                                              Set<UUID> failedNodeIds)
        Commits transaction in case when node started transaction failed, but all related transactions were prepared (invalidates transaction if it is not fully prepared).
        Parameters:
        tx - Transaction.
        failedNodeIds - Failed nodes IDs.
      • deadlockDetectionEnabled

        public boolean deadlockDetectionEnabled()
        Returns:
        True if deadlock detection is enabled.
      • addFuture

        public void addFuture​(org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture fut)
        Parameters:
        fut - Future.
      • future

        @Nullable
        public @Nullable org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture future​(long futId)
        Parameters:
        futId - Future ID.
        Returns:
        Found future.
      • removeFuture

        public void removeFuture​(long futId)
        Parameters:
        futId - Future ID.
      • sendDeferredAckResponse

        public void sendDeferredAckResponse​(UUID nodeId,
                                            GridCacheVersion ver)
        Parameters:
        nodeId - Node ID to send message to.
        ver - Version to ack.
      • deadlockDetectionFutures

        public Collection<IgniteInternalFuture<?>> deadlockDetectionFutures()
        Returns:
        Collection of active transaction deadlock detection futures.
      • setTxTimeoutOnPartitionMapExchange

        public void setTxTimeoutOnPartitionMapExchange​(long timeout)
                                                throws IgniteCheckedException
        Sets transaction timeout on partition map exchange.
        Parameters:
        timeout - Transaction timeout on partition map exchange in milliseconds.
        Throws:
        IgniteCheckedException
      • onTxTimeoutOnPartitionMapExchangeChange

        public void onTxTimeoutOnPartitionMapExchangeChange​(TxTimeoutOnPartitionMapExchangeChangeMessage msg)
        Callback invoked from discovery thread when discovery custom message is received.
        Parameters:
        msg - Discovery message for changing transaction timeout on partition map exchange.
      • processTxTimeoutOnPartitionMapExchangeChange

        public void processTxTimeoutOnPartitionMapExchangeChange​(TxTimeoutOnPartitionMapExchangeChangeMessage msg)
        The task for changing transaction timeout on partition map exchange processed by exchange worker.
        Parameters:
        msg - Message.
      • checkEmptyTransactions

        public void checkEmptyTransactions​(@NotNull
                                           @NotNull IgniteOutClosure<String> errMsgConstructor)
        Method checks that current thread does not have active transactions. If transaction or topology lock is hold by current thread exception IgniteException with given errMsgConstructor message will be thrown.
        Parameters:
        errMsgConstructor - Error message constructor.
      • setTxOwnerDumpRequestsAllowedDistributed

        public void setTxOwnerDumpRequestsAllowedDistributed​(boolean allowed)
        Sets if dump requests from local node to near node are allowed, when long-running transaction is found. If allowed, the compute request to near node will be made to get thread dump of transaction owner thread. Also broadcasts this setting on other server nodes in cluster.
        Parameters:
        allowed - whether allowed
      • longTransactionTimeDumpThresholdDistributed

        public void longTransactionTimeDumpThresholdDistributed​(long threshold)
        Sets threshold timeout in milliseconds for long transactions, if transaction exceeds it, it will be dumped in log with information about how much time did it spent in system time (time while aquiring locks, preparing, commiting, etc.) and user time (time when client node runs some code while holding transaction). Can be set to 0 - no transactions will be dumped in log in this case.
        Parameters:
        threshold - Threshold timeout in milliseconds.
      • transactionTimeDumpSamplesCoefficientDistributed

        public void transactionTimeDumpSamplesCoefficientDistributed​(double coefficient)
        Sets the coefficient for samples of long-running transactions that will be dumped in log, if longTransactionTimeDumpThreshold() is set to non-zero value.
        Parameters:
        coefficient - Coefficient, must be value between 0.0 and 1.0 inclusively.
      • longTransactionTimeDumpSamplesPerSecondLimit

        public void longTransactionTimeDumpSamplesPerSecondLimit​(int limit)
        Sets the limit of samples of completed transactions that will be dumped in log per second, if transactionTimeDumpSamplesCoefficient() is above 0.0. Must be integer value greater than 0.
        Parameters:
        limit - Limit value.
      • longOperationsDumpTimeoutDistributed

        public void longOperationsDumpTimeoutDistributed​(long longOpsDumpTimeout)
        Setting (for all nodes) a timeout (in millis) for printing long-running transactions as well as transactions that cannot receive locks for all their keys for a long time. Set less than or equal 0 to disable.
        Parameters:
        longOpsDumpTimeout - Long operations dump timeout.
      • collisionsDumpIntervalDistributed

        public void collisionsDumpIntervalDistributed​(int collisionsDumpInterval)
        Changes tx key collisions dump interval. For additional info check IgniteSystemProperties.IGNITE_DUMP_TX_COLLISIONS_INTERVAL description.
        Parameters:
        collisionsDumpInterval - New collisions dump interval or negative for disabling.
      • pushCollidingKeysWithQueueSize

        public void pushCollidingKeysWithQueueSize​(GridCacheMapEntry key,
                                                   int queueSize)
        Collect queue size per key collisions info.
        Parameters:
        key - Key.
        queueSize - Collisions queue size
      • detectPossibleCollidingKeys

        public void detectPossibleCollidingKeys​(GridDistributedCacheEntry entry)
        Check local and remote candidates queue size.
        Parameters:
        entry - CacheEntry.
      • onCommitCallback

        public void onCommitCallback​(Consumer<IgniteInternalTx> callback)
        Parameters:
        callback - Callback invoked on transaction commit.
      • collectTxStates

        public void collectTxStates​(TxRecord txRec)
        Collects tx states TransactionState for further correct restoring.
        Parameters:
        txRec - tx Record.
      • uncommitedTx

        public boolean uncommitedTx​(DataEntry dataEntry)
        Parameters:
        dataEntry - Processing entry.
        Returns:
        true If entry contains not completed tx version.
      • clearUncommitedStates

        public void clearUncommitedStates()
        Clears tx states collections.
      • ensureTransactionModeSupported

        public static void ensureTransactionModeSupported​(TransactionIsolation isolation)
        Checks if transaction mode supported for transaction aware queries.
        Parameters:
        isolation - Transaction isolation to check.