Search in sources :

Example 1 with IgniteNeedReconnectException

use of org.apache.ignite.internal.IgniteNeedReconnectException in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method init.

/**
     * Starts activity.
     *
     * @throws IgniteInterruptedCheckedException If interrupted.
     */
public void init() throws IgniteInterruptedCheckedException {
    if (isDone())
        return;
    initTs = U.currentTimeMillis();
    U.await(evtLatch);
    assert discoEvt != null : this;
    assert exchId.nodeId().equals(discoEvt.eventNode().id()) : this;
    assert !dummy && !forcePreload : this;
    try {
        discoCache.updateAlives(cctx.discovery());
        AffinityTopologyVersion topVer = topologyVersion();
        srvNodes = new ArrayList<>(discoCache.serverNodes());
        remaining.addAll(F.nodeIds(F.view(srvNodes, F.remoteNodes(cctx.localNodeId()))));
        crd = srvNodes.isEmpty() ? null : srvNodes.get(0);
        boolean crdNode = crd != null && crd.isLocal();
        skipPreload = cctx.kernalContext().clientNode();
        ExchangeType exchange;
        if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
            DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) discoEvt).customMessage();
            if (msg instanceof DynamicCacheChangeBatch) {
                assert exchActions != null && !exchActions.empty();
                exchange = onCacheChangeRequest(crdNode);
            } else if (msg instanceof StartFullSnapshotAckDiscoveryMessage)
                exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode);
            else {
                assert affChangeMsg != null : this;
                exchange = onAffinityChangeRequest(crdNode);
            }
        } else {
            if (discoEvt.type() == EVT_NODE_JOINED) {
                if (!discoEvt.eventNode().isLocal()) {
                    Collection<DynamicCacheDescriptor> receivedCaches = cctx.cache().startReceivedCaches(discoEvt.eventNode().id(), topVer);
                    cctx.affinity().initStartedCaches(crdNode, this, receivedCaches);
                } else
                    cctx.cache().startCachesOnLocalJoin(topVer);
            }
            exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode);
        }
        updateTopologies(crdNode);
        if (exchActions != null && exchActions.hasStop())
            cctx.cache().context().database().beforeCachesStop();
        switch(exchange) {
            case ALL:
                {
                    distributedExchange();
                    break;
                }
            case CLIENT:
                {
                    initTopologies();
                    clientOnlyExchange();
                    break;
                }
            case NONE:
                {
                    initTopologies();
                    onDone(topVer);
                    break;
                }
            default:
                assert false;
        }
    } catch (IgniteInterruptedCheckedException e) {
        onDone(e);
        throw e;
    } catch (IgniteNeedReconnectException e) {
        onDone(e);
    } catch (Throwable e) {
        if (reconnectOnError(e))
            onDone(new IgniteNeedReconnectException(cctx.localNode(), e));
        else {
            U.error(log, "Failed to reinitialize local partitions (preloading will be stopped): " + exchId, e);
            onDone(e);
        }
        if (e instanceof Error)
            throw (Error) e;
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) StartFullSnapshotAckDiscoveryMessage(org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException)

Example 2 with IgniteNeedReconnectException

use of org.apache.ignite.internal.IgniteNeedReconnectException in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method onAllReceived.

/**
     *
     */
