Search in sources :

Example 6 with CacheLockCandidates

use of org.apache.ignite.internal.processors.cache.CacheLockCandidates 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;
    synchronized (this) {
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.localOwners();
            mvcc.releaseLocal(threadId);
            if (mvcc.isEmpty())
                mvccExtras(null);
            else
                owner = mvcc.allOwners();
        }
        val = this.val;
    }
    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 7 with CacheLockCandidates

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

the class GridNearCacheEntry method addNearLocal.

/**
     * Add near local candidate.
     *
     * @param dhtNodeId DHT node ID.
     * @param threadId Owning thread ID.
     * @param ver Lock version.
     * @param topVer Topology version.
     * @param timeout Timeout to acquire lock.
     * @param reenter Reentry flag.
     * @param tx Transaction flag.
     * @param implicitSingle Implicit flag.
     * @param read Read lock flag.
     * @return New candidate.
     * @throws GridCacheEntryRemovedException If entry has been removed.
     */
@Nullable
GridCacheMvccCandidate addNearLocal(@Nullable UUID dhtNodeId, long threadId, GridCacheVersion ver, AffinityTopologyVersion topVer, long timeout, boolean reenter, boolean tx, boolean implicitSingle, boolean read) throws GridCacheEntryRemovedException {
    CacheLockCandidates prev;
    CacheLockCandidates owner = null;
    GridCacheMvccCandidate cand;
    CacheObject val;
    UUID locId = cctx.nodeId();
    synchronized (this) {
        checkObsolete();
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc == null) {
            mvcc = new GridCacheMvcc(cctx);
            mvccExtras(mvcc);
        }
        GridCacheMvccCandidate c = mvcc.localCandidate(locId, threadId);
        if (c != null)
            return reenter ? c.reenter() : null;
        prev = mvcc.allOwners();
        boolean emptyBefore = mvcc.isEmpty();
        // Lock could not be acquired.
        if (timeout < 0 && !emptyBefore)
            return null;
        // Local lock for near cache is a local lock.
        cand = mvcc.addNearLocal(this, locId, dhtNodeId, threadId, ver, tx, implicitSingle, read);
        cand.topologyVersion(topVer);
        boolean emptyAfter = mvcc.isEmpty();
        checkCallbacks(emptyBefore, emptyAfter);
        val = this.val;
        if (emptyAfter)
            mvccExtras(null);
        else
            owner = mvcc.allOwners();
    }
    // This call must be outside of synchronization.
    checkOwnerChanged(prev, owner, val);
    return cand;
}
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) UUID(java.util.UUID) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with CacheLockCandidates

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

the class GridDhtTxPrepareFuture method readyLocks.

/**
     * @param checkEntries Entries.
     */
private void readyLocks(Iterable<IgniteTxEntry> checkEntries) {
    for (IgniteTxEntry txEntry : checkEntries) {
        GridCacheContext cacheCtx = txEntry.context();
        if (cacheCtx.isLocal())
            continue;
        GridDistributedCacheEntry entry = (GridDistributedCacheEntry) txEntry.cached();
        if (entry == null) {
            entry = (GridDistributedCacheEntry) cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion());
            txEntry.cached(entry);
        }
        if (tx.optimistic() && txEntry.explicitVersion() == null) {
            synchronized (this) {
                lockKeys.add(txEntry.txKey());
            }
        }
        while (true) {
            try {
                assert txEntry.explicitVersion() == null || entry.lockedBy(txEntry.explicitVersion());
                CacheLockCandidates owners = entry.readyLock(tx.xidVersion());
                if (log.isDebugEnabled())
                    log.debug("Current lock owners for entry [owner=" + owners + ", entry=" + entry + ']');
                // While.
                break;
            }// Possible if entry cached within transaction is obsolete.
             catch (GridCacheEntryRemovedException ignored) {
                if (log.isDebugEnabled())
                    log.debug("Got removed entry in future onAllReplies method (will retry): " + txEntry);
                entry = (GridDistributedCacheEntry) cacheCtx.cache().entryEx(txEntry.key(), tx.topologyVersion());
                txEntry.cached(entry);
            }
        }
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridDistributedCacheEntry(org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheEntry) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates)

Example 9 with CacheLockCandidates

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

the class GridDhtCacheEntry method addDhtLocal.

