Search in sources :

Example 16 with CacheLockCandidates

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

the class GridDistributedCacheEntry method removeLock.

/**
     * Unlocks local lock.
     *
     * @return Removed candidate, or <tt>null</tt> if thread still holds the lock.
     */
@Nullable
public GridCacheMvccCandidate removeLock() {
    GridCacheMvccCandidate rmvd = null;
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    CacheObject val;
    synchronized (this) {
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.allOwners();
            boolean emptyBefore = mvcc.isEmpty();
            rmvd = mvcc.releaseLocal();
            boolean emptyAfter = mvcc.isEmpty();
            checkCallbacks(emptyBefore, emptyAfter);
            if (emptyAfter)
                mvccExtras(null);
            else
                owner = mvcc.allOwners();
        }
        val = this.val;
    }
    if (log.isDebugEnabled()) {
        log.debug("Released local candidate from entry [owner=" + owner + ", prev=" + prev + ", rmvd=" + rmvd + ", entry=" + this + ']');
    }
    if (prev != null) {
        for (int i = 0; i < prev.size(); i++) {
            GridCacheMvccCandidate cand = prev.candidate(i);
            checkThreadChain(cand);
        }
    }
    // This call must be outside of synchronization.
    checkOwnerChanged(prev, owner, val);
    return rmvd;
}
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) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with CacheLockCandidates

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

the class GridLocalCacheEntry method removeLock.

/** {@inheritDoc} */
@Override
public boolean removeLock(GridCacheVersion ver) throws GridCacheEntryRemovedException {
    CacheObject val;
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    GridCacheMvccCandidate doomed;
    synchronized (this) {
        GridCacheVersion obsoleteVer = obsoleteVersionExtras();
        if (obsoleteVer != null && !obsoleteVer.equals(ver))
            checkObsolete();
        GridCacheMvcc mvcc = mvccExtras();
        doomed = mvcc == null ? null : mvcc.candidate(ver);
        if (doomed != null) {
            prev = mvcc.allOwners();
            mvcc.remove(ver);
            if (mvcc.isEmpty())
                mvccExtras(null);
            else
                owner = mvcc.allOwners();
        }
        val = this.val;
    }
    if (doomed != null)
        checkThreadChain(doomed);
    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) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 18 with CacheLockCandidates

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

the class GridLocalCacheEntry method addLocal.

/**
     * Add local candidate.
     *
     * @param threadId Owning thread ID.
     * @param ver Lock version.
     * @param serOrder Version for serializable transactions ordering.
     * @param serReadVer Optional read entry version for optimistic serializable transaction.
     * @param timeout Timeout to acquire lock.
     * @param reenter Reentry flag.
     * @param tx Transaction flag.
     * @param implicitSingle Implicit transaction flag.
     * @param read Read lock flag.
     * @return New candidate.
     * @throws GridCacheEntryRemovedException If entry has been removed.
     */
@Nullable
GridCacheMvccCandidate addLocal(long threadId, GridCacheVersion ver, @Nullable GridCacheVersion serOrder, @Nullable GridCacheVersion serReadVer, long timeout, boolean reenter, boolean tx, boolean implicitSingle, boolean read) throws GridCacheEntryRemovedException {
    assert serReadVer == null || serOrder != null;
    CacheObject val;
    GridCacheMvccCandidate cand;
    CacheLockCandidates prev;
    CacheLockCandidates owner = null;
    synchronized (this) {
        checkObsolete();
        if (serReadVer != null) {
            if (!checkSerializableReadVersion(serReadVer))
                return null;
        }
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc == null) {
            mvcc = new GridCacheMvcc(cctx);
            mvccExtras(mvcc);
        }
        prev = mvcc.localOwners();
        cand = mvcc.addLocal(this, /*nearNodeId*/
        null, /*nearVer*/
        null, threadId, ver, timeout, serOrder, reenter, tx, implicitSingle, /*dht-local*/
        false, read);
        if (mvcc.isEmpty())
            mvccExtras(null);
        else
            owner = mvcc.localOwners();
        val = this.val;
    }
    if (cand != null && !cand.reentry())
        cctx.mvcc().addNext(cctx, cand);
    checkOwnerChanged(prev, owner, val);
    return cand;
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) Nullable(org.jetbrains.annotations.Nullable)

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