Search in sources :

Example 11 with DiscoveryCustomEvent

use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.

the class IgniteStatisticsConfigurationManager method afterTopologyUnlock.

/**
 * Update statistics after topology change, if necessary.
 *
 * @param fut Topology change future.
 */
public void afterTopologyUnlock(GridDhtPartitionsExchangeFuture fut) {
    topVer = fut.topologyVersion();
    // Skip join/left client nodes.
    if (fut.exchangeType() != GridDhtPartitionsExchangeFuture.ExchangeType.ALL || (persistence && cluster.clusterState().lastState() != ClusterState.ACTIVE))
        return;
    DiscoveryEvent evt = fut.firstEvent();
    // Skip create/destroy caches.
    if (evt.type() == DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) {
        DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) evt).customMessage();
        if (msg instanceof DynamicCacheChangeBatch)
            return;
    }
    mgmtBusyExecutor.execute(this::updateAllLocalStatistics);
}
Also used : DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent)

Example 12 with DiscoveryCustomEvent

use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.

the class IgniteClusterSnapshotSelfTest method testClusterSnapshotOnMovingPartitionsCoordinatorLeft.

/**
 * @throws Exception If fails.
 */
@Test
public void testClusterSnapshotOnMovingPartitionsCoordinatorLeft() throws Exception {
    startGridsWithCache(2, dfltCacheCfg, CACHE_KEYS_RANGE);
    for (Ignite grid : G.allGrids()) {
        TestRecordingCommunicationSpi.spi(grid).blockMessages((node, msg) -> msg instanceof GridDhtPartitionSupplyMessage);
    }
    Ignite ignite = startGrid(2);
    ignite.cluster().setBaselineTopology(ignite.cluster().topologyVersion());
    TestRecordingCommunicationSpi.spi(grid(0)).waitForBlocked();
    CountDownLatch latch = new CountDownLatch(G.allGrids().size());
    IgniteInternalFuture<?> stopFut = GridTestUtils.runAsync(() -> {
        try {
            U.await(latch);
            stopGrid(0);
        } catch (IgniteInterruptedCheckedException e) {
            fail("Must not fail here: " + e.getMessage());
        }
    });
    Queue<T2<GridDhtPartitionExchangeId, Boolean>> exchFuts = new ConcurrentLinkedQueue<>();
    for (Ignite ig : G.allGrids()) {
        ((IgniteEx) ig).context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
                if (!(fut.firstEvent() instanceof DiscoveryCustomEvent))
                    return;
                try {
                    exchFuts.add(new T2<>(fut.exchangeId(), fut.rebalanced()));
                    latch.countDown();
                    stopFut.get();
                } catch (IgniteCheckedException e) {
                    U.log(log, "Interrupted on coordinator: " + e.getMessage());
                }
            }
        });
    }
    IgniteFuture<Void> fut = ignite.snapshot().createSnapshot(SNAPSHOT_NAME);
    stopFut.get();
    assertThrowsAnyCause(log, fut::get, IgniteException.class, "Snapshot creation has been finished with an error");
    assertEquals("Snapshot futures expected: " + exchFuts, 3, exchFuts.size());
    for (T2<GridDhtPartitionExchangeId, Boolean> exch : exchFuts) assertFalse("Snapshot `rebalanced` must be false with moving partitions: " + exch.get1(), exch.get2());
}
Also used : GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) CountDownLatch(java.util.concurrent.CountDownLatch) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) T2(org.apache.ignite.internal.util.typedef.T2) Test(org.junit.Test)

Example 13 with DiscoveryCustomEvent

use of org.apache.ignite.internal.events.DiscoveryCustomEvent 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 14 with DiscoveryCustomEvent

use of org.apache.ignite.internal.events.DiscoveryCustomEvent 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 15 with DiscoveryCustomEvent

use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.

the class CacheBlockOnReadAbstractTest method testUpdateBaselineTopologyTransactionalReplicated.

/**
 * @throws Exception If failed.
 */
@Params(timeout = 5000L, atomicityMode = TRANSACTIONAL, cacheMode = REPLICATED)
@Test
public void testUpdateBaselineTopologyTransactionalReplicated() throws Exception {
    doTest(asMessagePredicate(discoEvt -> {
        if (discoEvt instanceof DiscoveryCustomEvent) {
            DiscoveryCustomEvent discoCustomEvt = (DiscoveryCustomEvent) discoEvt;
            DiscoveryCustomMessage customMsg = discoCustomEvt.customMessage();
            return customMsg instanceof ChangeGlobalStateMessage;
        }
        return false;
    }), () -> {
        startNodesInClientMode(false);
        IgniteEx ignite = startGrid(UUID.randomUUID().toString());
        baseline.get(0).cluster().setBaselineTopology(baseline.get(0).context().discovery().topologyVersion());
        baseline.add(ignite);
    });
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) Arrays(java.util.Arrays) TcpDiscoveryNodeAddFinishedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddFinishedMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) X(org.apache.ignite.internal.util.typedef.X) PARTITIONED(org.apache.ignite.cache.CacheMode.PARTITIONED) TcpDiscoveryNodeLeftMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeLeftMessage) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) Predicate(java.util.function.Predicate) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) UUID(java.util.UUID) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) CountDownLatch(java.util.concurrent.CountDownLatch) ExchangeActions(org.apache.ignite.internal.processors.cache.ExchangeActions) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Message(org.apache.ignite.plugin.extensions.communication.Message) RunnableX(org.apache.ignite.testframework.GridTestUtils.RunnableX) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) NotNull(org.jetbrains.annotations.NotNull) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TcpDiscoveryIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) U(org.apache.ignite.internal.util.typedef.internal.U) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) BiConsumer(java.util.function.BiConsumer) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) CacheActionData(org.apache.ignite.internal.processors.cache.ExchangeActions.CacheActionData) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Target(java.lang.annotation.Target) Test(org.junit.Test) ElementType(java.lang.annotation.ElementType) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) REPLICATED(org.apache.ignite.cache.CacheMode.REPLICATED) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) ATOMIC(org.apache.ignite.cache.CacheAtomicityMode.ATOMIC) GridDhtPartitionExchangeId(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionExchangeId) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) RetentionPolicy(java.lang.annotation.RetentionPolicy) CacheMode(org.apache.ignite.cache.CacheMode) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) IgniteEx(org.apache.ignite.internal.IgniteEx) ChangeGlobalStateMessage(org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

DiscoveryCustomEvent (org.apache.ignite.internal.events.DiscoveryCustomEvent)16 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)10 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 DynamicCacheChangeBatch (org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)5 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3 UUID (java.util.UUID)3 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)3 IgniteNeedReconnectException (org.apache.ignite.internal.IgniteNeedReconnectException)3 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)3 SnapshotDiscoveryMessage (org.apache.ignite.internal.processors.cache.persistence.snapshot.SnapshotDiscoveryMessage)3 Test (org.junit.Test)3 Map (java.util.Map)2 Set (java.util.Set)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2