Search in sources :

Example 11 with GridCacheMvccCandidate

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

the class GridDistributedCacheEntry method remoteMvccSnapshot.

/**
 * {@inheritDoc}
 */
@Override
public Collection<GridCacheMvccCandidate> remoteMvccSnapshot(GridCacheVersion... exclude) {
    Collection<GridCacheMvccCandidate> rmts = this.rmts;
    if (rmts.isEmpty() || F.isEmpty(exclude))
        return rmts;
    Collection<GridCacheMvccCandidate> cands = new ArrayList<>(rmts.size());
    for (GridCacheMvccCandidate c : rmts) {
        assert !c.reentry();
        // Don't include reentries.
        if (!U.containsObjectArray(exclude, c.version()))
            cands.add(c);
    }
    return cands;
}
Also used : ArrayList(java.util.ArrayList) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 12 with GridCacheMvccCandidate

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

the class GridDistributedCacheEntry method checkThreadChain.

/**
 * {@inheritDoc}
 */
@Override
protected final void checkThreadChain(GridCacheMvccCandidate owner) {
    assert !lockedByCurrentThread();
    assert owner != null;
    assert owner.owner() || owner.used() : "Neither owner or used flags are set on ready local candidate: " + owner;
    if (owner.local() && owner.next() != null) {
        for (GridCacheMvccCandidate cand = owner.next(); cand != null; cand = cand.next()) {
            assert cand.local() : "Remote candidate cannot be part of thread chain: " + cand;
            // Allow next lock in the thread to proceed.
            if (!cand.used()) {
                if (cand.owner())
                    break;
                GridCacheContext cctx0 = cand.parent().context();
                GridDistributedCacheEntry e = (GridDistributedCacheEntry) cctx0.cache().peekEx(cand.parent().key());
                // At this point candidate may have been removed and entry destroyed, so we check for null.
                if (e == null || e.recheck(owner.version()))
                    break;
            }
        }
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 13 with GridCacheMvccCandidate

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

the class GridLocalLockFuture method addEntries.

/**
 * @param keys Keys.
 * @return {@code False} in case of error.
 * @throws IgniteCheckedException If failed.
 */
public boolean addEntries(Collection<KeyCacheObject> keys) throws IgniteCheckedException {
    for (KeyCacheObject key : keys) {
        while (true) {
            GridLocalCacheEntry entry = null;
            try {
                entry = cache.entryExx(key);
                entry.unswap(false);
                if (!cctx.isAll(entry, filter)) {
                    onFailed();
                    return false;
                }
                // Removed exception may be thrown here.
                GridCacheMvccCandidate cand = addEntry(entry);
                if (cand == null && isDone())
                    return false;
                break;
            } catch (GridCacheEntryRemovedException ignored) {
                if (log.isDebugEnabled())
                    log.debug("Got removed entry in lockAsync(..) method (will retry): " + entry);
            }
        }
    }
    if (timeout > 0) {
        timeoutObj = new LockTimeoutObject();
        cctx.time().addTimeoutObject(timeoutObj);
    }
    return true;
}
Also used : GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 14 with GridCacheMvccCandidate

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

the class GridLocalCacheEntry method releaseLocal.

/**
 * Releases local lock.
 *
 * @param threadId Thread ID.
 */
private void releaseLocal(long threadId) {
    CacheObject val;
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    lockEntry();
    try {
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.localOwners();
            mvcc.releaseLocal(threadId);
            if (mvcc.isEmpty())
                mvccExtras(null);
            else
                owner = mvcc.allOwners();
        }
        val = this.val;
    } finally {
        unlockEntry();
    }
    if (prev != null) {
        for (int i = 0; i < prev.size(); i++) {
            GridCacheMvccCandidate cand = prev.candidate(i);
            boolean unlocked = owner == null || !owner.hasCandidate(cand.version());
            if (unlocked)
                checkThreadChain(cand);
        }
    }
    checkOwnerChanged(prev, owner, val);
}
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)

Example 15 with GridCacheMvccCandidate

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

the class GridLocalCacheEntry method checkThreadChain.

/**
 * {@inheritDoc}
 */
@Override
protected void checkThreadChain(GridCacheMvccCandidate owner) {
    assert !lockedByCurrentThread();
    assert owner != null;
    assert owner.owner() || owner.used() : "Neither owner or used flags are set on ready local candidate: " + owner;
    if (owner.next() != null) {
        for (GridCacheMvccCandidate cand = owner.next(); cand != null; cand = cand.next()) {
            assert cand.local();
            // Allow next lock in the thread to proceed.
            if (!cand.used()) {
                GridCacheContext cctx0 = cand.parent().context();
                GridLocalCacheEntry e = (GridLocalCacheEntry) cctx0.cache().peekEx(cand.parent().key());
                // At this point candidate may have been removed and entry destroyed, so we check for null.
                if (e == null || e.recheck(owner.version()))
                    break;
            }
        }
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Aggregations

GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)41 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)17 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)15 Nullable (org.jetbrains.annotations.Nullable)14 GridCacheMvcc (org.apache.ignite.internal.processors.cache.GridCacheMvcc)13 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)11 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 CacheLockCandidates (org.apache.ignite.internal.processors.cache.CacheLockCandidates)9 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)6 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)6 UUID (java.util.UUID)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)5 GridDistributedCacheEntry (org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry)5 Collection (java.util.Collection)4