private void onAllReceived() {
    try {
        assert crd.isLocal();
        if (!crd.equals(discoCache.serverNodes().get(0))) {
            for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
                if (!cacheCtx.isLocal())
                    cacheCtx.topology().beforeExchange(this, !centralizedAff);
            }
        }
        for (GridDhtPartitionsAbstractMessage msg : msgs.values()) {
            if (msg instanceof GridDhtPartitionsSingleMessage) {
                GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage) msg;
                for (Map.Entry<Integer, GridDhtPartitionMap> entry : msg0.partitions().entrySet()) {
                    Integer cacheId = entry.getKey();
                    GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
                    GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() : cctx.exchange().clientTopology(cacheId, this);
                    Map<Integer, T2<Long, Long>> cntrs = msg0.partitionUpdateCounters(cacheId);
                    if (cntrs != null)
                        top.applyUpdateCounters(cntrs);
                }
            }
        }
        if (discoEvt.type() == EVT_NODE_JOINED) {
            if (cctx.kernalContext().state().active())
                assignPartitionsStates();
        } else if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
            assert discoEvt instanceof DiscoveryCustomEvent;
            if (((DiscoveryCustomEvent) discoEvt).customMessage() instanceof DynamicCacheChangeBatch) {
                if (exchActions != null) {
                    if (exchActions.newClusterState() == ClusterState.ACTIVE)
                        assignPartitionsStates();
                    Set<String> caches = exchActions.cachesToResetLostPartitions();
                    if (!F.isEmpty(caches))
                        resetLostPartitions(caches);
                }
            }
        } else if (discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED)
            detectLostPartitions();
        updateLastVersion(cctx.versions().last());
        cctx.versions().onExchange(lastVer.get().order());
        if (centralizedAff) {
            IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>> fut = cctx.affinity().initAffinityOnNodeLeft(this);
            if (!fut.isDone()) {
                fut.listen(new IgniteInClosure<IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>>>() {

                    @Override
                    public void apply(IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>> fut) {
                        onAffinityInitialized(fut);
                    }
                });
            } else
                onAffinityInitialized(fut);
        } else {
            List<ClusterNode> nodes;
            synchronized (this) {
                srvNodes.remove(cctx.localNode());
                nodes = new ArrayList<>(srvNodes);
            }
            if (!nodes.isEmpty())
                sendAllPartitions(nodes);
            if (exchangeOnChangeGlobalState && !F.isEmpty(changeGlobalStateExceptions))
                cctx.kernalContext().state().onFullResponseMessage(changeGlobalStateExceptions);
            onDone(exchangeId().topologyVersion());
        }
    } catch (IgniteCheckedException e) {
        if (reconnectOnError(e))
            onDone(new IgniteNeedReconnectException(cctx.localNode(), e));
        else
            onDone(e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) Set(java.util.Set) HashSet(java.util.HashSet) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) T2(org.apache.ignite.internal.util.typedef.T2)

Example 3 with IgniteNeedReconnectException

use of org.apache.ignite.internal.IgniteNeedReconnectException in project ignite by apache.

the class GridDhtAssignmentFetchFuture method requestFromNextNode.

/**
     * Requests affinity from next node in the list.
     */
