org.apache.ignite.internal.processors.cache

## Class GridCacheMvccManager

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

All Implemented Interfaces:
  GridCacheSharedManager

    public class GridCacheMvccManager
    extends GridCacheSharedManagerAdapter

Manages lock order within a thread.

### Field Summary

Fields
`static int` `DFLT_MAX_NESTED_LISTENER_CALLS`
`protected AtomicLong` `globalAtomicCnt` Global atomic id counter.
`protected static int` `THREAD_RESERVE_SIZE` Maxim number of atomic IDs for thread.

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

`cctx, diagnosticLog, log`

### Constructor Summary

Constructors
Constructor and Description
`GridCacheMvccManager()`

### Method Summary

All Methods Instance Methods Concrete Methods
`Collection<GridCacheExplicitLockSpan>` `activeExplicitLocks()`
`Collection<GridCacheFuture<?>>` `activeFutures()`
`boolean` `addAtomicFuture(long futId, GridCacheAtomicFuture<?> fut)`
`GridFutureAdapter` `addDataStreamerFuture(AffinityTopologyVersion topVer)`
`void` `addExplicitLock(long threadId, GridCacheMvccCandidate cand, AffinityTopologyVersion topVer)` Adds candidate to the list of near local candidates.
`boolean` `addFuture(GridCacheFuture<?> fut, IgniteUuid futId)`
`boolean` `addFuture(GridCacheVersionedFuture<?> fut)` /** Adds future.
`boolean` `addNext(GridCacheContext cacheCtx, GridCacheMvccCandidate cand)`
`boolean` `addRemoved(GridCacheContext cacheCtx, GridCacheVersion ver)`
`@Nullable IgniteInternalFuture<?>` `atomicFuture(long futId)` Gets future by given future ID.
`Collection<GridCacheAtomicFuture<?>>` `atomicFutures()`
`int` `atomicFuturesCount()`
`GridCacheLockCallback` `callback()`
`void` `contextReset()` Reset MVCC context.
`Collection<org.apache.ignite.internal.processors.cache.GridCacheMvccManager.DataStreamerFuture>` `dataStreamerFutures()`
`@Nullable GridCacheMvccCandidate` `explicitLock(IgniteTxKey key, @Nullable GridCacheVersion ver)` Gets explicit lock candidate added by any thread by given key and lock version.
`@Nullable GridCacheMvccCandidate` `explicitLock(long threadId, IgniteTxKey key)` Gets last added explicit lock candidate by thread id and key.
`IgniteInternalFuture<?>` `finishAtomicUpdates(AffinityTopologyVersion topVer)`
`IgniteInternalFuture<?>` `finishDataStreamerUpdates(AffinityTopologyVersion topVer)`
`IgniteInternalFuture<?>` `finishExplicitLocks(AffinityTopologyVersion topVer)` Creates a future that will wait for all explicit locks acquired on given topology version to be released.
`IgniteInternalFuture<?>` `finishKeys(Collection<KeyCacheObject> keys, int cacheId, AffinityTopologyVersion topVer)`
`IgniteInternalFuture<?>` `finishLocks(AffinityTopologyVersion topVer)`
`IgniteInternalFuture<?>` `finishRemoteTxs(AffinityTopologyVersion topVer)` Creates a future that will wait for finishing all remote transactions (primary -> backup) with topology version less or equal to `topVer`.
`@Nullable GridCacheFuture` `future(IgniteUuid futId)`
`@Nullable Collection<GridCacheVersionedFuture<?>>` `futuresForVersion(GridCacheVersion ver)` Gets futures for given lock ID.
`boolean` `isLockedByThread(IgniteTxKey key, long threadId)` Checks if given key is locked by thread with given id or any thread.
`boolean` `isRemoved(GridCacheContext cacheCtx, GridCacheVersion ver)`
`@Nullable AffinityTopologyVersion` `lastExplicitLockTopologyVersion(long threadId)`
`Collection<GridCacheMvccCandidate>` `localCandidates()` This method has poor performance, so use with care.
`Collection<IgniteTxKey>` `lockedKeys()`
`GridCacheVersion` `mappedVersion(GridCacheVersion from)`
`void` `mapVersion(GridCacheVersion from, GridCacheVersion to)`
`void` `markExplicitOwner(IgniteTxKey key, long threadId)` Marks candidates for given thread and given key as owned.
`Collection<IgniteTxKey>` `nearLockedKeys()`
`long` `nextAtomicId()`
`void` `onDisconnected(IgniteFuture reconnectFut)`
`void` `onKernalStop0(boolean cancel)`
`void` `onStop()` Cancels all client futures.
`void` `printMemoryStats()` Prints memory statistics (sizes of internal data structures, etc.).
`void` `recheckPendingLocks()`
`Collection<GridCacheMvccCandidate>` `remoteCandidates()` This method has poor performance, so use with care.
`@Nullable IgniteInternalFuture<?>` `removeAtomicFuture(long futId)`
`void` `removeExplicitLock(GridCacheMvccCandidate cand)` Removes candidate from the list of near local candidates.
`GridCacheMvccCandidate` `removeExplicitLock(long threadId, IgniteTxKey key, @Nullable GridCacheVersion ver)` Removes explicit lock for given thread id, key and optional version.
`void` `removeExplicitNodeLocks(UUID leftNodeId)`
`void` `removeFuture(IgniteUuid futId)`
`boolean` `removeVersionedFuture(GridCacheVersionedFuture<?> fut)`
`protected void` `start0()`
`Map<IgniteTxKey,Collection<GridCacheMvccCandidate>>` `unfinishedLocks(AffinityTopologyVersion topVer)`
`GridCacheVersion` `unmapVersion(GridCacheVersion from)`
`@Nullable GridCacheVersionedFuture<?>` `versionedFuture(GridCacheVersion ver, IgniteUuid futId)` Gets future for given future ID and lock ID.

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

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

#### THREAD_RESERVE_SIZE

    protected static final int THREAD_RESERVE_SIZE

Maxim number of atomic IDs for thread. Must be power of two!

See Also:
  Constant Field Values

#### DFLT_MAX_NESTED_LISTENER_CALLS

    public static final int DFLT_MAX_NESTED_LISTENER_CALLS

See Also:
  `IgniteSystemProperties.IGNITE_MAX_NESTED_LISTENER_CALLS`, Constant Field Values

#### globalAtomicCnt

    protected final AtomicLong globalAtomicCnt

Global atomic id counter.

### Constructor Detail

#### GridCacheMvccManager

    public GridCacheMvccManager()

### Method Detail

#### start0

    protected void start0()
                   throws IgniteCheckedException

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

#### onKernalStop0

    public void onKernalStop0(boolean cancel)

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

#### callback

    public GridCacheLockCallback callback()

Returns:
  MVCC callback.

#### activeExplicitLocks

    public Collection<GridCacheExplicitLockSpan> activeExplicitLocks()

Returns:
  Collection of pending explicit locks.

#### activeFutures

    public Collection<GridCacheFuture<?>> activeFutures()

Returns:
  Collection of active futures.

#### finishRemoteTxs

    public IgniteInternalFuture<?> finishRemoteTxs(AffinityTopologyVersion topVer)

Creates a future that will wait for finishing all remote transactions (primary -> backup) with topology version less or equal to `topVer`.

Parameters:
  `topVer` - Topology version.
Returns:
  Compound future of all `GridDhtTxFinishFuture` futures.

#### removeExplicitNodeLocks

    public void removeExplicitNodeLocks(UUID leftNodeId)

Parameters:
  `leftNodeId` - Left node ID.

#### mapVersion

    public void mapVersion(GridCacheVersion from,
                           GridCacheVersion to)

Parameters:
  `from` - From version.
  `to` - To version.

#### mappedVersion

    public GridCacheVersion mappedVersion(GridCacheVersion from)

Parameters:
  `from` - Near version.
Returns:
  DHT version.

#### onStop

    public void onStop()

Cancels all client futures.

#### onDisconnected

    public void onDisconnected(IgniteFuture reconnectFut)

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

#### unmapVersion

    public GridCacheVersion unmapVersion(GridCacheVersion from)

Parameters:
  `from` - From version.
Returns:
  To version.

#### addAtomicFuture

    public boolean addAtomicFuture(long futId,
                                   GridCacheAtomicFuture<?> fut)

Parameters:
  `futId` - Future ID.
  `fut` - Future.
Returns:
  `False` if future was forcibly completed with error.

#### atomicFutures

    public Collection<GridCacheAtomicFuture<?>> atomicFutures()

Returns:
  Collection of pending atomic futures.

#### atomicFuturesCount

    public int atomicFuturesCount()

Returns:
  Number of pending atomic futures.

#### dataStreamerFutures

    public Collection<org.apache.ignite.internal.processors.cache.GridCacheMvccManager.DataStreamerFuture> dataStreamerFutures()

Returns:
  Collection of pending data streamer futures.

#### atomicFuture

    @Nullable
    public @Nullable IgniteInternalFuture<?> atomicFuture(long futId)

Gets future by given future ID.

Parameters:
  `futId` - Future ID.
Returns:
  Future.

#### removeAtomicFuture

    @Nullable
    public @Nullable IgniteInternalFuture<?> removeAtomicFuture(long futId)

Parameters:
  `futId` - Future ID.
Returns:
  Removed future.

#### addFuture

    public boolean addFuture(GridCacheFuture<?> fut,
                             IgniteUuid futId)

Parameters:
  `fut` - Future.
  `futId` - Future ID.
Returns:
  `True` if added.

#### addDataStreamerFuture

    public GridFutureAdapter addDataStreamerFuture(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version.
Returns:
  Future.

#### addFuture

    public boolean addFuture(GridCacheVersionedFuture<?> fut)

/** Adds future.

Parameters:
  `fut` - Future.
Returns:
  `True` if added.

#### removeFuture

    public void removeFuture(IgniteUuid futId)

Parameters:
  `futId` - Future ID.

#### removeVersionedFuture

    public boolean removeVersionedFuture(GridCacheVersionedFuture<?> fut)

Parameters:
  `fut` - Future to remove.
Returns:
  `True` if removed.

#### versionedFuture

    @Nullable
    public @Nullable GridCacheVersionedFuture<?> versionedFuture(GridCacheVersion ver,
                                                                           IgniteUuid futId)

Gets future for given future ID and lock ID.

Parameters:
  `ver` - Lock ID.
  `futId` - Future ID.
Returns:
  Future.

#### futuresForVersion

    @Nullable
    public @Nullable Collection<GridCacheVersionedFuture<?>> futuresForVersion(GridCacheVersion ver)

Gets futures for given lock ID.

Parameters:
  `ver` - Lock ID.
Returns:
  Futures.

#### future

    @Nullable
    public @Nullable GridCacheFuture future(IgniteUuid futId)

Parameters:
  `futId` - Future ID.
Returns:
  Found future.

#### isRemoved

    public boolean isRemoved(GridCacheContext cacheCtx,
                             GridCacheVersion ver)

Parameters:
  `cacheCtx` - Cache context.
  `ver` - Lock version to check.
Returns:
  `True` if lock had been removed.

#### addRemoved

    public boolean addRemoved(GridCacheContext cacheCtx,
                              GridCacheVersion ver)

Parameters:
  `cacheCtx` - Cache context.
  `ver` - Obsolete entry version.
Returns:
  `True` if added.

#### lockedKeys

    public Collection<IgniteTxKey> lockedKeys()

Returns:
  Locked keys.

#### nearLockedKeys

    public Collection<IgniteTxKey> nearLockedKeys()

Returns:
  Locked near keys.

#### remoteCandidates

    public Collection<GridCacheMvccCandidate> remoteCandidates()

This method has poor performance, so use with care. It is currently only used by `DGC`.

Returns:
  Remote candidates.

#### localCandidates

    public Collection<GridCacheMvccCandidate> localCandidates()

This method has poor performance, so use with care. It is currently only used by `DGC`.

Returns:
  Local candidates.

#### addNext

    public boolean addNext(GridCacheContext cacheCtx,
                           GridCacheMvccCandidate cand)

Parameters:
  `cacheCtx` - Cache context.
  `cand` - Cache lock candidate to add.
Returns:
  `True` if added as a result of this operation, `false` if was previously added.

#### contextReset

    public void contextReset()

Reset MVCC context.

#### addExplicitLock

    public void addExplicitLock(long threadId,
                                GridCacheMvccCandidate cand,
                                AffinityTopologyVersion topVer)

Adds candidate to the list of near local candidates.

Parameters:
  `threadId` - Thread ID.
  `cand` - Candidate to add.
  `topVer` - Topology version.

#### removeExplicitLock

    public void removeExplicitLock(GridCacheMvccCandidate cand)

Removes candidate from the list of near local candidates.

Parameters:
  `cand` - Candidate to remove.

#### isLockedByThread

    public boolean isLockedByThread(IgniteTxKey key,
                                    long threadId)

Checks if given key is locked by thread with given id or any thread.

Parameters:
  `key` - Key to check.
  `threadId` - Thread id. If -1, all threads will be checked.
Returns:
  `True` if locked by any or given thread (depending on `threadId` value).

#### markExplicitOwner

    public void markExplicitOwner(IgniteTxKey key,
                                  long threadId)

Marks candidates for given thread and given key as owned.

Parameters:
  `key` - Key.
  `threadId` - Thread id.

#### removeExplicitLock

    public GridCacheMvccCandidate removeExplicitLock(long threadId,
                                                     IgniteTxKey key,
                                                     @Nullable
                                                     @Nullable GridCacheVersion ver)

Removes explicit lock for given thread id, key and optional version.

Parameters:
  `threadId` - Thread id.
  `key` - Key.
  `ver` - Optional version.
Returns:
  Candidate.

#### explicitLock

    @Nullable
    public @Nullable GridCacheMvccCandidate explicitLock(long threadId,
                                                                   IgniteTxKey key)

Gets last added explicit lock candidate by thread id and key.

Parameters:
  `threadId` - Thread id.
  `key` - Key to look up.
Returns:
  Last added explicit lock candidate for given thread id and key or `null` if no such candidate.

#### explicitLock

    @Nullable
    public @Nullable GridCacheMvccCandidate explicitLock(IgniteTxKey key,
                                                                   @Nullable
                                                                   @Nullable GridCacheVersion ver)

Gets explicit lock candidate added by any thread by given key and lock version.

Parameters:
  `key` - Key.
  `ver` - Version.
Returns:
  Lock candidate that satisfies given criteria or `null` if no such candidate.

#### lastExplicitLockTopologyVersion

    @Nullable
    public @Nullable AffinityTopologyVersion lastExplicitLockTopologyVersion(long threadId)

Parameters:
  `threadId` - Thread ID.
Returns:
  Topology snapshot for last acquired and not released lock.

#### printMemoryStats

    public void printMemoryStats()

Prints memory statistics (sizes of internal data structures, etc.). NOTE: this method is for testing and profiling purposes only.

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

#### finishLocks

    public IgniteInternalFuture<?> finishLocks(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version.
Returns:
  Future that signals when all locks for given partitions are released.

#### unfinishedLocks

    public Map<IgniteTxKey,Collection<GridCacheMvccCandidate>> unfinishedLocks(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version.
Returns:
  Locked keys.

#### finishExplicitLocks

    public IgniteInternalFuture<?> finishExplicitLocks(AffinityTopologyVersion topVer)

Creates a future that will wait for all explicit locks acquired on given topology version to be released.

Parameters:
  `topVer` - Topology version to wait for.
Returns:
  Explicit locks release future.

#### finishAtomicUpdates

    public IgniteInternalFuture<?> finishAtomicUpdates(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version to finish.
Returns:
  Finish update future.

#### finishDataStreamerUpdates

    public IgniteInternalFuture<?> finishDataStreamerUpdates(AffinityTopologyVersion topVer)

Returns:
  Finish update future.

#### finishKeys

    public IgniteInternalFuture<?> finishKeys(Collection<KeyCacheObject> keys,
                                              int cacheId,
                                              AffinityTopologyVersion topVer)

Parameters:
  `keys` - Key for which locks should be released.
  `cacheId` - Cache ID.
  `topVer` - Topology version.
Returns:
  Future that signals when all locks for given keys are released.

#### recheckPendingLocks

    public void recheckPendingLocks()

#### nextAtomicId

    public long nextAtomicId()

Returns:
  Next future ID for atomic futures.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.10.0
Release Date | : March 10 2021