Search in sources :

Example 16 with DiscoveryCustomMessage

use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.

the class CacheBlockOnReadAbstractTest method createCachePredicate.

/**
 * Checks that given discovery event is from "Create cache" operation.
 *
 * @param discoEvt Discovery event.
 */
private static boolean createCachePredicate(DiscoveryEvent discoEvt) {
    if (discoEvt instanceof DiscoveryCustomEvent) {
        DiscoveryCustomEvent discoCustomEvt = (DiscoveryCustomEvent) discoEvt;
        DiscoveryCustomMessage customMsg = discoCustomEvt.customMessage();
        if (customMsg instanceof DynamicCacheChangeBatch) {
            DynamicCacheChangeBatch cacheChangeBatch = (DynamicCacheChangeBatch) customMsg;
            ExchangeActions exchangeActions = U.field(cacheChangeBatch, "exchangeActions");
            Collection<CacheActionData> startRequests = exchangeActions.cacheStartRequests();
            return !startRequests.isEmpty();
        }
    }
    return false;
}
Also used : CacheActionData(org.apache.ignite.internal.processors.cache.ExchangeActions.CacheActionData) ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)

Example 17 with DiscoveryCustomMessage

use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.

the class CacheContinuousQueryFilterDeploymentFailedTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    // Failure detection timeout > P2P class loading timeout which is set as network timeout.
    cfg.setFailureDetectionTimeout(cfg.getNetworkTimeout() * 2);
    ((TestTcpDiscoverySpi) cfg.getDiscoverySpi()).discoveryHook(new DiscoveryHook() {

        @Override
        public void afterDiscovery(DiscoveryCustomMessage customMsg) {
            if (customMsg instanceof StopRoutineDiscoveryMessage)
                stopRoutineLatch.countDown();
        }
    });
    cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
    return cfg;
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) StopRoutineDiscoveryMessage(org.apache.ignite.internal.processors.continuous.StopRoutineDiscoveryMessage) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)

Example 18 with DiscoveryCustomMessage

use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.

the class DistributedMetaStorageImpl method startCas.

/**
 * Basically the same as {@link #startWrite(String, byte[])} but for CAS operations.
 */
private GridFutureAdapter<Boolean> startCas(String key, byte[] expValBytes, byte[] newValBytes) throws IgniteCheckedException {
    UUID reqId = UUID.randomUUID();
    GridFutureAdapter<Boolean> fut = prepareWriteFuture(key, reqId);
    if (fut.isDone())
        return fut;
    DiscoveryCustomMessage msg = new DistributedMetaStorageCasMessage(reqId, key, expValBytes, newValBytes);
    ctx.discovery().sendCustomEvent(msg);
    return fut;
}
Also used : UUID(java.util.UUID) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)

Example 19 with DiscoveryCustomMessage

use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method init.

/**
 * Starts activity.
 *
 * @param newCrd {@code True} if node become coordinator on this exchange.
 * @throws IgniteInterruptedCheckedException If interrupted.
 */
