Search in sources :

Example 61 with AffinityTopologyVersion

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

the class InitNewCoordinatorFuture method onAllReceived.

/**
 */
private void onAllReceived() {
    if (fullMsg != null) {
        AffinityTopologyVersion resVer = fullMsg.resultTopologyVersion();
        for (Iterator<Map.Entry<ClusterNode, GridDhtPartitionsSingleMessage>> it = msgs.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<ClusterNode, GridDhtPartitionsSingleMessage> e = it.next();
            GridDhtPartitionExchangeId msgVer = joinedNodes.get(e.getKey().id());
            if (msgVer != null) {
                assert msgVer.topologyVersion().compareTo(initTopVer) > 0 : msgVer;
                if (log.isInfoEnabled()) {
                    log.info("Process joined node message [resVer=" + resVer + ", initTopVer=" + initTopVer + ", msgVer=" + msgVer.topologyVersion() + ']');
                }
                if (msgVer.topologyVersion().compareTo(resVer) > 0)
                    it.remove();
                else {
                    GridDhtPartitionsSingleMessage msg = e.getValue();
                    msg.exchangeId(msgVer);
                    if (joinExchMsgs == null)
                        joinExchMsgs = new HashMap<>();
                    joinExchMsgs.put(e.getKey().id(), msg);
                }
            }
        }
    } else {
        for (Iterator<Map.Entry<ClusterNode, GridDhtPartitionsSingleMessage>> it = msgs.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<ClusterNode, GridDhtPartitionsSingleMessage> e = it.next();
            GridDhtPartitionExchangeId msgVer = joinedNodes.get(e.getKey().id());
            if (msgVer != null) {
                it.remove();
                assert msgVer.topologyVersion().compareTo(initTopVer) > 0 : msgVer;
                if (log.isInfoEnabled()) {
                    log.info("Process joined node message [initTopVer=" + initTopVer + ", msgVer=" + msgVer.topologyVersion() + ']');
                }
                if (joinExchMsgs == null)
                    joinExchMsgs = new HashMap<>();
                e.getValue().exchangeId(msgVer);
                joinExchMsgs.put(e.getKey().id(), e.getValue());
            }
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 62 with AffinityTopologyVersion

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

the class InitNewCoordinatorFuture method init.

/**
 * @param exchFut Current future.
 * @throws IgniteCheckedException If failed.
 */
public void init(GridDhtPartitionsExchangeFuture exchFut) throws IgniteCheckedException {
    initTopVer = exchFut.initialVersion();
    GridCacheSharedContext cctx = exchFut.sharedContext();
    restoreState = exchangeProtocolVersion(exchFut.context().events().discoveryCache().minimumNodeVersion()) > 1;
    boolean newAff = exchFut.localJoinExchange();
    IgniteInternalFuture<?> fut = cctx.affinity().initCoordinatorCaches(exchFut, newAff);
    if (fut != null)
        add(fut);
    if (restoreState) {
        DiscoCache curDiscoCache = cctx.discovery().discoCache();
        DiscoCache discoCache = exchFut.events().discoveryCache();
        List<ClusterNode> nodes = new ArrayList<>();
        synchronized (this) {
            for (ClusterNode node : discoCache.allNodes()) {
                if (!node.isLocal() && cctx.discovery().alive(node)) {
                    awaited.add(node.id());
                    nodes.add(node);
                } else if (!node.isLocal()) {
                    if (log.isInfoEnabled())
                        log.info("Init new coordinator future will skip remote node: " + node);
                }
            }
            if (exchFut.context().mergeExchanges() && !curDiscoCache.version().equals(discoCache.version())) {
                for (ClusterNode node : curDiscoCache.allNodes()) {
                    if (discoCache.node(node.id()) == null) {
                        if (exchangeProtocolVersion(node.version()) == 1)
                            break;
                        awaited.add(node.id());
                        nodes.add(node);
                        if (joinedNodes == null)
                            joinedNodes = new HashMap<>();
                        GridDhtPartitionExchangeId exchId = new GridDhtPartitionExchangeId(node.id(), EVT_NODE_JOINED, new AffinityTopologyVersion(node.order()));
                        joinedNodes.put(node.id(), exchId);
                    }
                }
            }
            if (joinedNodes == null)
                joinedNodes = Collections.emptyMap();
            if (!awaited.isEmpty()) {
                restoreStateFut = new GridFutureAdapter();
                add(restoreStateFut);
            }
        }
        if (log.isInfoEnabled()) {
            log.info("Try restore exchange result [awaited=" + awaited + ", joined=" + joinedNodes.keySet() + ", nodes=" + U.nodeIds(nodes) + ", discoAllNodes=" + U.nodeIds(discoCache.allNodes()) + ']');
        }
        if (!nodes.isEmpty()) {
            GridDhtPartitionsSingleRequest req = GridDhtPartitionsSingleRequest.restoreStateRequest(exchFut.exchangeId(), exchFut.exchangeId());
            for (ClusterNode node : nodes) {
                try {
                    GridDhtPartitionsSingleRequest sndReq = req;
                    if (joinedNodes.containsKey(node.id())) {
                        sndReq = GridDhtPartitionsSingleRequest.restoreStateRequest(joinedNodes.get(node.id()), exchFut.exchangeId());
                    }
                    cctx.io().send(node, sndReq, GridIoPolicy.SYSTEM_POOL);
                } catch (ClusterTopologyCheckedException e) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to send partitions request, node failed: " + node);
                    onNodeLeft(node.id());
                }
            }
        }
    }
    markInitialized();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) HashMap(java.util.HashMap) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 63 with AffinityTopologyVersion

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

the class GridNearAtomicCache method processNearAtomicUpdateResponse.

/**
 * @param ver Version.
 * @param key Key.
 * @param val Value.
 * @param ttl TTL.
 * @param expireTime Expire time.
 * @param nodeId Node ID.
 * @param subjId Subject ID.
 * @param taskName Task name.
 * @throws IgniteCheckedException If failed.
 */
private void processNearAtomicUpdateResponse(GridCacheVersion ver, KeyCacheObject key, @Nullable CacheObject val, long ttl, long expireTime, boolean keepBinary, UUID nodeId, UUID subjId, String taskName) throws IgniteCheckedException {
    try {
        while (true) {
            GridCacheEntryEx entry = null;
            AffinityTopologyVersion topVer = ctx.affinity().affinityTopologyVersion();
            try {
                entry = entryEx(key, topVer);
                GridCacheOperation op = val != null ? UPDATE : DELETE;
                GridCacheUpdateAtomicResult updRes = entry.innerUpdate(ver, nodeId, nodeId, op, val, null, /*write-through*/
                false, /*read-through*/
                false, /*retval*/
                false, keepBinary, /*expiry policy*/
                null, /*event*/
                true, /*metrics*/
                true, /*primary*/
                false, /*check version*/
                true, topVer, CU.empty0(), DR_NONE, ttl, expireTime, null, false, false, subjId, taskName, null, null, null);
                if (updRes.removeVersion() != null)
                    ctx.onDeferredDelete(entry, updRes.removeVersion());
                // While.
                break;
            } catch (GridCacheEntryRemovedException ignored) {
                if (log.isDebugEnabled())
                    log.debug("Got removed entry while updating near cache value (will retry): " + key);
                entry = null;
            } finally {
                if (entry != null)
                    ctx.evicts().touch(entry, topVer);
            }
        }
    } catch (GridDhtInvalidPartitionException ignored) {
    // Ignore.
    }
}
Also used : GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) GridCacheUpdateAtomicResult(org.apache.ignite.internal.processors.cache.GridCacheUpdateAtomicResult)

Example 64 with AffinityTopologyVersion

use of org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion 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 65 with AffinityTopologyVersion

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

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