Search in sources :

Example 36 with GridCacheReturn

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

the class GridNearAtomicUpdateFuture method map.

/**
 * @param topVer Topology version.
 * @param remapKeys Keys to remap.
 */
private void map(AffinityTopologyVersion topVer, @Nullable Collection<KeyCacheObject> remapKeys) {
    Collection<ClusterNode> topNodes = CU.affinityNodes(cctx, topVer);
    if (F.isEmpty(topNodes)) {
        completeFuture(null, new ClusterTopologyServerNotFoundException("Failed to map keys for cache (all partition nodes left the grid)."), null);
        return;
    }
    long futId = cctx.mvcc().nextAtomicId();
    Exception err = null;
    PrimaryRequestState singleReq0 = null;
    Map<UUID, PrimaryRequestState> mappings0 = null;
    int size = keys.size();
    boolean mappingKnown = cctx.topology().rebalanceFinished(topVer);
    try {
        if (size == 1) {
            assert remapKeys == null || remapKeys.size() == 1;
            singleReq0 = mapSingleUpdate(topVer, futId, mappingKnown);
        } else {
            Map<UUID, PrimaryRequestState> pendingMappings = mapUpdate(topNodes, topVer, futId, remapKeys, mappingKnown);
            if (pendingMappings.size() == 1)
                singleReq0 = F.firstValue(pendingMappings);
            else {
                mappings0 = pendingMappings;
                assert !mappings0.isEmpty() || size == 0 : this;
            }
        }
        synchronized (this) {
            assert topVer.topologyVersion() > 0 : topVer;
            assert this.topVer == AffinityTopologyVersion.ZERO : this;
            this.topVer = topVer;
            this.futId = futId;
            resCnt = 0;
            singleReq = singleReq0;
            mappings = mappings0;
            this.remapKeys = null;
        }
        if (storeFuture() && !cctx.mvcc().addAtomicFuture(futId, this)) {
            assert isDone();
            return;
        }
    } catch (Exception e) {
        err = e;
    }
    if (err != null) {
        completeFuture(null, err, futId);
        return;
    }
    // Optimize mapping for single key.
    if (singleReq0 != null)
        sendSingleRequest(singleReq0.req.nodeId(), singleReq0.req);
    else {
        assert mappings0 != null;
        if (size == 0) {
            completeFuture(new GridCacheReturn(cctx, true, true, null, null, true), null, futId);
            return;
        } else
            sendUpdateRequests(mappings0);
    }
    if (syncMode == FULL_ASYNC) {
        completeFuture(new GridCacheReturn(cctx, true, true, null, null, true), null, futId);
        return;
    }
    if (mappingKnown && syncMode == FULL_SYNC && cctx.discovery().topologyVersion() != topVer.topologyVersion())
        checkDhtNodes(futId);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) UUID(java.util.UUID) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteCacheRestartingException(org.apache.ignite.IgniteCacheRestartingException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) CacheStoppedException(org.apache.ignite.internal.processors.cache.CacheStoppedException) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)

Aggregations

GridCacheReturn (org.apache.ignite.internal.processors.cache.GridCacheReturn)36 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)24 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)18 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)14 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)13 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)12 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)12 CachePartialUpdateCheckedException (org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)11 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)10 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)10 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)10 ArrayList (java.util.ArrayList)9 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)9 Map (java.util.Map)8 LinkedHashMap (java.util.LinkedHashMap)7 IgniteException (org.apache.ignite.IgniteException)7 GridDhtCacheEntry (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheEntry)7 CacheStoppedException (org.apache.ignite.internal.processors.cache.CacheStoppedException)6 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)6 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)6