public void init(boolean newCrd) throws IgniteInterruptedCheckedException {
    if (isDone())
        return;
    assert !cctx.kernalContext().isDaemon();
    cctx.exchange().exchangerBlockingSectionBegin();
    try {
        U.await(evtLatch);
    } finally {
        cctx.exchange().exchangerBlockingSectionEnd();
    }
    assert firstDiscoEvt != null : this;
    assert exchId.nodeId().equals(firstDiscoEvt.eventNode().id()) : this;
    try {
        AffinityTopologyVersion topVer = initialVersion();
        srvNodes = new ArrayList<>(firstEvtDiscoCache.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();
        exchCtx = new ExchangeContext(cctx, crdNode, this);
        cctx.exchange().exchangerBlockingSectionBegin();
        assert state == null : state;
        if (crdNode)
            state = ExchangeLocalState.CRD;
        else
            state = cctx.kernalContext().clientNode() ? ExchangeLocalState.CLIENT : ExchangeLocalState.SRV;
        initTime = System.currentTimeMillis();
        if (exchLog.isInfoEnabled()) {
            exchLog.info("Started exchange init [topVer=" + topVer + ", crd=" + crdNode + ", evt=" + IgniteUtils.gridEventName(firstDiscoEvt.type()) + ", evtNode=" + firstDiscoEvt.eventNode().id() + ", customEvt=" + (firstDiscoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT ? ((DiscoveryCustomEvent) firstDiscoEvt).customMessage() : null) + ", allowMerge=" + exchCtx.mergeExchanges() + ", exchangeFreeSwitch=" + exchCtx.exchangeFreeSwitch() + ']');
        }
        span.addLog(() -> "Exchange parameters initialization");
        timeBag.finishGlobalStage("Exchange parameters initialization");
        ExchangeType exchange;
        if (exchCtx.exchangeFreeSwitch()) {
            if (isSnapshotOperation(firstDiscoEvt)) {
                // Keep if the cluster was rebalanced.
                if (wasRebalanced())
                    markRebalanced();
                if (!forceAffReassignment)
                    cctx.affinity().onCustomMessageNoAffinityChange(this, exchActions);
                exchange = cctx.kernalContext().clientNode() ? ExchangeType.NONE : ExchangeType.ALL;
            } else
                exchange = onExchangeFreeSwitchNodeLeft();
            initCoordinatorCaches(newCrd);
        } else if (firstDiscoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
            assert !exchCtx.mergeExchanges();
            DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) firstDiscoEvt).customMessage();
            forceAffReassignment = DiscoveryCustomEvent.requiresCentralizedAffinityAssignment(msg) && firstEventCache().minimumNodeVersion().compareToIgnoreTimestamp(FORCE_AFF_REASSIGNMENT_SINCE) >= 0;
            if (msg instanceof ChangeGlobalStateMessage) {
                assert exchActions != null && !exchActions.empty();
                exchange = onClusterStateChangeRequest(crdNode);
            } else if (msg instanceof DynamicCacheChangeBatch) {
                assert exchActions != null && !exchActions.empty();
                exchange = onCacheChangeRequest(crdNode);
            } else if (msg instanceof SnapshotDiscoveryMessage)
                exchange = onCustomMessageNoAffinityChange();
            else if (msg instanceof WalStateAbstractMessage)
                exchange = onCustomMessageNoAffinityChange();
            else {
                assert affChangeMsg != null : this;
                exchange = onAffinityChangeRequest();
            }
            if (forceAffReassignment)
                cctx.affinity().onCentralizedAffinityChange(this, crdNode);
            initCoordinatorCaches(newCrd);
        } else {
            if (firstDiscoEvt.type() == EVT_NODE_JOINED) {
                if (!firstDiscoEvt.eventNode().isLocal()) {
                    Collection<DynamicCacheDescriptor> receivedCaches = cctx.cache().startReceivedCaches(firstDiscoEvt.eventNode().id(), topVer);
                    registerCachesFuture = cctx.affinity().initStartedCaches(crdNode, this, receivedCaches);
                } else
                    registerCachesFuture = initCachesOnLocalJoin();
            }
            initCoordinatorCaches(newCrd);
            if (exchCtx.mergeExchanges()) {
                if (localJoinExchange()) {
                    if (cctx.kernalContext().clientNode()) {
                        onClientNodeEvent();
                        exchange = ExchangeType.CLIENT;
                    } else {
                        onServerNodeEvent(crdNode);
                        exchange = ExchangeType.ALL;
                    }
                } else {
                    if (firstDiscoEvt.eventNode().isClient())
                        exchange = onClientNodeEvent();
                    else
                        exchange = cctx.kernalContext().clientNode() ? ExchangeType.CLIENT : ExchangeType.ALL;
                }
                if (exchId.isLeft())
                    onLeft();
            } else {
                exchange = firstDiscoEvt.eventNode().isClient() ? onClientNodeEvent() : onServerNodeEvent(crdNode);
            }
        }
        cctx.cache().registrateProxyRestart(resolveCacheRequests(exchActions), afterLsnrCompleteFut);
        exchangeType = exchange;
        for (PartitionsExchangeAware comp : cctx.exchange().exchangeAwareComponents()) comp.onInitBeforeTopologyLock(this);
        updateTopologies(crdNode);
        timeBag.finishGlobalStage("Determine exchange type");
        switch(exchange) {
            case ALL:
                {
                    distributedExchange();
                    break;
                }
            case CLIENT:
                {
                    if (!exchCtx.mergeExchanges() && exchCtx.fetchAffinityOnJoin())
                        initTopologies();
                    clientOnlyExchange();
                    break;
                }
            case NONE:
                {
                    initTopologies();
                    synchronized (mux) {
                        state = ExchangeLocalState.DONE;
                    }
                    onDone(topVer);
                    break;
                }
            default:
                assert false;
        }
        if (cctx.localNode().isClient()) {
            cctx.exchange().exchangerBlockingSectionBegin();
            try {
                tryToPerformLocalSnapshotOperation();
            } finally {
                cctx.exchange().exchangerBlockingSectionEnd();
            }
        }
        for (PartitionsExchangeAware comp : cctx.exchange().exchangeAwareComponents()) comp.onInitAfterTopologyLock(this);
        // invoked prior to onDoneBeforeTopologyUnlock.
        if (exchange == ExchangeType.ALL && context().exchangeFreeSwitch()) {
            cctx.exchange().exchangerBlockingSectionBegin();
            try {
                onDone(initialVersion());
            } finally {
                cctx.exchange().exchangerBlockingSectionEnd();
            }
        }
        if (exchLog.isInfoEnabled())
            exchLog.info("Finished exchange init [topVer=" + topVer + ", crd=" + crdNode + ']');
    } catch (IgniteInterruptedCheckedException e) {
        assert cctx.kernalContext().isStopping() || cctx.kernalContext().clientDisconnected();
        if (cctx.kernalContext().clientDisconnected())
            onDone(new IgniteCheckedException("Client disconnected"));
        else
            onDone(new IgniteCheckedException("Node stopped"));
        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 (rebalancing will be stopped): " + exchId, e);
            onDone(e);
        }
        if (e instanceof Error)
            throw (Error) e;
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) SnapshotDiscoveryMessage(org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotDiscoveryMessage) Collection(java.util.Collection) ExchangeContext(org.apache.ignite.internal.processors.cache.ExchangeContext) WalStateAbstractMessage(org.apache.ignite.internal.processors.cache.WalStateAbstractMessage) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException)

