Search in sources :

Example 11 with CacheLockCandidates

use of org.apache.ignite.internal.processors.cache.CacheLockCandidates in project ignite by apache.

the class GridDistributedCacheEntry method removeExplicitNodeLocks.

/**
     * Removes all lock candidates for node.
     *
     * @param nodeId ID of node to remove locks from.
     * @throws GridCacheEntryRemovedException If entry was removed.
     */
public void removeExplicitNodeLocks(UUID nodeId) throws GridCacheEntryRemovedException {
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    CacheObject val = null;
    synchronized (this) {
        checkObsolete();
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.allOwners();
            boolean emptyBefore = mvcc.isEmpty();
            owner = mvcc.removeExplicitNodeCandidates(nodeId);
            boolean emptyAfter = mvcc.isEmpty();
            checkCallbacks(emptyBefore, emptyAfter);
            val = this.val;
            refreshRemotes();
            if (emptyAfter) {
                mvccExtras(null);
                onUnlock();
            }
        }
    }
    // This call must be outside of synchronization.
    checkOwnerChanged(prev, owner, val);
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 12 with CacheLockCandidates

use of org.apache.ignite.internal.processors.cache.CacheLockCandidates in project ignite by apache.

the class GridDistributedCacheEntry method addRemote.

/**
     * Adds new lock candidate.
     *
     * @param nodeId Node ID.
     * @param otherNodeId Other node ID.
     * @param threadId Thread ID.
     * @param ver Lock version.
     * @param tx Transaction flag.
     * @param implicitSingle Implicit flag.
     * @param owned Owned candidate version.
     * @throws GridDistributedLockCancelledException If lock has been canceled.
     * @throws GridCacheEntryRemovedException If this entry is obsolete.
     */
public void addRemote(UUID nodeId, @Nullable UUID otherNodeId, long threadId, GridCacheVersion ver, boolean tx, boolean implicitSingle, @Nullable GridCacheVersion owned) throws GridDistributedLockCancelledException, GridCacheEntryRemovedException {
    CacheLockCandidates prev;
    CacheLockCandidates owner;
    CacheObject val;
    synchronized (this) {
        // Check removed locks prior to obsolete flag.
        checkRemoved(ver);
        checkObsolete();
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc == null) {
            mvcc = new GridCacheMvcc(cctx);
            mvccExtras(mvcc);
        }
        prev = mvcc.allOwners();
        boolean emptyBefore = mvcc.isEmpty();
        mvcc.addRemote(this, nodeId, otherNodeId, threadId, ver, tx, implicitSingle, /*near-local*/
        false);
        if (owned != null)
            mvcc.markOwned(ver, owned);
        owner = mvcc.allOwners();
        boolean emptyAfter = mvcc.isEmpty();
        checkCallbacks(emptyBefore, emptyAfter);
        val = this.val;
        refreshRemotes();
        if (emptyAfter)
            mvccExtras(null);
    }
    // This call must be outside of synchronization.
    checkOwnerChanged(prev, owner, val);
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 13 with CacheLockCandidates

use of org.apache.ignite.internal.processors.cache.CacheLockCandidates in project ignite by apache.

the class GridDistributedCacheEntry method readyLock.

/**
     *
     * @param ver Version of candidate to acquire lock for.
     * @return Owner.
     * @throws GridCacheEntryRemovedException If entry is removed.
     */
@Nullable
public CacheLockCandidates readyLock(GridCacheVersion ver) throws GridCacheEntryRemovedException {
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    CacheObject val;
    synchronized (this) {
        checkObsolete();
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.allOwners();
            boolean emptyBefore = mvcc.isEmpty();
            owner = mvcc.readyLocal(ver);
            assert owner == null || owner.candidate(0).owner() : "Owner flag not set for owner: " + owner;
            boolean emptyAfter = mvcc.isEmpty();
            checkCallbacks(emptyBefore, emptyAfter);
            if (emptyAfter)
                mvccExtras(null);
        }
        val = this.val;
    }
    // This call must be made outside of synchronization.
    checkOwnerChanged(prev, owner, val);
    return owner;
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with CacheLockCandidates

use of org.apache.ignite.internal.processors.cache.CacheLockCandidates in project ignite by apache.

the class GridDistributedCacheEntry method readyNearLock.

/**
     * Notifies mvcc that near local lock is ready to be acquired.
     *
     * @param ver Lock version.
     * @param mapped Mapped dht lock version.
     * @param committed Committed versions.
     * @param rolledBack Rolled back versions.
     * @param pending Pending locks on dht node with version less then mapped.
     *
     * @throws GridCacheEntryRemovedException If entry is removed.
     */
public void readyNearLock(GridCacheVersion ver, GridCacheVersion mapped, Collection<GridCacheVersion> committed, Collection<GridCacheVersion> rolledBack, Collection<GridCacheVersion> pending) throws GridCacheEntryRemovedException {
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    CacheObject val;
    synchronized (this) {
        checkObsolete();
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.allOwners();
            boolean emptyBefore = mvcc.isEmpty();
            owner = mvcc.readyNearLocal(ver, mapped, committed, rolledBack, pending);
            assert owner == null || owner.candidate(0).owner() : "Owner flag is not set for owner: " + owner;
            boolean emptyAfter = mvcc.isEmpty();
            checkCallbacks(emptyBefore, emptyAfter);
            if (emptyAfter)
                mvccExtras(null);
        }
        val = this.val;
    }
    // This call must be made outside of synchronization.
    checkOwnerChanged(prev, owner, val);
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 15 with CacheLockCandidates

use of org.apache.ignite.internal.processors.cache.CacheLockCandidates in project ignite by apache.

the class GridDistributedCacheEntry method removeLock.

/** {@inheritDoc} */
@Override
public boolean removeLock(GridCacheVersion ver) throws GridCacheEntryRemovedException {
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    GridCacheMvccCandidate doomed;
    CacheObject val;
    synchronized (this) {
        GridCacheMvcc mvcc = mvccExtras();
        doomed = mvcc == null ? null : mvcc.candidate(ver);
        if (doomed == null)
            addRemoved(ver);
        GridCacheVersion obsoleteVer = obsoleteVersionExtras();
        if (obsoleteVer != null && !obsoleteVer.equals(ver))
            checkObsolete();
        if (doomed != null) {
            prev = mvcc.allOwners();
            boolean emptyBefore = mvcc.isEmpty();
            mvcc.remove(doomed.version());
            boolean emptyAfter = mvcc.isEmpty();
            if (!doomed.local())
                refreshRemotes();
            checkCallbacks(emptyBefore, emptyAfter);
            if (emptyAfter)
                mvccExtras(null);
            else
                owner = mvcc.allOwners();
        }
        val = this.val;
    }
    if (log.isDebugEnabled())
        log.debug("Removed lock candidate from entry [doomed=" + doomed + ", owner=" + owner + ", prev=" + prev + ", entry=" + this + ']');
    if (doomed != null && doomed.nearLocal())
        cctx.mvcc().removeExplicitLock(doomed);
    if (doomed != null)
        checkThreadChain(doomed);
    // This call must be outside of synchronization.
    checkOwnerChanged(prev, owner, val);
    return doomed != null;
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Aggregations

CacheLockCandidates (org.apache.ignite.internal.processors.cache.CacheLockCandidates)18 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)17 GridCacheMvcc (org.apache.ignite.internal.processors.cache.GridCacheMvcc)17 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)17 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)9 Nullable (org.jetbrains.annotations.Nullable)7 UUID (java.util.UUID)2 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)2 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)1 GridDistributedCacheEntry (org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry)1 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)1