Search in sources :

Example 1 with StartFullSnapshotAckDiscoveryMessage

use of org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage 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 StartFullSnapshotAckDiscoveryMessage

use of org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method distributedExchange.

/**
     * @throws IgniteCheckedException If failed.
     */
private void distributedExchange() throws IgniteCheckedException {
    assert crd != null;
    assert !cctx.kernalContext().clientNode();
    for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
        if (cacheCtx.isLocal())
            continue;
        cacheCtx.preloader().onTopologyChanged(this);
    }
    waitPartitionRelease();
    boolean topChanged = discoEvt.type() != EVT_DISCOVERY_CUSTOM_EVT || affChangeMsg != null;
    for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
        if (cacheCtx.isLocal() || stopping(cacheCtx.cacheId()))
            continue;
        if (topChanged) {
            // Partition release future is done so we can flush the write-behind store.
            cacheCtx.store().forceFlush();
        }
        cacheCtx.topology().beforeExchange(this, !centralizedAff);
    }
    cctx.database().beforeExchange(this);
    // If a backup request, synchronously wait for backup start.
    if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
        DiscoveryCustomMessage customMessage = ((DiscoveryCustomEvent) discoEvt).customMessage();
        if (customMessage instanceof StartFullSnapshotAckDiscoveryMessage) {
            StartFullSnapshotAckDiscoveryMessage backupMsg = (StartFullSnapshotAckDiscoveryMessage) customMessage;
            if (!cctx.localNode().isClient() && !cctx.localNode().isDaemon()) {
                ClusterNode node = cctx.discovery().node(backupMsg.initiatorNodeId());
                assert node != null;
                IgniteInternalFuture fut = cctx.database().startLocalSnapshotCreation(backupMsg, node, backupMsg.message());
                if (fut != null)
                    fut.get();
            }
        }
    }
    if (crd.isLocal()) {
        if (remaining.isEmpty())
            onAllReceived();
    } else
        sendPartitions(crd);
    initDone();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) StartFullSnapshotAckDiscoveryMessage(org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent)

Aggregations

DiscoveryCustomEvent (org.apache.ignite.internal.events.DiscoveryCustomEvent)2 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)2 StartFullSnapshotAckDiscoveryMessage (org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 IgniteNeedReconnectException (org.apache.ignite.internal.IgniteNeedReconnectException)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 DynamicCacheChangeBatch (org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch)1 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1