org.apache.ignite.internal.processors.cache

## Class GridCacheMvcc

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheMvcc

    public final class GridCacheMvcc
    extends Object

Replicated lock based on MVCC paradigm. This class ensures that locks are acquired in proper order and that there is no more than only one active lock present at all times. It also ensures that new generated lock candidates will appear after old ones in the pending set, hence preventing lock starvation. See `GridCacheVersionManager.next()` for information on how lock IDs are generated to prevent starvation.

### Constructor Summary

Constructors
Constructor and Description
`GridCacheMvcc(GridCacheContext<?,?> cctx)`

### Method Summary

All Methods Instance Methods Concrete Methods
`GridCacheMvccCandidate` `addLocal(GridCacheEntryEx parent, long threadId, GridCacheVersion ver, long timeout, boolean reenter, boolean tx, boolean implicitSingle, boolean read)`
`GridCacheMvccCandidate` `addLocal(GridCacheEntryEx parent, UUID nearNodeId, GridCacheVersion nearVer, long threadId, GridCacheVersion ver, long timeout, GridCacheVersion serOrder, boolean reenter, boolean tx, boolean implicitSingle, boolean dhtLoc, boolean read)`
`GridCacheMvccCandidate` `addNearLocal(GridCacheEntryEx parent, UUID nodeId, UUID otherNodeId, long threadId, GridCacheVersion ver, boolean tx, boolean implicitSingle, boolean read)` Adds new near local lock candidate.
`GridCacheMvccCandidate` `addRemote(GridCacheEntryEx parent, UUID nodeId, UUID otherNodeId, long threadId, GridCacheVersion ver, boolean tx, boolean implicitSingle, boolean nearLoc)` Adds new remote lock candidate (either near remote or dht remote).
`CacheLockCandidates` `allOwners()`
`GridCacheMvccCandidate` `candidate(GridCacheVersion ver)` Gets candidate for lock ID.
`CacheLockCandidates` `doneRemote(GridCacheVersion ver, Collection<GridCacheVersion> pending, Collection<GridCacheVersion> committed, Collection<GridCacheVersion> rolledback)` Sets remote candidate to done.
`boolean` `isEmpty(GridCacheVersion... exclude)`
`GridCacheMvccCandidate` `localCandidate(UUID nodeId, long threadId)` Near local candidate.
`List<GridCacheMvccCandidate>` `localCandidates(boolean reentries, GridCacheVersion... excludeVers)`
`Collection<GridCacheMvccCandidate>` `localCandidates(GridCacheVersion... excludeVers)`
`List<GridCacheMvccCandidate>` `localCandidatesNoCopy(boolean reentry)`
`CacheLockCandidates` `localOwners()`
`void` `markOwned(GridCacheVersion baseVer, GridCacheVersion owned)` Puts owned versions in front of base.
`void` `orderCompleted(GridCacheVersion baseVer, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers)` Moves completed candidates right before the base one.
`CacheLockCandidates` `readyLocal(GridCacheMvccCandidate cand)`
`CacheLockCandidates` `readyLocal(GridCacheVersion ver)`
`CacheLockCandidates` `readyNearLocal(GridCacheVersion ver, GridCacheVersion mappedVer, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledBackVers, Collection<GridCacheVersion> pending)` Marks near-local candidate as ready and makes locks reassignment.
`CacheLockCandidates` `recheck()` Checks if lock should be assigned.
`GridCacheMvccCandidate` `releaseLocal()` Local local release.
`GridCacheMvccCandidate` `releaseLocal(long threadId)` Local release.
`List<GridCacheMvccCandidate>` `remoteCandidates(GridCacheVersion... excludeVers)`
`void` `remove(GridCacheVersion ver)` Removes lock even if it is not owner.
`CacheLockCandidates` `removeExplicitNodeCandidates(UUID nodeId)` Removes all candidates for node.
`void` `salvageRemote(GridCacheVersion ver)` For all remote candidates standing behind the candidate being salvaged marks their transactions as system invalidate and marks these candidates as owned and used.
`String` `toString()`

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

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

### Constructor Detail

#### GridCacheMvcc

    public GridCacheMvcc(GridCacheContext<?,?> cctx)

Parameters:
  `cctx` - Cache context.

### Method Detail

#### allOwners

    @Nullable
    public CacheLockCandidates allOwners()

Returns:
  All owners.

#### localOwners

    @Nullable
    public CacheLockCandidates localOwners()

