Search in sources :

Example 1 with CachePartialUpdateCheckedException

use of org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException 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.shared().exchange().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 GridPlainRunnable() {

                @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) GridPlainRunnable(org.apache.ignite.internal.util.lang.GridPlainRunnable) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 2 with CachePartialUpdateCheckedException

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

the class GridNearAtomicSingleUpdateFuture method onPrimaryResponse.

/**
 * {@inheritDoc}
 */
@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 3 with CachePartialUpdateCheckedException

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

the class GridNearAtomicSingleUpdateFuture method onDhtResponse.

/**
 * {@inheritDoc}
 */
@Override
public void onDhtResponse(UUID nodeId, GridDhtAtomicNearResponse res) {
    GridCacheReturn opRes0;
    CachePartialUpdateCheckedException err0;
    AffinityTopologyVersion remapTopVer0;
    synchronized (this) {
        if (!checkFutureId(res.futureId()))
            return;
        assert reqState != null;
        assert reqState.req.nodeId().equals(res.primaryId());
        if (opRes == null && res.hasResult())
            opRes = res.result();
        if (reqState.onDhtResponse(nodeId, res)) {
            opRes0 = opRes;
            err0 = err;
            remapTopVer0 = onAllReceived();
        } else
            return;
    }
    UpdateErrors errors = res.errors();
    if (errors != null) {
        assert errors.error() != null;
        completeFuture(null, errors.error(), res.futureId());
        return;
    }
    finishUpdateFuture(opRes0, err0, remapTopVer0, 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)

Example 4 with CachePartialUpdateCheckedException

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

the class GridNearAtomicSingleUpdateFuture method checkDhtNodes.

/**
 * @param futId Future ID.
 */
private void checkDhtNodes(long futId) {
    GridCacheReturn opRes0 = null;
    CachePartialUpdateCheckedException err0 = null;
    AffinityTopologyVersion remapTopVer0 = null;
    GridNearAtomicCheckUpdateRequest checkReq = null;
    synchronized (this) {
        if (!checkFutureId(futId))
            return;
        assert reqState != null;
        DhtLeftResult res = reqState.checkDhtNodes(cctx);
        if (res == DhtLeftResult.DONE) {
            opRes0 = opRes;
            err0 = err;
            remapTopVer0 = onAllReceived();
        } else if (res == DhtLeftResult.ALL_RCVD_CHECK_PRIMARY)
            checkReq = new GridNearAtomicCheckUpdateRequest(reqState.req);
        else
            return;
    }
    if (checkReq != null)
        sendCheckUpdateRequest(checkReq);
    else
        finishUpdateFuture(opRes0, err0, remapTopVer0, futId);
}
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)

Example 5 with CachePartialUpdateCheckedException

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

the class GridNearAtomicUpdateFuture method onPrimaryResponse.

/**
 * {@inheritDoc}
 */
@Override
public void onPrimaryResponse(UUID nodeId, GridNearAtomicUpdateResponse res, boolean nodeErr) {
    GridNearAtomicAbstractUpdateRequest req;
    AffinityTopologyVersion remapTopVer0 = null;
    GridCacheReturn opRes0 = null;
    CachePartialUpdateCheckedException err0 = null;
    boolean rcvAll;
    synchronized (this) {
        if (!checkFutureId(res.futureId()))
            return;
        if (singleReq != null) {
            req = singleReq.processPrimaryResponse(nodeId, res);
            if (req == null)
                return;
            rcvAll = singleReq.onPrimaryResponse(res, cctx);
        } else {
            if (mappings == null)
                return;
            PrimaryRequestState reqState = mappings.get(nodeId);
            if (reqState == null)
                return;
            req = reqState.processPrimaryResponse(nodeId, res);
            if (req != null) {
                if (reqState.onPrimaryResponse(res, cctx)) {
                    assert mappings.size() > resCnt : "[mappings=" + mappings.size() + ", cnt=" + resCnt + ']';
                    resCnt++;
                    rcvAll = mappings.size() == resCnt;
                } else {
                    assert mappings.size() > resCnt : "[mappings=" + mappings.size() + ", cnt=" + resCnt + ']';
                    rcvAll = false;
                }
            } else
                return;
        }
        assert req.topologyVersion().equals(topVer) : req;
        if (res.remapTopologyVersion() != null) {
            assert !req.topologyVersion().equals(res.remapTopologyVersion());
            if (remapKeys == null)
                remapKeys = U.newHashSet(req.size());
            remapKeys.addAll(req.keys());
            if (remapTopVer == null || remapTopVer.compareTo(res.remapTopologyVersion()) < 0)
                remapTopVer = req.topologyVersion();
        } 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;
        }
        if (rcvAll) {
            remapTopVer0 = onAllReceived();
            if (remapTopVer0 == null) {
                err0 = err;
                opRes0 = opRes;
            }
        }
    }
    if (res.error() != null && res.failedKeys() == null) {
        completeFuture(null, res.error(), res.futureId());
        return;
    }
    if (rcvAll && nearEnabled) {
        if (mappings != null) {
            for (PrimaryRequestState reqState : mappings.values()) {
                GridNearAtomicUpdateResponse res0 = reqState.req.response();
                assert res0 != null : reqState;
                updateNear(reqState.req, res0);
            }
        } else if (!nodeErr)
            updateNear(req, res);
    }
    if (remapTopVer0 != null) {
        waitAndRemap(remapTopVer0);
        return;
    }
    if (rcvAll)
        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)

Aggregations

CachePartialUpdateCheckedException (org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)18 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)12 GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)9 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)5 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)5 Map (java.util.Map)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 EntryProcessorException (javax.cache.processor.EntryProcessorException)3 EntryProcessorResult (javax.cache.processor.EntryProcessorResult)3 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)3 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)3 EntryProcessor (javax.cache.processor.EntryProcessor)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)2 CacheInvokeEntry (org.apache.ignite.internal.processors.cache.CacheInvokeEntry)2 CacheInvokeResult (org.apache.ignite.internal.processors.cache.CacheInvokeResult)2 CacheLazyEntry (org.apache.ignite.internal.processors.cache.CacheLazyEntry)2