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

## Class IgniteTxManager<K,V>

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter<K,V>
  - - org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager<K,V>

All Implemented Interfaces:
  GridCacheSharedManager<K,V>

    public class IgniteTxManager<K,V>
    extends GridCacheSharedManagerAdapter<K,V>

Cache transaction manager.

### Field Summary

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

`cctx, log`

### Constructor Summary

Constructors
Constructor and Description
`IgniteTxManager()`

### Method Summary

Methods
`void` `addAlternateVersion(GridCacheVersion ver, IgniteInternalTx<K,V> tx)`
`boolean` `addCommittedTx(GridCacheVersion xidVer, GridCacheVersion nearXidVer)`
`boolean` `addCommittedTx(IgniteInternalTx<K,V> tx)`
`boolean` `addRolledbackTx(GridCacheVersion xidVer)`
`boolean` `addRolledbackTx(IgniteInternalTx<K,V> tx)`
`void` `addSynchronizations(TransactionSynchronization... sync)`
`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.
`int` `commitQueueSize()`
`Collection<GridCacheVersion>` `committedVersions(GridCacheVersion min)` Gets committed transactions starting from the given version (inclusive). // TODO: GG-4011: why inclusive?
`void` `commitTx(IgniteInternalTx<K,V> tx)` Commits a transaction.
`int` `completedVersionsSize()`
`void` `finishOptimisticTxOnRecovery(IgniteInternalTx<K,V> tx, boolean commit)` Commits or rolls back prepared transaction.
`void` `finishPessimisticTxOnRecovery(IgniteInternalTx<K,V> tx, GridCacheCommittedTxInfo<K,V> commitInfo)` Commits or rolls back pessimistic transaction.
`void` `finishSyncDisabled(boolean finishSyncDisabled)` For test purposes only.
`IgniteInternalFuture<Boolean>` `finishTxs(long topVer)` Creates a future that will wait for all ongoing transactions that maybe affected by topology update to be finished.
`int` `idMapSize()`
`boolean` `inUserTx()`
`boolean` `isCompleted(IgniteInternalTx<K,V> tx)`
`<T> T` `localTx()`
`IgniteInternalTx<K,V>` `localTxForRecovery(GridCacheVersion nearXidVer, boolean markFinalizing)` Gets local transaction for pessimistic tx recovery.
`IgniteInternalTx<K,V>` `localTxx()`
`GridCacheVersion` `mappedVersion(GridCacheVersion from)`
`<T extends IgniteInternalTx<K,V>> T` `nearTx(GridCacheVersion txId)`
`GridCacheVersion` `nearVersion(GridCacheVersion dhtVer)` Reverse mapped version look up.
`IgniteTxLocalAdapter<K,V>` `newTx(boolean implicit, boolean implicitSingle, boolean sys, TransactionConcurrency concurrency, TransactionIsolation isolation, long timeout, boolean invalidate, boolean storeEnabled, int txSize, IgniteTxKey grpLockKey, boolean partLock)`
`<T extends IgniteInternalTx<K,V>> T` `onCreated(T tx)`
`void` `onFinishedRemote(UUID rmtNodeId, long threadId)` Callback invoked when near finish response is received from remote node.
`protected void` `onKernalStart0()`
`boolean` `onOwnerChanged(GridCacheEntryEx<K,V> entry, GridCacheMvccCandidate<K> owner)` Callback invoked whenever a member of a transaction acquires lock ownership.
`boolean` `onStarted(IgniteInternalTx<K,V> tx)` Transaction start callback (has to do with when any operation was performed on this transaction).
`void` `onTxStateChange(TransactionState prevState, TransactionState newState, IgniteInternalTx tx)`
`int` `prepareQueueSize()`
`void` `prepareTx(IgniteInternalTx<K,V> tx)` Handles prepare stage of 2PC.
`void` `printMemoryStats()` Prints out memory stats to standard out.
`void` `removeCommittedTx(IgniteInternalTx<K,V> tx)`
`void` `removeSynchronizations(TransactionSynchronization... sync)`
`void` `rollbackTx(IgniteInternalTx<K,V> tx)` Rolls back a transaction.
`Collection<GridCacheVersion>` `rolledbackVersions(GridCacheVersion min)` Gets rolledback transactions starting from the given version (inclusive). // TODO: GG-4011: why inclusive?
`boolean` `salvageTx(IgniteInternalTx<K,V> tx)` Invalidates transaction.
`int` `slowTxWarnTimeout()`
`void` `slowTxWarnTimeout(int slowTxWarnTimeout)`
`protected void` `start0()`
`int` `startVersionCountsSize()`
`Collection<TransactionSynchronization>` `synchronizations()`
`<T> T` `threadLocalTx()`
`int` `threadMapSize()`
`<T> T` `tx()`
`<T extends IgniteInternalTx<K,V>> T` `tx(GridCacheVersion txId)`
`<T> T` `tx(long threadId)`
`void` `txContext(IgniteInternalTx tx)`
`void` `txContextReset()` Commit ended.
`GridCacheVersion` `txContextVersion()` Gets version of transaction in tx context or `null` if tx context is empty.
`IgniteTxHandler<K,V>` `txHandler()`
`Collection<IgniteInternalTx<K,V>>` `txs()`
`boolean` `txsPreparedOrCommitted(GridCacheVersion nearVer, int txNum)` Checks if transactions with given near version ID was prepared or committed.
`IgniteInternalTx<K,V>` `txx()`
`IgniteInternalTx<K,V>` `txx(GridCacheVersion txId)`
`void` `uncommitTx(IgniteInternalTx<K,V> tx)` Tries to minimize damage from partially-committed transaction.
`IgniteInternalTx` `userTx()`
`<T extends IgniteTxLocalEx<K,V>> T` `userTxx()`

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

`context, kernalStartInfo, kernalStopInfo, log, onKernalStart, onKernalStop, onKernalStop0, start, startInfo, stop, stop0, stopInfo, toString`

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

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

### Constructor Detail

#### IgniteTxManager

    public IgniteTxManager()

### Method Detail

#### onKernalStart0

    protected void onKernalStart0()

Overrides:
  `onKernalStart0` in class `GridCacheSharedManagerAdapter<K,V>`

#### start0

    protected void start0()
                   throws IgniteCheckedException

Overrides:
  `start0` in class `GridCacheSharedManagerAdapter<K,V>`
Throws:
  `IgniteCheckedException` - If failed.

#### txHandler

    public IgniteTxHandler<K,V> txHandler()

Returns:
  TX handler.

#### salvageTx

    public boolean salvageTx(IgniteInternalTx<K,V> 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<K,V>`
