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 IgniteProductVersion` `TX_DEADLOCK_DETECTION_SINCE` Version in which deadlock detection introduced.

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

`cctx, log`

### Constructor Summary

Constructors
Constructor and Description
`IgniteTxManager()`

### Method Summary

Methods
`Collection<IgniteInternalTx>` `activeTransactions()`
`void` `addAlternateVersion(GridCacheVersion ver, IgniteInternalTx tx)`
`void` `addCommittedTx(IgniteInternalTx tx)`
`boolean` `addCommittedTx(IgniteInternalTx tx, GridCacheVersion xidVer, GridCacheVersion nearXidVer)`
`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` `commitIfPrepared(IgniteInternalTx tx)` 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()`
`IgniteInternalFuture<TxDeadlock>` `detectDeadlock(IgniteInternalTx tx, Set<IgniteTxKey> keys)` Performs deadlock detection for given keys.
`void` `fastFinishTx(IgniteInternalTx tx, boolean commit)` Fast finish transaction.
`void` `finishSyncDisabled(boolean finishSyncDisabled)` For test purposes only.
`void` `finishTxOnRecovery(IgniteInternalTx tx, boolean commit)` Commits or rolls back prepared transaction.
`IgniteInternalFuture<Boolean>` `finishTxs(AffinityTopologyVersion topVer)` Creates a future that will wait for all ongoing transactions that maybe affected by topology update to be finished.
`org.apache.ignite.internal.processors.cache.transactions.TxDeadlockDetection.TxDeadlockFuture` `future(long futId)`
`int` `idMapSize()`
`boolean` `inUserTx()`
`boolean` `isCompleted(IgniteInternalTx tx)`
`<T> T` `localTx()`
`IgniteInternalTx` `localTxx()`
`AffinityTopologyVersion` `lockedTopologyVersion(long threadId, IgniteInternalTx ignore)`
`GridCacheVersion` `mappedVersion(GridCacheVersion from)`
`<T extends IgniteInternalTx> T` `nearTx(GridCacheVersion txId)`
`boolean` `needWaitTransaction(IgniteInternalTx tx, AffinityTopologyVersion topVer)`
`IgniteTxLocalAdapter` `newTx(boolean implicit, boolean implicitSingle, GridCacheContext sysCacheCtx, TransactionConcurrency concurrency, TransactionIsolation isolation, long timeout, boolean storeEnabled, int txSize)`
`<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` `onKernalStart0(boolean reconnect)`
`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)` Handles prepare stage of 2PC.
`void` `printMemoryStats()` Prints out memory stats to standard out.
`IgniteInternalFuture<?>` `remoteTxFinishFuture(GridCacheVersion nearVer)`
`void` `removeCommittedTx(IgniteInternalTx tx)`
`void` `removeFuture(long futId)`
`void` `resetContext()` Commit ended.
`void` `rollbackTx(IgniteInternalTx tx)` Rolls back a transaction.
`boolean` `salvageTx(IgniteInternalTx tx)` Invalidates transaction.
`boolean` `setTxTopologyHint(AffinityTopologyVersion topVer)`
`int` `slowTxWarnTimeout()`
`void` `slowTxWarnTimeout(int slowTxWarnTimeout)`
`protected void` `start0()`
`<T> T` `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()`
`Collection<IgniteInternalTx>` `txs()`
`IgniteInternalFuture<Boolean>` `txsPreparedOrCommitted(GridCacheVersion nearVer, int txNum)` Checks if transactions with given near version ID was prepared or committed.
`IgniteInternalTx` `txx()`
`void` `uncommitTx(IgniteInternalTx tx)` Tries to minimize damage from partially-committed transaction.
`IgniteInternalTx` `userTx()`
`IgniteInternalTx` `userTx(GridCacheContext cctx)`
`<T extends IgniteTxLocalEx> T` `userTxx()`
`IgnitePair<Collection<GridCacheVersion>>` `versions(GridCacheVersion min)`

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

`context, kernalStartInfo, kernalStopInfo, log, onKernalStart, onKernalStop, 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

#### TX_DEADLOCK_DETECTION_SINCE

    public static final IgniteProductVersion TX_DEADLOCK_DETECTION_SINCE

Version in which deadlock detection introduced.

### Constructor Detail

#### IgniteTxManager

    public IgniteTxManager()

### Method Detail

#### onKernalStart0

    protected void onKernalStart0(boolean reconnect)

Overrides:
  `onKernalStart0` in class `GridCacheSharedManagerAdapter`
Parameters:
  `reconnect` - `True` if manager restarted after client reconnect.

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

#### 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 boolean salvageTx(IgniteInternalTx tx)

Invalidates transaction.

Parameters:
  `tx` - Transaction.
Returns:
  `True` if transaction was salvaged by this call.

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

#### isCompleted

    public boolean isCompleted(IgniteInternalTx tx)

Parameters:
  `tx` - Transaction to check.
Returns:
  `True` if transaction has been committed or rolled back, `false` otherwise.

#### newTx

    public IgniteTxLocalAdapter newTx(boolean implicit,
                             boolean implicitSingle,
                             @Nullable
                             GridCacheContext sysCacheCtx,
                             TransactionConcurrency concurrency,
                             TransactionIsolation isolation,
                             long timeout,
                             boolean storeEnabled,
                             int txSize)

Parameters:
  `implicit` - `True` if transaction is implicit.
  `implicitSingle` - Implicit-with-single-key flag.
  `concurrency` - Concurrency.
  `isolation` - Isolation.
  `timeout` - transaction timeout.
  `txSize` - Expected transaction size.
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.

#### finishTxs

    public IgniteInternalFuture<Boolean> finishTxs(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.

#### 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 <T> T localTx()

Returns:
  Local transaction.

#### threadLocalTx

    public <T> T threadLocalTx(GridCacheContext cctx)

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.

#### localTxx

    @Nullable
    public IgniteInternalTx localTxx()

Returns:
  Local transaction.

#### txx

    public IgniteInternalTx txx()

Returns:
  Transaction for current thread.

#### userTx

    @Nullable
    public IgniteInternalTx userTx()

Returns:
  User transaction for current thread.

#### userTx

    @Nullable
    public IgniteInternalTx userTx(GridCacheContext cctx)

Returns:
  User transaction for current thread.

#### userTxx

    @Nullable
    public <T extends IgniteTxLocalEx> T userTxx()

Returns:
  User transaction.

#### 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)
                   throws IgniteCheckedException

Handles prepare stage of 2PC.

Parameters:
  `tx` - Transaction to prepare.
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.

#### addRolledbackTx

    public boolean addRolledbackTx(IgniteInternalTx tx)

Parameters:
  `tx` - Committed transaction.
Returns:
  If transaction was not already present in committed 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.

#### commitTx

    public void commitTx(IgniteInternalTx tx)

Commits a transaction.

Parameters:
  `tx` - Transaction to commit.

#### rollbackTx

    public void rollbackTx(IgniteInternalTx tx)

Rolls back a transaction.

Parameters:
  `tx` - Transaction to rollback.

#### fastFinishTx

    public void fastFinishTx(IgniteInternalTx tx,
                    boolean commit)

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.

#### uncommitTx

    public void uncommitTx(IgniteInternalTx tx)

Tries to minimize damage from partially-committed transaction.

Parameters:
  `tx` - Tx to uncommit.

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

#### txs

    public Collection<IgniteInternalTx> txs()

Returns:
  All transactions.

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

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.

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

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.6.0
Release Date | : May 18 2016