org.apache.ignite.internal.processors.cache.transactions

## Class IgniteTxManager

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter
  - - org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager

All Implemented Interfaces:
  GridCacheSharedManager

    public class IgniteTxManager
    extends GridCacheSharedManagerAdapter

Cache transaction manager.

### Field Summary

Fields
`static int` `DEFERRED_ONE_PHASE_COMMIT_ACK_REQUEST_TIMEOUT` One phase commit deferred ack request timeout.

### Fields inherited from class org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter

`cctx, diagnosticLog, log`

### Constructor Summary

Constructors
Constructor and Description
`IgniteTxManager()`

### Method Summary

All Methods Instance Methods Concrete Methods
`Collection<IgniteInternalTx>` `activeTransactions()`
`void` `addAlternateVersion(GridCacheVersion ver, IgniteInternalTx tx)`
`void` `addCommittedTx(IgniteInternalTx tx)`
`boolean` `addCommittedTx(IgniteInternalTx tx, GridCacheVersion xidVer, GridCacheVersion nearXidVer)`
`void` `addCommittedTxReturn(IgniteInternalTx tx, GridCacheReturnCompletableWrapper ret)`
`void` `addFuture(org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture fut)`
`boolean` `addRolledbackTx(IgniteInternalTx tx)`
`boolean` `addRolledbackTx(IgniteInternalTx tx, GridCacheVersion xidVer)`
`IgniteInternalFuture<?>` `awaitFinishAckAsync(UUID rmtNodeId, long threadId)` Asynchronously waits for last finish request ack.
`void` `beforeFinishRemote(UUID rmtNodeId, long threadId)` Callback called by near finish future before sending near finish request to remote node.
`void` `clearThreadMap(IgniteInternalTx tx)`
`void` `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).
`void` `commitTx(IgniteInternalTx tx)` Commits a transaction.
`int` `completedVersionsSize()`
`boolean` `deadlockDetectionEnabled()`
`Collection<IgniteInternalFuture<?>>` `deadlockDetectionFutures()`
`IgniteInternalFuture<TxDeadlock>` `detectDeadlock(IgniteInternalTx tx, Set<IgniteTxKey> keys)` Performs deadlock detection for given keys.
`void` `fastFinishTx(GridNearTxLocal tx, boolean commit, boolean clearThreadMap)` Fast finish transaction.
`IgniteInternalFuture<?>` `finishAllTxs(IgniteInternalFuture<?> finishLocalTxsFuture, AffinityTopologyVersion topVer)` Creates a future that will wait for finishing all tx updates on backups after all local transactions are finished.
`IgniteInternalFuture<Boolean>` `finishLocalTxs(AffinityTopologyVersion topVer)` Creates a future that will wait for all ongoing transactions that maybe affected by topology update to be finished.
`void` `finishSyncDisabled(boolean finishSyncDisabled)` For test purposes only.
`void` `finishTxOnRecovery(IgniteInternalTx tx, boolean commit)` Commits or rolls back prepared transaction.
`org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture` `future(long futId)`
`GridCacheReturnCompletableWrapper` `getCommittedTxReturn(GridCacheVersion xidVer)`
`int` `idMapSize()`
`boolean` `inUserTx()`
`IgniteTxLocalAdapter` `localTx()`
`AffinityTopologyVersion` `lockedTopologyVersion(long threadId, IgniteInternalTx ignore)`
`boolean` `logTxRecords()`
`GridCacheVersion` `mappedVersion(GridCacheVersion from)`
`<T extends IgniteInternalTx> T` `nearTx(GridCacheVersion txId)`
`boolean` `needWaitTransaction(IgniteInternalTx tx, AffinityTopologyVersion topVer)`
`GridNearTxLocal` `newTx(boolean implicit, boolean implicitSingle, GridCacheContext sysCacheCtx, TransactionConcurrency concurrency, TransactionIsolation isolation, long timeout, boolean storeEnabled, int txSize, String lb)`
`<T extends IgniteInternalTx> T` `onCreated(GridCacheContext cacheCtx, T tx)`
`void` `onDisconnected(IgniteFuture reconnectFut)`
`void` `onFinishedRemote(UUID rmtNodeId, long threadId)` Callback invoked when near finish response is received from remote node.
`protected void` `onKernalStop0(boolean cancel)`
`boolean` `onOwnerChanged(GridCacheEntryEx entry, GridCacheMvccCandidate owner)` Callback invoked whenever a member of a transaction acquires lock ownership.
`boolean` `onStarted(IgniteInternalTx tx)` Transaction start callback (has to do with when any operation was performed on this transaction).
`void` `prepareTx(IgniteInternalTx tx, Collection<IgniteTxEntry> entries)` Handles prepare stage.
`void` `printMemoryStats()` Prints out memory stats to standard out.
`IgniteInternalFuture<?>` `remoteTxFinishFuture(GridCacheVersion nearVer)`
`void` `removeCommittedTx(IgniteInternalTx tx)`
`void` `removeFuture(long futId)`
`void` `removeTxReturn(GridCacheVersion xidVer)`
`void` `resetContext()` Commit ended.
`void` `resumeTx(GridNearTxLocal tx, long threadId)` Resume transaction in current thread.
`void` `rollbackOnTopologyChange(AffinityTopologyVersion topVer)` Rollback transactions blocking partition map exchange.
`void` `rollbackTransactionsForCache(int cacheId)`
`void` `rollbackTx(IgniteInternalTx tx, boolean clearThreadMap, boolean skipCompletedVers)` Rolls back a transaction.
`void` `salvageTx(IgniteInternalTx tx)` Invalidates transaction.
`void` `sendDeferredAckResponse(UUID nodeId, GridCacheVersion ver)`
`boolean` `setTxTopologyHint(AffinityTopologyVersion topVer)`
`int` `slowTxWarnTimeout()`
`void` `slowTxWarnTimeout(int slowTxWarnTimeout)`
`protected void` `start0()`
`void` `suspendTx(GridNearTxLocal tx)` Suspends transaction.
`GridNearTxLocal` `threadLocalTx(GridCacheContext cctx)`
`int` `threadMapSize()`
`<T> T` `tx()`
`<T extends IgniteInternalTx> T` `tx(GridCacheVersion txId)`
`IgniteInternalFuture<Boolean>` `txCommitted(GridCacheVersion xidVer)`
`void` `txContext(IgniteInternalTx tx)`
`GridCacheVersion` `txContextVersion()` Gets version of transaction in tx context or `null` if tx context is empty.
`IgniteTxHandler` `txHandler()`
`IgniteInternalFuture<Boolean>` `txsPreparedOrCommitted(GridCacheVersion nearVer, int txNum)` Checks if transactions with given near version ID was prepared or committed.
`GridNearTxLocal` `userTx()`
`IgnitePair<Collection<GridCacheVersion>>` `versions(GridCacheVersion min)`

### Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter

`context, isStopping, kernalStartInfo, kernalStopInfo, log, onKernalStop, onReconnected, start, startInfo, stop, stop0, stopInfo, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### DEFERRED_ONE_PHASE_COMMIT_ACK_REQUEST_TIMEOUT

    public static final int DEFERRED_ONE_PHASE_COMMIT_ACK_REQUEST_TIMEOUT