/**
     * Add local candidate.
     *
     * @param nearNodeId Near node ID.
     * @param nearVer Near version.
     * @param topVer Topology version.
     * @param threadId Owning thread ID.
     * @param ver Lock version.
     * @param serOrder Version for serializable transactions ordering.
     * @param timeout Timeout to acquire lock.
     * @param reenter Reentry flag.
     * @param tx Tx flag.
     * @param implicitSingle Implicit flag.
     * @param read Read lock flag.
     * @return New candidate.
     * @throws GridCacheEntryRemovedException If entry has been removed.
     * @throws GridDistributedLockCancelledException If lock was cancelled.
     */
@Nullable
GridCacheMvccCandidate addDhtLocal(UUID nearNodeId, GridCacheVersion nearVer, AffinityTopologyVersion topVer, long threadId, GridCacheVersion ver, @Nullable GridCacheVersion serOrder, long timeout, boolean reenter, boolean tx, boolean implicitSingle, boolean read) throws GridCacheEntryRemovedException, GridDistributedLockCancelledException {
    assert !reenter || serOrder == null;
    GridCacheMvccCandidate cand;
    CacheLockCandidates prev;
    CacheLockCandidates owner;
    CacheObject val;
    synchronized (this) {
        // Check removed locks prior to obsolete flag.
        checkRemoved(ver);
        checkRemoved(nearVer);
        checkObsolete();
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc == null) {
            mvcc = new GridCacheMvcc(cctx);
            mvccExtras(mvcc);
        }
        prev = mvcc.allOwners();
        boolean emptyBefore = mvcc.isEmpty();
        cand = mvcc.addLocal(this, nearNodeId, nearVer, threadId, ver, timeout, serOrder, reenter, tx, implicitSingle, /*dht-local*/
        true, read);
        if (cand == null)
            return null;
        cand.topologyVersion(topVer);
        owner = mvcc.allOwners();
        if (owner != null)
            cand.ownerVersion(owner.candidate(0).version());
        boolean emptyAfter = mvcc.isEmpty();
        checkCallbacks(emptyBefore, emptyAfter);
        val = this.val;
        if (mvcc.isEmpty())
            mvccExtras(null);
    }
    // Don't link reentries.
    if (!cand.reentry())
        // Link with other candidates in the same thread.
        cctx.mvcc().addNext(cctx, cand);
    checkOwnerChanged(prev, owner, val);
    return cand;
}
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 10 with CacheLockCandidates

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

the class GridDistributedCacheEntry method addLocal.

/**
     * Add local candidate.
     *
     * @param threadId Owning thread ID.
     * @param ver Lock version.
     * @param topVer Topology version.
     * @param timeout Timeout to acquire lock.
     * @param reenter Reentry flag.
     * @param tx Transaction flag.
     * @param implicitSingle Implicit flag.
     * @param read Read lock flag.
     * @return New candidate.
     * @throws GridCacheEntryRemovedException If entry has been removed.
     */
@Nullable
public GridCacheMvccCandidate addLocal(long threadId, GridCacheVersion ver, AffinityTopologyVersion topVer, long timeout, boolean reenter, boolean tx, boolean implicitSingle, boolean read) throws GridCacheEntryRemovedException {
    GridCacheMvccCandidate cand;
    CacheLockCandidates prev;
    CacheLockCandidates owner;
    CacheObject val;
    synchronized (this) {
        checkObsolete();
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc == null) {
            mvcc = new GridCacheMvcc(cctx);
            mvccExtras(mvcc);
        }
        prev = mvcc.allOwners();
        boolean emptyBefore = mvcc.isEmpty();
        cand = mvcc.addLocal(this, threadId, ver, timeout, reenter, tx, implicitSingle, read);
        if (cand != null)
            cand.topologyVersion(topVer);
        owner = mvcc.allOwners();
        boolean emptyAfter = mvcc.isEmpty();
        checkCallbacks(emptyBefore, emptyAfter);
        val = this.val;
        if (emptyAfter)
            mvccExtras(null);
    }
    // Don't link reentries.
    if (cand != null && !cand.reentry())
        // Link with other candidates in the same thread.
        cctx.mvcc().addNext(cctx, cand);
    checkOwnerChanged(prev, owner, val);
    return cand;
}
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)

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