Search in sources :

Example 66 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.

the class GridNearAtomicSingleUpdateFuture method onPrimaryResponse.

/**
 * {@inheritDoc}
 */
@SuppressWarnings({ "unchecked", "ThrowableResultOfMethodCallIgnored" })
@Override
public void onPrimaryResponse(UUID nodeId, GridNearAtomicUpdateResponse res, boolean nodeErr) {
    GridNearAtomicAbstractUpdateRequest req;
    AffinityTopologyVersion remapTopVer0;
    GridCacheReturn opRes0 = null;
    CachePartialUpdateCheckedException err0 = null;
    synchronized (this) {
        if (!checkFutureId(res.futureId()))
            return;
        req = reqState.processPrimaryResponse(nodeId, res);
        if (req == null)
            return;
        boolean remapKey = res.remapTopologyVersion() != null;
        if (remapKey) {
            assert !req.topologyVersion().equals(res.remapTopologyVersion());
            assert remapTopVer == null : remapTopVer;
            remapTopVer = res.remapTopologyVersion();
        } else if (res.error() != null)
            onPrimaryError(req, res);
        else {
            GridCacheReturn ret = res.returnValue();
            if (op == TRANSFORM) {
                if (ret != null) {
                    assert ret.value() == null || ret.value() instanceof Map : ret.value();
                    if (ret.value() != null) {
                        if (opRes != null)
                            opRes.mergeEntryProcessResults(ret);
                        else
                            opRes = ret;
                    }
                }
            } else
                opRes = ret;
            assert reqState != null;
            if (!reqState.onPrimaryResponse(res, cctx))
                return;
        }
        remapTopVer0 = onAllReceived();
        if (remapTopVer0 == null) {
            err0 = err;
            opRes0 = opRes;
        }
    }
    if (res.error() != null && res.failedKeys() == null) {
        completeFuture(null, res.error(), res.futureId());
        return;
    }
    if (remapTopVer0 != null) {
        waitAndRemap(remapTopVer0);
        return;
    }
    if (nearEnabled && !nodeErr)
        updateNear(req, res);
    completeFuture(opRes0, err0, res.futureId());
}
Also used : GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) Map(java.util.Map)

Example 67 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.

the class GridNearAtomicSingleUpdateFuture method waitAndRemap.

/**
 * @param remapTopVer New topology version.
 */
private void waitAndRemap(AffinityTopologyVersion remapTopVer) {
    if (topLocked) {
        CachePartialUpdateCheckedException e = new CachePartialUpdateCheckedException("Failed to update keys (retry update if possible).");
        ClusterTopologyCheckedException cause = new ClusterTopologyCheckedException("Failed to update keys, topology changed while execute atomic update inside transaction.");
        cause.retryReadyFuture(cctx.affinity().affinityReadyFuture(remapTopVer));
        e.add(Collections.singleton(cctx.toCacheKeyObject(key)), cause);
        completeFuture(null, e, null);
        return;
    }
    IgniteInternalFuture<AffinityTopologyVersion> fut = cctx.shared().exchange().affinityReadyFuture(remapTopVer);
    if (fut == null)
        fut = new GridFinishedFuture<>(remapTopVer);
    fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

        @Override
        public void apply(final IgniteInternalFuture<AffinityTopologyVersion> fut) {
            cctx.kernalContext().closure().runLocalSafe(new Runnable() {

                @Override
                public void run() {
                    mapOnTopology();
                }
            });
        }
    });
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 68 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.

the class GridNearAtomicSingleUpdateFuture method mapOnTopology.

/**
 * {@inheritDoc}
 */
@Override
protected void mapOnTopology() {
    AffinityTopologyVersion topVer;
    if (cache.topology().stopping()) {
        completeFuture(null, new CacheStoppedException(cache.name()), null);
        return;
    }
    GridDhtTopologyFuture fut = cache.topology().topologyVersionFuture();
    if (fut.isDone()) {
        Throwable err = fut.validateCache(cctx, recovery, /*read*/
        false, key, null);
        if (err != null) {
            completeFuture(null, err, null);
            return;
        }
        topVer = fut.topologyVersion();
    } else {
        assert !topLocked : this;
        fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

            @Override
            public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
                cctx.kernalContext().closure().runLocalSafe(new Runnable() {

                    @Override
                    public void run() {
                        mapOnTopology();
                    }
                });
            }
        });
        return;
    }
    map(topVer);
}
Also used : GridDhtTopologyFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTopologyFuture) CacheStoppedException(org.apache.ignite.internal.processors.cache.CacheStoppedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 69 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.

the class GridDhtCacheAdapter method beginMultiUpdate.

/**
 * Starts multi-update lock. Will wait for topology future is ready.
 *
 * @return Topology version.
 * @throws IgniteCheckedException If failed.
 */
public AffinityTopologyVersion beginMultiUpdate() throws IgniteCheckedException {
    IgniteBiTuple<IgniteUuid, GridDhtTopologyFuture> tup = multiTxHolder.get();
    if (tup != null)
        throw new IgniteCheckedException("Nested multi-update locks are not supported");
    GridDhtPartitionTopology top = ctx.group().topology();
    top.readLock();
    GridDhtTopologyFuture topFut;
    AffinityTopologyVersion topVer;
    try {
        // While we are holding read lock, register lock future for partition release future.
        IgniteUuid lockId = IgniteUuid.fromUuid(ctx.localNodeId());
        topVer = top.readyTopologyVersion();
        MultiUpdateFuture fut = new MultiUpdateFuture(topVer);
        MultiUpdateFuture old = multiTxFuts.putIfAbsent(lockId, fut);
        assert old == null;
        topFut = top.topologyVersionFuture();
        multiTxHolder.set(F.t(lockId, topFut));
    } finally {
        top.readUnlock();
    }
    topFut.get();
    return topVer;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Example 70 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion in project ignite by apache.

the class GridDhtCacheAdapter method primarySizeLong.

/**
 * {@inheritDoc}
 */
@Override
public long primarySizeLong() {
    long sum = 0;
    AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
    for (GridDhtLocalPartition p : topology().currentLocalPartitions()) {
        if (p.primary(topVer))
            sum += p.dataStore().cacheSize(ctx.cacheId());
    }
    return sum;
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)

Aggregations

AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)242 ClusterNode (org.apache.ignite.cluster.ClusterNode)87 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)75 ArrayList (java.util.ArrayList)60 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)46 List (java.util.List)36 UUID (java.util.UUID)35 Ignite (org.apache.ignite.Ignite)33 Map (java.util.Map)32 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)31 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)30 HashMap (java.util.HashMap)27 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)22 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)20 IgniteKernal (org.apache.ignite.internal.IgniteKernal)20 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)20 IgniteException (org.apache.ignite.IgniteException)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)17 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)17 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)15