Search in sources :

Example 11 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();
    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 12 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 synchronized GridCacheMvccCandidate dhtNodeId(GridCacheVersion ver, UUID dhtNodeId) throws GridCacheEntryRemovedException {
    checkObsolete();
    GridCacheMvcc mvcc = mvccExtras();
    GridCacheMvccCandidate cand = mvcc == null ? null : mvcc.candidate(ver);
    if (cand == null)
        return null;
    cand.otherNodeId(dhtNodeId);
    return cand;
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) Nullable(org.jetbrains.annotations.Nullable)

Example 13 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;
    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 14 with GridCacheMvcc

use of org.apache.ignite.internal.processors.cache.GridCacheMvcc 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)

Example 15 with GridCacheMvcc

use of org.apache.ignite.internal.processors.cache.GridCacheMvcc 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)

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