Overrides:
  `printMemoryStats` in class `GridCacheSharedManagerAdapter<K,V>`

#### threadMapSize

    public int threadMapSize()

Returns:
  Thread map size.

#### idMapSize

    public int idMapSize()

Returns:
  ID map size.

#### commitQueueSize

    public int commitQueueSize()

Returns:
  Committed queue size.

#### prepareQueueSize

    public int prepareQueueSize()

Returns:
  Prepare queue size.

#### startVersionCountsSize

    public int startVersionCountsSize()

Returns:
  Start version counts.

#### completedVersionsSize

    public int completedVersionsSize()

Returns:
  Committed versions size.

#### isCompleted

    public boolean isCompleted(IgniteInternalTx<K,V> tx)

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

#### newTx

    public IgniteTxLocalAdapter<K,V> newTx(boolean implicit,
                                  boolean implicitSingle,
                                  boolean sys,
                                  TransactionConcurrency concurrency,
                                  TransactionIsolation isolation,
                                  long timeout,
                                  boolean invalidate,
                                  boolean storeEnabled,
                                  int txSize,
                                  @Nullable
                                  IgniteTxKey grpLockKey,
                                  boolean partLock)

Parameters:
  `implicit` - `True` if transaction is implicit.
  `implicitSingle` - Implicit-with-single-key flag.
  `concurrency` - Concurrency.
  `isolation` - Isolation.
  `timeout` - transaction timeout.
  `txSize` - Expected transaction size.
  `grpLockKey` - Group lock key if this is a group-lock transaction.
  `partLock` - `True` if partition is locked.
Returns:
  New transaction.

#### onCreated

    @Nullable
    public <T extends IgniteInternalTx<K,V>> T onCreated(T tx)

Parameters:
  `tx` - Created transaction.
Returns:
  Started transaction.

#### finishTxs

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