Returns:
  All local owners.

#### isEmpty

    public boolean isEmpty(GridCacheVersion... exclude)

Parameters:
  `exclude` - Versions to exclude form check.
Returns:
  `True` if lock is empty.

#### orderCompleted

    public void orderCompleted(GridCacheVersion baseVer,
                               Collection<GridCacheVersion> committedVers,
                               Collection<GridCacheVersion> rolledbackVers)

Moves completed candidates right before the base one. Note that if base is not found, then nothing happens and `false` is returned.

Parameters:
  `baseVer` - Base version.
  `committedVers` - Committed versions relative to base.
  `rolledbackVers` - Rolled back versions relative to base.

#### markOwned

    public void markOwned(GridCacheVersion baseVer,
                          GridCacheVersion owned)

Puts owned versions in front of base.

Parameters:
  `baseVer` - Base version.
  `owned` - Owned list.

#### addLocal

    @Nullable
    public GridCacheMvccCandidate addLocal(GridCacheEntryEx parent,
                                                     long threadId,
                                                     GridCacheVersion ver,
                                                     long timeout,
                                                     boolean reenter,
                                                     boolean tx,
                                                     boolean implicitSingle,
                                                     boolean read)

Parameters:
  `parent` - Parent entry.
  `threadId` - Thread ID.
  `ver` - Lock version.
  `timeout` - Lock acquisition timeout.
  `reenter` - Reentry flag (`true` if reentry is allowed).
  `tx` - Transaction flag.
  `implicitSingle` - Implicit transaction flag.
  `read` - Read lock flag.
Returns:
  New lock candidate if lock was added, or current owner if lock was reentered, or `null` if lock was owned by another thread and timeout is negative.

#### addLocal

    @Nullable
    public GridCacheMvccCandidate addLocal(GridCacheEntryEx parent,
                                                     @Nullable
                                                     UUID nearNodeId,
                                                     @Nullable
                                                     GridCacheVersion nearVer,
                                                     long threadId,
                                                     GridCacheVersion ver,
                                                     long timeout,
                                                     @Nullable
                                                     GridCacheVersion serOrder,
                                                     boolean reenter,
                                                     boolean tx,
                                                     boolean implicitSingle,
                                                     boolean dhtLoc,
                                                     boolean read)

Parameters:
  `parent` - Parent entry.
  `nearNodeId` - Near node ID.
  `nearVer` - Near version.
  `threadId` - Thread ID.
  `ver` - Lock version.
  `timeout` - Lock acquisition timeout.
  `serOrder` - Version for serializable transactions ordering.
  `reenter` - Reentry flag (`true` if reentry is allowed).
  `tx` - Transaction flag.
  `implicitSingle` - Implicit flag.
  `dhtLoc` - DHT local flag.
  `read` - Read lock flag.
Returns:
  New lock candidate if lock was added, or current owner if lock was reentered, or `null` if lock was owned by another thread and timeout is negative.

#### addRemote

    public GridCacheMvccCandidate addRemote(GridCacheEntryEx parent,
                                            UUID nodeId,
                                            @Nullable
                                            UUID otherNodeId,
                                            long threadId,
                                            GridCacheVersion ver,
                                            boolean tx,
                                            boolean implicitSingle,
                                            boolean nearLoc)

Adds new remote lock candidate (either near remote or dht remote).

Parameters:
  `parent` - Parent entry.
  `nodeId` - Node ID.
  `otherNodeId` - Other node ID.
  `threadId` - Thread ID.
  `ver` - Lock version.
  `tx` - Transaction flag.
  `implicitSingle` - Implicit flag.
  `nearLoc` - Near local flag.
Returns:
  Add remote candidate.

#### addNearLocal

    public GridCacheMvccCandidate addNearLocal(GridCacheEntryEx parent,
                                               UUID nodeId,
                                               @Nullable
                                               UUID otherNodeId,
                                               long threadId,
                                               GridCacheVersion ver,
                                               boolean tx,
                                               boolean implicitSingle,
                                               boolean read)

Adds new near local lock candidate.

Parameters:
  `parent` - Parent entry.
  `nodeId` - Node ID.
  `otherNodeId` - Other node ID.
  `threadId` - Thread ID.
  `ver` - Lock version.
  `tx` - Transaction flag.
  `implicitSingle` - Implicit flag.
  `read` - Read lock flag.
Returns:
  Add remote candidate.

#### readyLocal

    @Nullable
    public CacheLockCandidates readyLocal(GridCacheVersion ver)