One phase commit deferred ack request timeout.

### Constructor Detail

#### IgniteTxManager

    public IgniteTxManager()

### Method Detail

#### onKernalStop0

    protected void onKernalStop0(boolean cancel)

Overrides:
  `onKernalStop0` in class `GridCacheSharedManagerAdapter`
Parameters:
  `cancel` - Cancel flag.

#### start0

    protected void start0()
                   throws IgniteCheckedException

Overrides:
  `start0` in class `GridCacheSharedManagerAdapter`
Throws:
  `IgniteCheckedException` - If failed.

#### rollbackTransactionsForCache

    public void rollbackTransactionsForCache(int cacheId)

Parameters:
  `cacheId` - Cache ID.

#### rollbackOnTopologyChange

    public void rollbackOnTopologyChange(AffinityTopologyVersion topVer)

Rollback transactions blocking partition map exchange.

Parameters:
  `topVer` - Initial exchange version.

#### onDisconnected

    public void onDisconnected(IgniteFuture reconnectFut)

Specified by:
  `onDisconnected` in interface `GridCacheSharedManager`
Overrides:
  `onDisconnected` in class `GridCacheSharedManagerAdapter`
Parameters:
  `reconnectFut` - Reconnect future.

#### txHandler

    public IgniteTxHandler txHandler()

Returns:
  TX handler.