#### onStarted

    public boolean onStarted(IgniteInternalTx<K,V> 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.

#### nearVersion

    @Nullable
    public GridCacheVersion nearVersion(GridCacheVersion dhtVer)

Reverse mapped version look up.

Parameters:
  `dhtVer` - Dht version.
Returns:
  Near version.

#### mappedVersion

    public GridCacheVersion mappedVersion(GridCacheVersion from)

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

#### addAlternateVersion

    public void addAlternateVersion(GridCacheVersion ver,
                           IgniteInternalTx<K,V> tx)

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

#### localTx

    @Nullable
    public <T> T localTx()

Returns:
  Local transaction.

#### threadLocalTx

    public <T> T threadLocalTx()

Returns:
  Transaction for current thread.

#### tx

    public <T> T tx()

Returns:
  Transaction for current thread.

#### localTxx

    @Nullable
    public IgniteInternalTx<K,V> localTxx()

Returns:
  Local transaction.

#### txx

    public IgniteInternalTx<K,V> txx()

Returns:
  Transaction for current thread.

#### userTx

    @Nullable
    public IgniteInternalTx userTx()

Returns:
  User transaction for current thread.

#### userTxx

    @Nullable
    public <T extends IgniteTxLocalEx<K,V>> T userTxx()

Returns:
  User transaction.

#### tx

    public <T> T tx(long threadId)

Parameters:
  `threadId` - Id of thread for transaction.
Returns:
  Transaction for thread with given ID.

#### inUserTx

    public boolean inUserTx()

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

#### tx

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

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

#### nearTx

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

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

#### txx

    @Nullable
    public IgniteInternalTx<K,V> txx(GridCacheVersion txId)

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

#### prepareTx

    public void prepareTx(IgniteInternalTx<K,V> tx)
                   throws IgniteCheckedException

Handles prepare stage of 2PC.

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

#### committedVersions

    public Collection<GridCacheVersion> committedVersions(GridCacheVersion min)

Gets committed transactions starting from the given version (inclusive). // TODO: GG-4011: why inclusive?

Parameters:
  `min` - Start (or minimum) version.
Returns:
  Committed transactions starting from the given version (non-inclusive).

#### rolledbackVersions

    public Collection<GridCacheVersion> rolledbackVersions(GridCacheVersion min)

Gets rolledback transactions starting from the given version (inclusive). // TODO: GG-4011: why inclusive?

Parameters:
  `min` - Start (or minimum) version.
Returns:
  Committed transactions starting from the given version (non-inclusive).

#### removeCommittedTx

    public void removeCommittedTx(IgniteInternalTx<K,V> tx)

Parameters:
  `tx` - Tx to remove.

#### addCommittedTx

    public boolean addCommittedTx(IgniteInternalTx<K,V> tx)

Parameters:
  `tx` - Committed transaction.
Returns:
  If transaction was not already present in committed set.

#### addRolledbackTx

    public boolean addRolledbackTx(IgniteInternalTx<K,V> tx)

Parameters:
  `tx` - Committed transaction.
Returns:
  If transaction was not already present in committed set.

#### addCommittedTx

    public boolean addCommittedTx(GridCacheVersion xidVer,
                         @Nullable
                         GridCacheVersion nearXidVer)

Parameters:
  `xidVer` - Completed transaction version.
  `nearXidVer` - Optional near transaction ID.
Returns:
  If transaction was not already present in completed set.

#### addRolledbackTx

    public boolean addRolledbackTx(GridCacheVersion xidVer)

Parameters:
  `xidVer` - Completed transaction version.
Returns:
  If transaction was not already present in completed set.

#### commitTx

    public void commitTx(IgniteInternalTx<K,V> tx)

Commits a transaction.

Parameters:
  `tx` - Transaction to commit.

#### rollbackTx

    public void rollbackTx(IgniteInternalTx<K,V> tx)

Rolls back a transaction.

Parameters:
  `tx` - Transaction to rollback.

#### uncommitTx

    public void uncommitTx(IgniteInternalTx<K,V> tx)

Tries to minimize damage from partially-committed transaction.

Parameters:
  `tx` - Tx to uncommit.

#### onOwnerChanged

    public boolean onOwnerChanged(GridCacheEntryEx<K,V> entry,
                         GridCacheMvccCandidate<K> 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.

#### addSynchronizations

    public void addSynchronizations(TransactionSynchronization... sync)

Parameters:
  `sync` - Transaction synchronizations to add.

#### removeSynchronizations

    public void removeSynchronizations(TransactionSynchronization... sync)

Parameters:
  `sync` - Transaction synchronizations to remove.

#### synchronizations

    public Collection<TransactionSynchronization> synchronizations()

Returns:
  Registered transaction synchronizations

#### onTxStateChange

    public void onTxStateChange(@Nullable
                       TransactionState prevState,
                       TransactionState newState,
                       IgniteInternalTx tx)

Parameters:
  `prevState` - Previous state.
  `newState` - New state.
  `tx` - Cache transaction.

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

#### txContextReset

    public void txContextReset()

Commit ended.

#### txs

    public Collection<IgniteInternalTx<K,V>> 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

    public 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:
  `True` if transactions were prepared or committed.

#### localTxForRecovery

    @Nullable
    public IgniteInternalTx<K,V> localTxForRecovery(GridCacheVersion nearXidVer,
                                                    boolean markFinalizing)

Gets local transaction for pessimistic tx recovery.

Parameters:
  `nearXidVer` - Near tx ID.
Returns:
  Near local or colocated local transaction.

#### finishOptimisticTxOnRecovery

    public void finishOptimisticTxOnRecovery(IgniteInternalTx<K,V> tx,
                                    boolean commit)

Commits or rolls back prepared transaction.

Parameters:
  `tx` - Transaction.
  `commit` - Whether transaction should be committed or rolled back.

#### finishPessimisticTxOnRecovery

    public void finishPessimisticTxOnRecovery(IgniteInternalTx<K,V> tx,
                                     GridCacheCommittedTxInfo<K,V> commitInfo)

Commits or rolls back pessimistic transaction.

Parameters:
  `tx` - Transaction to finish.
  `commitInfo` - Commit information.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.0.0-RC1
Release Date | : February 17 2015