Parameters:
  `ver` - Lock version to acquire or set to ready.
Returns:
  Current owner.

#### readyLocal

    @Nullable
    public CacheLockCandidates readyLocal(GridCacheMvccCandidate cand)

Parameters:
  `cand` - Local candidate added in any of the `addLocal(..)` methods.
Returns:
  Current lock owner.

#### readyNearLocal

    @Nullable
    public CacheLockCandidates readyNearLocal(GridCacheVersion ver,
                                                        GridCacheVersion mappedVer,
                                                        Collection<GridCacheVersion> committedVers,
                                                        Collection<GridCacheVersion> rolledBackVers,
                                                        Collection<GridCacheVersion> pending)

Marks near-local candidate as ready and makes locks reassignment. Following reorderings are performed when candidate is marked ready:

All candidates preceding ready one are moved right after it.
Near local candidate is assigned a mapped dht version. All remote non-pending candidates with version less then mapped dht version are marked as owned.

Parameters:
  `ver` - Version to mark as ready.
  `mappedVer` - Mapped dht version.
  `committedVers` - Committed versions.
  `rolledBackVers` - Rolled back versions.
  `pending` - Pending dht versions that are not owned and which version is less then mapped.
Returns:
  Lock owner after reassignment.

#### doneRemote

    @Nullable
    public CacheLockCandidates doneRemote(GridCacheVersion ver,
                                                    Collection<GridCacheVersion> pending,
                                                    Collection<GridCacheVersion> committed,
                                                    Collection<GridCacheVersion> rolledback)

Sets remote candidate to done.

Parameters:
  `ver` - Version.
  `pending` - Pending versions.
  `committed` - Committed versions.
  `rolledback` - Rolledback versions.
Returns:
  Lock owner.

#### salvageRemote

    public void salvageRemote(GridCacheVersion ver)

For all remote candidates standing behind the candidate being salvaged marks their transactions as system invalidate and marks these candidates as owned and used.

Parameters:
  `ver` - Version to salvage.

#### recheck

    @Nullable
    public CacheLockCandidates recheck()

Checks if lock should be assigned.

Returns:
  Owner.

#### releaseLocal

    @Nullable
    public GridCacheMvccCandidate releaseLocal()

Local local release.

Returns:
  Removed candidate.

#### releaseLocal

    @Nullable
    public GridCacheMvccCandidate releaseLocal(long threadId)

Local release.

Parameters:
  `threadId` - ID of the thread.
Returns:
  Removed candidate.

#### remove

    public void remove(GridCacheVersion ver)

Removes lock even if it is not owner.

Parameters:
  `ver` - Lock version.

#### removeExplicitNodeCandidates

    @Nullable
    public CacheLockCandidates removeExplicitNodeCandidates(UUID nodeId)

Removes all candidates for node.

Parameters:
  `nodeId` - Node ID.
Returns:
  Current owner.

#### candidate

    @Nullable
    public GridCacheMvccCandidate candidate(GridCacheVersion ver)

Gets candidate for lock ID.

Parameters:
  `ver` - Lock version.
Returns:
  Candidate or `null` if there is no candidate for given ID.

#### localCandidate

    @Nullable
    public GridCacheMvccCandidate localCandidate(UUID nodeId,
                                                           long threadId)

Near local candidate.

Parameters:
  `nodeId` - Node ID.
  `threadId` - Thread ID.
Returns:
  Remote candidate.

#### localCandidatesNoCopy

    public List<GridCacheMvccCandidate> localCandidatesNoCopy(boolean reentry)

Parameters:
  `reentry` - Reentry flag.
Returns:
  Collection of local candidates.

#### localCandidates

    public Collection<GridCacheMvccCandidate> localCandidates(GridCacheVersion... excludeVers)

Parameters:
  `excludeVers` - Exclude versions.
Returns:
  Collection of local candidates.

#### localCandidates

    public List<GridCacheMvccCandidate> localCandidates(boolean reentries,
                                                        GridCacheVersion... excludeVers)

Parameters:
  `reentries` - Flag to include reentries.
  `excludeVers` - Exclude versions.
Returns:
  Collection of local candidates.

#### remoteCandidates

    public List<GridCacheMvccCandidate> remoteCandidates(GridCacheVersion... excludeVers)

Parameters:
  `excludeVers` - Exclude versions.
Returns:
  Collection of remote candidates.

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.7.5
Release Date | : June 4 2019