private void requestFromNextNode() {
    boolean complete;
    // Avoid 'protected field is accessed in synchronized context' warning.
    IgniteLogger log0 = log;
    synchronized (this) {
        while (!availableNodes.isEmpty()) {
            ClusterNode node = availableNodes.poll();
            try {
                if (log0.isDebugEnabled())
                    log0.debug("Sending affinity fetch request to remote node [locNodeId=" + ctx.localNodeId() + ", node=" + node + ']');
                ctx.io().send(node, new GridDhtAffinityAssignmentRequest(id, cacheId, topVer), AFFINITY_POOL);
                // Close window for listener notification.
                if (ctx.discovery().node(node.id()) == null) {
                    U.warn(log0, "Failed to request affinity assignment from remote node (node left grid, will " + "continue to another node): " + node);
                    continue;
                }
                pendingNode = node;
                break;
            } catch (ClusterTopologyCheckedException ignored) {
                U.warn(log0, "Failed to request affinity assignment from remote node (node left grid, will " + "continue to another node): " + node);
            } catch (IgniteCheckedException e) {
                if (ctx.discovery().reconnectSupported() && X.hasCause(e, IOException.class)) {
                    onDone(new IgniteNeedReconnectException(ctx.localNode(), e));
                    return;
                }
                U.warn(log0, "Failed to request affinity assignment from remote node (will " + "continue to another node): " + node);
            }
        }
        complete = pendingNode == null;
    }
    // Affinity should be calculated from scratch.
    if (complete)
        onDone((GridDhtAffinityAssignmentResponse) null);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 4 with IgniteNeedReconnectException

use of org.apache.ignite.internal.IgniteNeedReconnectException in project ignite by apache.

the class GridCachePartitionExchangeManager method onKernalStart0.

/** {@inheritDoc} */
@Override
protected void onKernalStart0(boolean reconnect) throws IgniteCheckedException {
    super.onKernalStart0(reconnect);
    ClusterNode loc = cctx.localNode();
    long startTime = loc.metrics().getStartTime();
    assert startTime > 0;
    // Generate dummy discovery event for local node joining.
    T2<DiscoveryEvent, DiscoCache> locJoin = cctx.discovery().localJoin();
    DiscoveryEvent discoEvt = locJoin.get1();
    DiscoCache discoCache = locJoin.get2();
    GridDhtPartitionExchangeId exchId = initialExchangeId();
    GridDhtPartitionsExchangeFuture fut = exchangeFuture(exchId, discoEvt, discoCache, null, null);
    if (reconnect)
        reconnectExchangeFut = new GridFutureAdapter<>();
    exchWorker.addFirstExchangeFuture(fut);
    if (!cctx.kernalContext().clientNode()) {
        for (int cnt = 0; cnt < cctx.gridConfig().getRebalanceThreadPoolSize(); cnt++) {
            final int idx = cnt;
            cctx.io().addOrderedHandler(rebalanceTopic(cnt), new CI2<UUID, GridCacheMessage>() {

                @Override
                public void apply(final UUID id, final GridCacheMessage m) {
                    if (!enterBusy())
                        return;
                    try {
                        GridCacheContext cacheCtx = cctx.cacheContext(m.cacheId);
                        if (cacheCtx != null) {
                            if (m instanceof GridDhtPartitionSupplyMessage)
                                cacheCtx.preloader().handleSupplyMessage(idx, id, (GridDhtPartitionSupplyMessage) m);
                            else if (m instanceof GridDhtPartitionDemandMessage)
                                cacheCtx.preloader().handleDemandMessage(idx, id, (GridDhtPartitionDemandMessage) m);
                            else
                                U.error(log, "Unsupported message type: " + m.getClass().getName());
                        }
                    } finally {
                        leaveBusy();
                    }
                }
            });
        }
    }
    new IgniteThread(cctx.igniteInstanceName(), "exchange-worker", exchWorker).start();
    if (reconnect) {
        fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

            @Override
            public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
                try {
                    fut.get();
                    for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.preloader().onInitialExchangeComplete(null);
                    reconnectExchangeFut.onDone();
                } catch (IgniteCheckedException e) {
                    for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.preloader().onInitialExchangeComplete(e);
                    reconnectExchangeFut.onDone(e);
                }
            }
        });
    } else {
        if (log.isDebugEnabled())
            log.debug("Beginning to wait on local exchange future: " + fut);
        boolean first = true;
        while (true) {
            try {
                fut.get(cctx.preloadExchangeTimeout());
                break;
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                if (first) {
                    U.warn(log, "Failed to wait for initial partition map exchange. " + "Possible reasons are: " + U.nl() + "  ^-- Transactions in deadlock." + U.nl() + "  ^-- Long running transactions (ignore if this is the case)." + U.nl() + "  ^-- Unreleased explicit locks.");
                    first = false;
                } else
                    U.warn(log, "Still waiting for initial partition map exchange [fut=" + fut + ']');
            } catch (IgniteNeedReconnectException e) {
                throw e;
            } catch (Exception e) {
                if (fut.reconnectOnError(e))
                    throw new IgniteNeedReconnectException(cctx.localNode(), e);
                throw e;
            }
        }
        AffinityTopologyVersion nodeStartVer = new AffinityTopologyVersion(discoEvt.topologyVersion(), 0);
        for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
            if (nodeStartVer.equals(cacheCtx.startTopologyVersion()))
                cacheCtx.preloader().onInitialExchangeComplete(null);
        }
        if (log.isDebugEnabled())
            log.debug("Finished waiting for initial exchange: " + fut.exchangeId());
    }
}
Also used : DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) UUID(java.util.UUID) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteThread(org.apache.ignite.thread.IgniteThread) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)

Aggregations

IgniteNeedReconnectException (org.apache.ignite.internal.IgniteNeedReconnectException)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 UUID (java.util.UUID)2 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2 DiscoveryCustomEvent (org.apache.ignite.internal.events.DiscoveryCustomEvent)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 DynamicCacheChangeBatch (org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)1