Search in sources :

Example 16 with GridCacheMvcc

use of org.apache.ignite.internal.processors.cache.GridCacheMvcc 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;
    lockEntry();
    try {
        // 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);
    } finally {
        unlockEntry();
    }
    // 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 17 with GridCacheMvcc

use of org.apache.ignite.internal.processors.cache.GridCacheMvcc 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;
    lockEntry();
    try {
        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;
    } finally {
        unlockEntry();
    }
    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 18 with GridCacheMvcc

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

the class GridNearCacheEntry method dhtNodeId.

/**
 * @param ver Version to set DHT node ID for.
 * @param dhtNodeId DHT node ID.
 * @return {@code true} if candidate was found.
 * @throws GridCacheEntryRemovedException If entry is removed.
 */
@Nullable
public GridCacheMvccCandidate dhtNodeId(GridCacheVersion ver, UUID dhtNodeId) throws GridCacheEntryRemovedException {
    lockEntry();
    try {
        checkObsolete();
        GridCacheMvcc mvcc = mvccExtras();
        GridCacheMvccCandidate cand = mvcc == null ? null : mvcc.candidate(ver);
        if (cand == null)
            return null;
        cand.otherNodeId(dhtNodeId);
        return cand;
    } finally {
        unlockEntry();
    }
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with GridCacheMvcc

use of org.apache.ignite.internal.processors.cache.GridCacheMvcc 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();
    lockEntry();
    try {
        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();
    } finally {
        unlockEntry();
    }
    // 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 20 with GridCacheMvcc

use of org.apache.ignite.internal.processors.cache.GridCacheMvcc 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;
    lockEntry();
    try {
        // 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);
    } finally {
        unlockEntry();
    }
    // 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)

Aggregations

GridCacheMvcc (org.apache.ignite.internal.processors.cache.GridCacheMvcc)22 CacheLockCandidates (org.apache.ignite.internal.processors.cache.CacheLockCandidates)17 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)17 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)17 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)14 Nullable (org.jetbrains.annotations.Nullable)10 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 UUID (java.util.UUID)2