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 Modifier and Type Field Description static intDFLT_MAX_NESTED_LISTENER_CALLSprotected AtomicLongglobalAtomicCntGlobal atomic id counter.protected static intTHREAD_RESERVE_SIZEMaxim number of atomic IDs for thread.-
Fields inherited from class org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter
cctx, diagnosticLog, log
-
-
Constructor Summary
Constructors Constructor Description GridCacheMvccManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection<GridCacheExplicitLockSpan>activeExplicitLocks()Collection<GridCacheFuture<?>>activeFutures()booleanaddAtomicFuture(long futId, GridCacheAtomicFuture<?> fut)GridFutureAdapteraddDataStreamerFuture(AffinityTopologyVersion topVer)voidaddExplicitLock(long threadId, GridCacheMvccCandidate cand, AffinityTopologyVersion topVer)Adds candidate to the list of near local candidates.booleanaddFuture(GridCacheFuture<?> fut, IgniteUuid futId)booleanaddFuture(GridCacheVersionedFuture<?> fut)/** Adds future.booleanaddNext(GridCacheContext cacheCtx, GridCacheMvccCandidate cand)booleanaddRemoved(GridCacheContext cacheCtx, GridCacheVersion ver)@Nullable IgniteInternalFuture<?>atomicFuture(long futId)Gets future by given future ID.Collection<GridCacheAtomicFuture<?>>atomicFutures()intatomicFuturesCount()GridCacheLockCallbackcallback()voidcontextReset()Reset MVCC context.Collection<org.apache.ignite.internal.processors.cache.GridCacheMvccManager.DataStreamerFuture>dataStreamerFutures()@Nullable GridCacheMvccCandidateexplicitLock(long threadId, IgniteTxKey key)Gets last added explicit lock candidate by thread id and key.@Nullable GridCacheMvccCandidateexplicitLock(IgniteTxKey key, @Nullable GridCacheVersion ver)Gets explicit lock candidate added by any thread by given key and lock version.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 totopVer.@Nullable GridCacheFuturefuture(IgniteUuid futId)@Nullable Collection<GridCacheVersionedFuture<?>>futuresForVersion(GridCacheVersion ver)Gets futures for given lock ID.booleanisLockedByThread(IgniteTxKey key, long threadId)Checks if given key is locked by thread with given id or any thread.booleanisRemoved(GridCacheContext cacheCtx, GridCacheVersion ver)@Nullable AffinityTopologyVersionlastExplicitLockTopologyVersion(long threadId)Collection<GridCacheMvccCandidate>localCandidates()This method has poor performance, so use with care.Collection<IgniteTxKey>lockedKeys()GridCacheVersionmappedVersion(GridCacheVersion from)voidmapVersion(GridCacheVersion from, GridCacheVersion to)voidmarkExplicitOwner(IgniteTxKey key, long threadId)Marks candidates for given thread and given key as owned.Collection<IgniteTxKey>nearLockedKeys()longnextAtomicId()voidonDisconnected(IgniteFuture reconnectFut)voidonKernalStop0(boolean cancel)voidonStop()Cancels all client futures.voidprintMemoryStats()Prints memory statistics (sizes of internal data structures, etc.).voidrecheckPendingLocks()Collection<GridCacheMvccCandidate>remoteCandidates()This method has poor performance, so use with care.@Nullable IgniteInternalFuture<?>removeAtomicFuture(long futId)GridCacheMvccCandidateremoveExplicitLock(long threadId, IgniteTxKey key, @Nullable GridCacheVersion ver)Removes explicit lock for given thread id, key and optional version.voidremoveExplicitLock(GridCacheMvccCandidate cand)Removes candidate from the list of near local candidates.voidremoveExplicitNodeLocks(UUID leftNodeId)voidremoveFuture(IgniteUuid futId)booleanremoveVersionedFuture(GridCacheVersionedFuture<?> fut)protected voidstart0()Map<IgniteTxKey,Collection<GridCacheMvccCandidate>>unfinishedLocks(AffinityTopologyVersion topVer)GridCacheVersionunmapVersion(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, onKernalStart, onKernalStart0, onKernalStop, onReconnected, start, startInfo, stop, stop0, stopInfo, toString
-
-
-
-
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
-
globalAtomicCnt
protected final AtomicLong globalAtomicCnt
Global atomic id counter.
-
-
Method Detail
-
start0
protected void start0() throws IgniteCheckedException- Overrides:
start0in classGridCacheSharedManagerAdapter- Throws:
IgniteCheckedException- If failed.
-
onKernalStop0
public void onKernalStop0(boolean cancel)
- Overrides:
onKernalStop0in classGridCacheSharedManagerAdapter- 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 totopVer.- Parameters:
topVer- Topology version.- Returns:
- Compound future of all
GridDhtTxFinishFuturefutures.
-
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:
onDisconnectedin interfaceGridCacheSharedManager- Overrides:
onDisconnectedin classGridCacheSharedManagerAdapter- 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:
Falseif 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:
Trueif 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:
Trueif added.
-
removeFuture
public void removeFuture(IgniteUuid futId)
- Parameters:
futId- Future ID.
-
removeVersionedFuture
public boolean removeVersionedFuture(GridCacheVersionedFuture<?> fut)
- Parameters:
fut- Future to remove.- Returns:
Trueif 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:
Trueif lock had been removed.
-
addRemoved
public boolean addRemoved(GridCacheContext cacheCtx, GridCacheVersion ver)
- Parameters:
cacheCtx- Cache context.ver- Obsolete entry version.- Returns:
Trueif 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 byDGC.- Returns:
- Remote candidates.
-
localCandidates
public Collection<GridCacheMvccCandidate> localCandidates()
This method has poor performance, so use with care. It is currently only used byDGC.- Returns:
- Local candidates.
-
addNext
public boolean addNext(GridCacheContext cacheCtx, GridCacheMvccCandidate cand)
- Parameters:
cacheCtx- Cache context.cand- Cache lock candidate to add.- Returns:
Trueif added as a result of this operation,falseif 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:
Trueif locked by any or given thread (depending onthreadIdvalue).
-
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
nullif 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
nullif 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:
printMemoryStatsin interfaceGridCacheSharedManager- Overrides:
printMemoryStatsin classGridCacheSharedManagerAdapter
-
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.
-
-