Example 20 with DiscoveryCustomMessage

use of org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage in project ignite by apache.

the class IgniteClusterSnapshotSelfTest method testConsistentClusterSnapshotLoadNewTopology.

/**
 * Take snapshot from the whole cluster and check snapshot consistency when the
 * cluster tx load starts on a new topology version.
 * Note: Client nodes and server nodes not in baseline topology must not be affected.
 *
 * @throws Exception If fails.
 */
@Test
public void testConsistentClusterSnapshotLoadNewTopology() throws Exception {
    int grids = 3;
    String snpName = "backup23012020";
    AtomicInteger atKey = new AtomicInteger(CACHE_KEYS_RANGE);
    AtomicInteger txKey = new AtomicInteger(CACHE_KEYS_RANGE);
    IgniteEx ignite = startGrids(grids);
    startClientGrid();
    ignite.cluster().baselineAutoAdjustEnabled(false);
    ignite.cluster().state(ACTIVE);
    ignite.events().localListen(e -> locEvts.add(e.type()), EVTS_CLUSTER_SNAPSHOT);
    // Start node not in baseline.
    IgniteEx notBltIgnite = startGrid(grids);
    File locSnpDir = snp(notBltIgnite).snapshotLocalDir(SNAPSHOT_NAME);
    String notBltDirName = folderName(notBltIgnite);
    IgniteCache<Integer, Integer> atCache = ignite.createCache(atomicCcfg);
    for (int idx = 0; idx < CACHE_KEYS_RANGE; idx++) {
        atCache.put(atKey.incrementAndGet(), -1);
        ignite.cache(DEFAULT_CACHE_NAME).put(txKey.incrementAndGet(), -1);
    }
    forceCheckpoint();
    CountDownLatch loadLatch = new CountDownLatch(1);
    ignite.context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
            if (fut.firstEvent().type() != EVT_DISCOVERY_CUSTOM_EVT)
                return;
            // First discovery custom event will be a snapshot operation.
            assertTrue(isSnapshotOperation(fut.firstEvent()));
            assertTrue("Snapshot must use pme-free exchange", fut.context().exchangeFreeSwitch());
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void onInitAfterTopologyLock(GridDhtPartitionsExchangeFuture fut) {
            if (fut.firstEvent().type() != EVT_DISCOVERY_CUSTOM_EVT)
                return;
            DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) fut.firstEvent()).customMessage();
            assertNotNull(msg);
            if (msg instanceof SnapshotDiscoveryMessage)
                loadLatch.countDown();
        }
    });
    // Start cache load.
    IgniteInternalFuture<Long> loadFut = GridTestUtils.runMultiThreadedAsync(() -> {
        try {
            U.await(loadLatch);
            while (!Thread.currentThread().isInterrupted()) {
                ThreadLocalRandom rnd = ThreadLocalRandom.current();
                int atIdx = rnd.nextInt(grids);
                // Zero out the sign bit.
                grid(atIdx).cache(atomicCcfg.getName()).put(txKey.incrementAndGet(), rnd.nextInt() & Integer.MAX_VALUE);
                int txIdx = rnd.nextInt(grids);
                grid(txIdx).cache(DEFAULT_CACHE_NAME).put(atKey.incrementAndGet(), rnd.nextInt() & Integer.MAX_VALUE);
            }
        } catch (IgniteInterruptedCheckedException e) {
            throw new RuntimeException(e);
        }
    }, 3, "cache-put-");
    try {
        IgniteFuture<Void> fut = ignite.snapshot().createSnapshot(snpName);
        U.await(loadLatch, 10, TimeUnit.SECONDS);
        fut.get();
        waitForEvents(EVT_CLUSTER_SNAPSHOT_STARTED, EVT_CLUSTER_SNAPSHOT_FINISHED);
    } finally {
        loadFut.cancel();
    }
    // Cluster can be deactivated but we must test snapshot restore when binary recovery also occurred.
    stopAllGrids();
    assertTrue("Snapshot directory must be empty for node not in baseline topology: " + notBltDirName, !searchDirectoryRecursively(locSnpDir.toPath(), notBltDirName).isPresent());
    IgniteEx snpIg0 = startGridsFromSnapshot(grids, snpName);
    assertEquals("The number of all (primary + backup) cache keys mismatch for cache: " + DEFAULT_CACHE_NAME, CACHE_KEYS_RANGE, snpIg0.cache(DEFAULT_CACHE_NAME).size());
    assertEquals("The number of all (primary + backup) cache keys mismatch for cache: " + atomicCcfg.getName(), CACHE_KEYS_RANGE, snpIg0.cache(atomicCcfg.getName()).size());
    snpIg0.cache(DEFAULT_CACHE_NAME).query(new ScanQuery<>(null)).forEach(e -> assertTrue("Snapshot must contains only negative values " + "[cache=" + DEFAULT_CACHE_NAME + ", entry=" + e + ']', (Integer) e.getValue() < 0));
    snpIg0.cache(atomicCcfg.getName()).query(new ScanQuery<>(null)).forEach(e -> assertTrue("Snapshot must contains only negative values " + "[cache=" + atomicCcfg.getName() + ", entry=" + e + ']', (Integer) e.getValue() < 0));
}
Also used : GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) ScanQuery(org.apache.ignite.cache.query.ScanQuery) CountDownLatch(java.util.concurrent.CountDownLatch) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) File(java.io.File) Test(org.junit.Test)

Aggregations

DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)29 DiscoveryCustomEvent (org.apache.ignite.internal.events.DiscoveryCustomEvent)10 DynamicCacheChangeBatch (org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch)9 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)8 DiscoveryHook (org.apache.ignite.testframework.GridTestUtils.DiscoveryHook)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 IgniteException (org.apache.ignite.IgniteException)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 DiscoverySpiCustomMessage (org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage)6 Test (org.junit.Test)6 UUID (java.util.UUID)5 TestTcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi)5 Ignite (org.apache.ignite.Ignite)4 Collection (java.util.Collection)3 List (java.util.List)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 IgniteNeedReconnectException (org.apache.ignite.internal.IgniteNeedReconnectException)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3