#### salvageTx

    public void salvageTx(IgniteInternalTx tx)

Invalidates transaction.

Parameters:
  `tx` - Transaction.

#### printMemoryStats

    public void printMemoryStats()

Prints out memory stats to standard out.

USE ONLY FOR MEMORY PROFILING DURING TESTS.

Specified by:
  `printMemoryStats` in interface `GridCacheSharedManager`
Overrides:
  `printMemoryStats` in class `GridCacheSharedManagerAdapter`

#### 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
                                 GridCacheContext sysCacheCtx,
                                 TransactionConcurrency concurrency,
                                 TransactionIsolation isolation,
                                 long timeout,
                                 boolean storeEnabled,
                                 int txSize,
                                 @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
                                                              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

All `TransactionConcurrency.PESSIMISTIC` transactions with topology version less or equal to `topVer`.
`TransactionConcurrency.OPTIMISTIC` transactions in PREPARING state with topology version less or equal to `topVer` and having transaction key with entry that belongs to one of partitions in `parts`.

Parameters:
  `topVer` - Topology version.
Returns:
  Future that will be completed when all ongoing transactions are finished.

#### finishAllTxs

    public IgniteInternalFuture<?> finishAllTxs(IgniteInternalFuture<?> finishLocalTxsFuture,
                                                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:
  `finishLocalTxsFuture` - 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.

#### mappedVersion

    public GridCacheVersion mappedVersion(GridCacheVersion from)

Parameters:
  `from` - Near version.
Returns:
  DHT version for a near version.

#### addAlternateVersion

    public void addAlternateVersion(GridCacheVersion ver,
                                    IgniteInternalTx tx)

Parameters:
  `ver` - Alternate version.
  `tx` - Transaction.

#### localTx

    @Nullable
    public IgniteTxLocalAdapter localTx()

Returns:
  Local transaction.

#### threadLocalTx

    public GridNearTxLocal threadLocalTx(GridCacheContext cctx)

Parameters:
  `cctx` - Cache context.
Returns:
  Transaction for current thread.

#### tx

    public <T> T tx()

Returns:
  Transaction for current thread.

#### lockedTopologyVersion

    @Nullable
    public 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
                                     AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Locked topology version.
Returns:
  `True` if topology hint was set.

#### userTx

    @Nullable
    public GridNearTxLocal userTx()

Returns:
  User transaction for current thread.

#### inUserTx

    public boolean inUserTx()

Returns:
  `True` if current thread is currently within transaction.

#### tx

    @Nullable
    public <T extends IgniteInternalTx> T tx(GridCacheVersion txId)

Parameters:
  `txId` - Transaction ID.
Returns:
  Transaction with given ID.

#### nearTx

    @Nullable
    public <T extends IgniteInternalTx> T nearTx(GridCacheVersion txId)

Parameters:
  `txId` - Transaction ID.
Returns:
  Transaction with given ID.

#### prepareTx

    public void prepareTx(IgniteInternalTx tx,
                          @Nullable
                          Collection<IgniteTxEntry> entries)
                   throws IgniteCheckedException

Handles prepare stage.

Parameters:
  `tx` - Transaction to prepare.
  `entries` - Entries to lock or `null` if use default `IgniteInternalTx.optimisticLockEntries()`.
Throws:
  `IgniteCheckedException` - If preparation failed.

#### versions

    public IgnitePair<Collection<GridCacheVersion>> versions(GridCacheVersion min)

Parameters:
  `min` - Minimum version.
Returns:
  Pair [committed, rolledback] - never `null`, elements potentially empty, but also never `null`.

#### activeTransactions

    public Collection<IgniteInternalTx> activeTransactions()

Returns:
  Collection of active transactions.

#### removeCommittedTx

    public void removeCommittedTx(IgniteInternalTx tx)

Parameters:
  `tx` - Tx to remove.

#### addCommittedTx

    public void addCommittedTx(IgniteInternalTx tx)

Parameters:
  `tx` - Committed transaction.

#### addCommittedTxReturn

    public void addCommittedTxReturn(IgniteInternalTx tx,
                                     GridCacheReturnCompletableWrapper ret)

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
                                  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.

#### getCommittedTxReturn

    public GridCacheReturnCompletableWrapper getCommittedTxReturn(GridCacheVersion xidVer)

Parameters:
  `xidVer` - xidVer Completed transaction version.
Returns:
  Tx result.

#### removeTxReturn

    public void removeTxReturn(GridCacheVersion xidVer)

Parameters:
  `xidVer` - xidVer Completed transaction version.

#### commitTx

    public void commitTx(IgniteInternalTx tx)
                  throws IgniteCheckedException

Commits a transaction.

Parameters:
  `tx` - Transaction to commit.
Throws:
  `IgniteCheckedException` - If failed.

#### 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.

#### 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.

#### beforeFinishRemote

    public void beforeFinishRemote(UUID rmtNodeId,
                                   long threadId)

Callback called by near finish future before sending near finish request to remote node. Will increment per-thread counter so that further awaitAck call will wait for finish response.

Parameters:
  `rmtNodeId` - Remote node ID for which finish request is being sent.
  `threadId` - Near tx thread ID.

#### onFinishedRemote

    public void onFinishedRemote(UUID rmtNodeId,
                                 long threadId)

Callback invoked when near finish response is received from remote node.

Parameters:
  `rmtNodeId` - Remote node ID from which response is received.
  `threadId` - Near tx thread ID.

#### awaitFinishAckAsync

    @Nullable
    public IgniteInternalFuture<?> awaitFinishAckAsync(UUID rmtNodeId,
                                                                 long threadId)

Asynchronously waits for last finish request ack.

Parameters:
  `rmtNodeId` - Remote node ID.
  `threadId` - Near tx thread ID.
Returns:
  `null` if ack was received or future that will be completed when ack is received.

#### finishSyncDisabled

    public void finishSyncDisabled(boolean finishSyncDisabled)

For test purposes only.

Parameters:
  `finishSyncDisabled` - `True` if finish sync should be disabled.

#### txContext

    public void txContext(IgniteInternalTx tx)

Parameters:
  `tx` - Committing transaction.

#### txContextVersion

    @Nullable
    public GridCacheVersion txContextVersion()

Gets version of transaction in tx context or `null` if tx context is empty.

This is a convenience method provided mostly for debugging.

Returns:
  Transaction version from transaction context.

#### resetContext

    public void resetContext()

Commit ended.

#### slowTxWarnTimeout

    public int slowTxWarnTimeout()

Returns:
  Slow tx warn timeout.

#### slowTxWarnTimeout

    public void slowTxWarnTimeout(int slowTxWarnTimeout)

Parameters:
  `slowTxWarnTimeout` - Slow tx warn timeout.

#### txsPreparedOrCommitted

    @Nullable
    public 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.

#### txCommitted

    public IgniteInternalFuture<Boolean> txCommitted(GridCacheVersion xidVer)

Parameters:
  `xidVer` - Version.
Returns:
  Future for flag indicating if transactions was committed.

#### 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 void 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.

#### detectDeadlock

    public IgniteInternalFuture<TxDeadlock> detectDeadlock(IgniteInternalTx tx,
                                                           Set<IgniteTxKey> keys)

Performs deadlock detection for given keys.

Parameters:
  `tx` - Target tx.
  `keys` - Keys.
Returns:
  Detection result.

#### addFuture

    public void addFuture(org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture fut)

Parameters:
  `fut` - Future.

#### future

    @Nullable
    public 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.

#### suspendTx

    public void suspendTx(GridNearTxLocal tx)
                   throws IgniteCheckedException

Suspends transaction. Should not be used directly. Use tx.suspend() instead.

Parameters:
  `tx` - Transaction to be suspended.
Throws:
  `IgniteCheckedException` - If failed to suspend transaction.
See Also:
  `resumeTx(GridNearTxLocal, long)`, `GridNearTxLocal.suspend()`, `GridNearTxLocal.resume()`

#### resumeTx

    public void resumeTx(GridNearTxLocal tx,
                         long threadId)
                  throws IgniteCheckedException

Resume transaction in current thread. Please don't use directly. Use tx.resume() instead.

Parameters:
  `tx` - Transaction to be resumed.
  `threadId` - Thread id to restore.
Throws:
  `IgniteCheckedException` - If failed to resume tx.
See Also:
  `suspendTx(GridNearTxLocal)`, `GridNearTxLocal.suspend()`, `GridNearTxLocal.resume()`

#### logTxRecords

    public boolean logTxRecords()

Returns:
  True if `TxRecord` records should be logged to WAL.

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.6.0
Release Date | : July 10 2018