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. SeeGridCacheVersionManager.next(long topVer)for information on how lock IDs are generated to prevent starvation.
-
-
Constructor Summary
Constructors Constructor Description GridCacheMvcc(GridCacheContext<?,?> cctx)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @Nullable GridCacheMvccCandidateaddLocal(GridCacheEntryEx parent, long threadId, GridCacheVersion ver, long timeout, boolean reenter, boolean tx, boolean implicitSingle, boolean read)@Nullable GridCacheMvccCandidateaddLocal(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)GridCacheMvccCandidateaddNearLocal(GridCacheEntryEx parent, UUID nodeId, @Nullable UUID otherNodeId, long threadId, GridCacheVersion ver, boolean tx, boolean implicitSingle, boolean read)Adds new near local lock candidate.GridCacheMvccCandidateaddRemote(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).@Nullable CacheLockCandidatesallOwners()@Nullable GridCacheMvccCandidatecandidate(GridCacheVersion ver)Gets candidate for lock ID.@Nullable CacheLockCandidatesdoneRemote(GridCacheVersion ver, Collection<GridCacheVersion> pending, Collection<GridCacheVersion> committed, Collection<GridCacheVersion> rolledback)Sets remote candidate to done.booleanisEmpty(GridCacheVersion... exclude)@Nullable GridCacheMvccCandidatelocalCandidate(UUID nodeId, long threadId)Local candidate.@Nullable GridCacheMvccCandidatelocalCandidateByThreadOrVer(UUID nodeId, long threadId, GridCacheVersion ver)Local candidate.List<GridCacheMvccCandidate>localCandidates(boolean reentries, GridCacheVersion... excludeVers)Collection<GridCacheMvccCandidate>localCandidates(GridCacheVersion... excludeVers)List<GridCacheMvccCandidate>localCandidatesNoCopy(boolean reentry)@Nullable CacheLockCandidateslocalOwners()voidmarkOwned(GridCacheVersion baseVer, GridCacheVersion owned)Puts owned versions in front of base.voidorderCompleted(GridCacheVersion baseVer, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers)Moves completed candidates right before the base one.@Nullable CacheLockCandidatesreadyLocal(GridCacheMvccCandidate cand)@Nullable CacheLockCandidatesreadyLocal(GridCacheVersion ver)@Nullable CacheLockCandidatesreadyNearLocal(GridCacheVersion ver, GridCacheVersion mappedVer, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledBackVers, Collection<GridCacheVersion> pending)Marks near-local candidate as ready and makes locks reassignment.@Nullable CacheLockCandidatesrecheck()Checks if lock should be assigned.@Nullable GridCacheMvccCandidatereleaseLocal()Local local release.@Nullable GridCacheMvccCandidatereleaseLocal(long threadId)Local release.List<GridCacheMvccCandidate>remoteCandidates(GridCacheVersion... excludeVers)voidremove(GridCacheVersion ver)Removes lock even if it is not owner.@Nullable CacheLockCandidatesremoveExplicitNodeCandidates(UUID nodeId)Removes all candidates for node.voidsalvageRemote(GridCacheVersion ver, boolean near)For all remote candidates standing behind the candidate being salvaged marks their transactions as system invalidate and marks these candidates as owned and used.StringtoString()
-
-
-
Constructor Detail
-
GridCacheMvcc
public GridCacheMvcc(GridCacheContext<?,?> cctx)
- Parameters:
cctx- Cache context.
-
-
Method Detail
-
allOwners
@Nullable public @Nullable CacheLockCandidates allOwners()
- Returns:
- All owners.
-
localOwners
@Nullable public @Nullable CacheLockCandidates localOwners()
- Returns:
- All local owners.
-
isEmpty
public boolean isEmpty(GridCacheVersion... exclude)
- Parameters:
exclude- Versions to exclude form check.- Returns:
Trueif 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 andfalseis 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 @Nullable 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 (trueif 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 @Nullable GridCacheMvccCandidate addLocal(GridCacheEntryEx parent, @Nullable @Nullable UUID nearNodeId, @Nullable @Nullable GridCacheVersion nearVer, long threadId, GridCacheVersion ver, long timeout, @Nullable @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 (trueif 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 @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 @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 @Nullable CacheLockCandidates readyLocal(GridCacheVersion ver)
- Parameters:
ver- Lock version to acquire or set to ready.- Returns:
- Current owner.
-
readyLocal
@Nullable public @Nullable CacheLockCandidates readyLocal(GridCacheMvccCandidate cand)
- Parameters:
cand- Local candidate added in any of theaddLocal(..)methods.- Returns:
- Current lock owner.
-
readyNearLocal
@Nullable public @Nullable 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 @Nullable 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, boolean near)
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.near-TrueIf salvage near cache candidate.
-
recheck
@Nullable public @Nullable CacheLockCandidates recheck()
Checks if lock should be assigned.- Returns:
- Owner.
-
releaseLocal
@Nullable public @Nullable GridCacheMvccCandidate releaseLocal()
Local local release.- Returns:
- Removed candidate.
-
releaseLocal
@Nullable public @Nullable 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 @Nullable CacheLockCandidates removeExplicitNodeCandidates(UUID nodeId)
Removes all candidates for node.- Parameters:
nodeId- Node ID.- Returns:
- Current owner.
-
candidate
@Nullable public @Nullable 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 @Nullable GridCacheMvccCandidate localCandidate(UUID nodeId, long threadId)
Local candidate.- Parameters:
nodeId- Node ID.threadId- Thread ID.- Returns:
- Local candidate.
-
localCandidateByThreadOrVer
@Nullable public @Nullable GridCacheMvccCandidate localCandidateByThreadOrVer(UUID nodeId, long threadId, GridCacheVersion ver)
Local candidate.- Parameters:
nodeId- Node ID.threadId- Thread ID.ver- Lock version.- Returns:
- Local 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.
-
-