Search in sources :

Example 16 with ClusterState

use of org.apache.ignite.cluster.ClusterState in project ignite by apache.

the class GridClusterStateProcessor method publicApiStateAsync.

/**
 * {@inheritDoc}
 */
@Override
public IgniteFuture<ClusterState> publicApiStateAsync(boolean asyncWaitForTransition) {
    if (ctx.isDaemon())
        return sendComputeCheckGlobalState();
    DiscoveryDataClusterState globalState = this.globalState;
    assert globalState != null;
    if (globalState.transition() && globalState.state().active()) {
        ClusterState transitionRes = globalState.transitionResult();
        if (transitionRes != null)
            return new IgniteFinishedFutureImpl<>(transitionRes);
        else {
            GridFutureAdapter<Void> fut = transitionFuts.get(globalState.transitionRequestId());
            if (fut != null) {
                if (asyncWaitForTransition) {
                    return new IgniteFutureImpl<>(fut.chain((C1<IgniteInternalFuture<Void>, ClusterState>) f -> {
                        ClusterState res = globalState.transitionResult();
                        assert res != null;
                        return res;
                    }));
                } else
                    return new IgniteFinishedFutureImpl<>(stateWithMinimalFeatures(globalState.lastState(), globalState.state()));
            }
            transitionRes = globalState.transitionResult();
            assert transitionRes != null;
            return new IgniteFinishedFutureImpl<>(transitionRes);
        }
    } else
        return new IgniteFinishedFutureImpl<>(globalState.state());
}
Also used : ClusterState(org.apache.ignite.cluster.ClusterState) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) IgniteFinishedFutureImpl(org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl) C1(org.apache.ignite.internal.util.typedef.C1)

Example 17 with ClusterState

use of org.apache.ignite.cluster.ClusterState in project ignite by apache.

the class GridClusterStateProcessor method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    IgniteConfiguration cfg = ctx.config();
    inMemoryMode = !CU.isPersistenceEnabled(cfg);
    ClusterState stateOnStart;
    if (inMemoryMode) {
        stateOnStart = cfg.getClusterStateOnStart();
        boolean activeOnStartSet = getBooleanFieldFromConfig(cfg, "activeOnStartPropSetFlag", false);
        if (activeOnStartSet) {
            if (stateOnStart != null)
                log.warning("Property `activeOnStart` will be ignored due to the property `clusterStateOnStart` is presented.");
            else
                stateOnStart = cfg.isActiveOnStart() ? ACTIVE : INACTIVE;
        } else if (stateOnStart == null)
            stateOnStart = DFLT_STATE_ON_START;
    } else {
        // Start first node as inactive if persistence is enabled.
        stateOnStart = INACTIVE;
        if (cfg.getClusterStateOnStart() != null && getBooleanFieldFromConfig(cfg, "autoActivationPropSetFlag", false))
            log.warning("Property `autoActivation` will be ignored due to the property `clusterStateOnStart` is presented.");
    }
    globalState = DiscoveryDataClusterState.createState(stateOnStart, null);
    ctx.event().addLocalEventListener(lsr, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
Also used : ClusterState(org.apache.ignite.cluster.ClusterState) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration)

Example 18 with ClusterState

use of org.apache.ignite.cluster.ClusterState in project ignite by apache.

the class ClusterActivationEventTest method checkClusterEvents.

/**
 * @param task Test.
 * @param lsnr Listener.
 * @param evtType Event type.
 * @param evtCnt Events count.
 */
private void checkClusterEvents(ClusterActivationTestTask task, IgnitePredicate<? extends Event> lsnr, ClusterState initState, int evtType, int evtCnt) throws Exception {
    IgniteEx crd = grid(0);
    if (crd.cluster().state() != initState)
        crd.cluster().state(initState);
    for (Ignite ignite : G.allGrids()) assertEquals(ignite.name(), initState, ignite.cluster().state());
    Map<Ignite, Long> maxLocEvtId = new HashMap<>();
    Map<Ignite, IgniteFuture<Event>> evtFuts = new HashMap<>();
    for (Ignite ignite : G.allGrids()) {
        Collection<Event> evts = ignite.events().localQuery(F.alwaysTrue(), evtType);
        long id = evts.isEmpty() ? 0 : Collections.max(evts, comparingLong(Event::localOrder)).localOrder();
        ignite.events().localListen(lsnr, evtType);
        maxLocEvtId.put(ignite, id);
        evtFuts.put(ignite, waitForLocalEvent(ignite.events(), e -> e.localOrder() > id, evtType));
    }
    task.execute(crd.cluster());
    for (Ignite ignite : maxLocEvtId.keySet()) {
        // We should wait received event on local node.
        evtFuts.get(ignite).get(2 * DELAY);
        Collection<Event> evts = ignite.events().localQuery(e -> e.localOrder() > maxLocEvtId.get(ignite), evtType);
        assertEquals(ignite.name() + " events: " + evts, evtCnt, evts.size());
    }
}
Also used : IntStream(java.util.stream.IntStream) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteCluster(org.apache.ignite.IgniteCluster) Map(java.util.Map) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) G(org.apache.ignite.internal.util.typedef.G) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) IgniteFuture(org.apache.ignite.lang.IgniteFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) EventType(org.apache.ignite.events.EventType) EVT_CLUSTER_DEACTIVATED(org.apache.ignite.events.EventType.EVT_CLUSTER_DEACTIVATED) Collection(java.util.Collection) Event(org.apache.ignite.events.Event) EVT_CLUSTER_ACTIVATED(org.apache.ignite.events.EventType.EVT_CLUSTER_ACTIVATED) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) StopNodeOrHaltFailureHandler(org.apache.ignite.failure.StopNodeOrHaltFailureHandler) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Comparator.comparingLong(java.util.Comparator.comparingLong) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Comparator.comparingLong(java.util.Comparator.comparingLong) IgniteFuture(org.apache.ignite.lang.IgniteFuture) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite)

Example 19 with ClusterState

use of org.apache.ignite.cluster.ClusterState in project ignite by apache.

the class ClusterStateChangeEventTest method changeStateAndCheckEvents.

/**
 */
private void changeStateAndCheckEvents(ClusterState state) throws IgniteCheckedException {
    IgniteEx crd = grid(0);
    ClusterState prevState = crd.cluster().state();
    Collection<BaselineNode> blt = crd.cluster().currentBaselineTopology();
    assertNotSame(prevState, state);
    Map<Ignite, IgniteFuture<Event>> evtFuts = new HashMap<>();
    for (Ignite node : G.allGrids()) {
        Event event = max(node.events().localQuery(F.alwaysTrue(), EVT_CLUSTER_STATE_CHANGED), comparingLong(Event::localOrder));
        log.info("Event with highest local id for node: " + node.name() + " is: " + event);
        evtFuts.put(node, waitForLocalEvent(node.events(), e -> e.localOrder() > event.localOrder(), EVT_CLUSTER_STATE_CHANGED));
    }
    crd.cluster().state(state);
    for (Ignite node : evtFuts.keySet()) {
        assertEquals(node.name(), state, node.cluster().state());
        Event e = evtFuts.get(node).get(1000L);
        assertNotNull(node.name(), e);
        assertTrue(node.name() + " " + e, e instanceof ClusterStateChangeEvent);
        ClusterStateChangeEvent changeEvent = (ClusterStateChangeEvent) e;
        assertEquals(prevState, changeEvent.previousState());
        assertEquals(state, changeEvent.state());
        if (blt == null)
            assertNull(node.name(), changeEvent.baselineNodes());
        else {
            assertNotNull(changeEvent.baselineNodes());
            Set<Object> bltIds = blt.stream().map(BaselineNode::consistentId).collect(toSet());
            Set<Object> evtBltIds = changeEvent.baselineNodes().stream().map(BaselineNode::consistentId).collect(toSet());
            assertEqualsCollections(bltIds, evtBltIds);
        }
    }
}
Also used : IntStream(java.util.stream.IntStream) ClusterState(org.apache.ignite.cluster.ClusterState) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) ACTIVE_READ_ONLY(org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY) Map(java.util.Map) Collectors.toSet(java.util.stream.Collectors.toSet) G(org.apache.ignite.internal.util.typedef.G) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) IgniteFuture(org.apache.ignite.lang.IgniteFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) EventType(org.apache.ignite.events.EventType) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Event(org.apache.ignite.events.Event) Set(java.util.Set) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) EVT_CLUSTER_STATE_CHANGED(org.apache.ignite.events.EventType.EVT_CLUSTER_STATE_CHANGED) Collectors(java.util.stream.Collectors) BaselineNode(org.apache.ignite.cluster.BaselineNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClusterStateChangeEvent(org.apache.ignite.events.ClusterStateChangeEvent) Comparator.comparingLong(java.util.Comparator.comparingLong) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections.max(java.util.Collections.max) ClusterState(org.apache.ignite.cluster.ClusterState) HashMap(java.util.HashMap) IgniteFuture(org.apache.ignite.lang.IgniteFuture) ClusterStateChangeEvent(org.apache.ignite.events.ClusterStateChangeEvent) BaselineNode(org.apache.ignite.cluster.BaselineNode) IgniteEx(org.apache.ignite.internal.IgniteEx) Event(org.apache.ignite.events.Event) ClusterStateChangeEvent(org.apache.ignite.events.ClusterStateChangeEvent) Ignite(org.apache.ignite.Ignite)

Example 20 with ClusterState

use of org.apache.ignite.cluster.ClusterState in project ignite by apache.

the class IgniteClusterActivateDeactivateTestWithPersistence method testDeactivateClusterWithPersistentCachesAndDifferentDataRegions.

/**
 * Tests "soft" deactivation (without using the --force flag)
 * when the cluster contains persistent caches and cluster nodes "support" different lists of data regions.
 *
 * Expected behavior: the cluster should be deactivated successfully (there is no data loss)..
 *
 * @throws Exception If failed.
 */
@Test
public void testDeactivateClusterWithPersistentCachesAndDifferentDataRegions() throws Exception {
    IgniteEx srv = startGrid(0);
    addAdditionalDataRegion = true;
    IgniteEx srv1 = startGrid(1);
    IgniteEx clientNode = startClientGrid(2);
    clientNode.cluster().state(ACTIVE);
    DataStorageConfiguration dsCfg = srv1.configuration().getDataStorageConfiguration();
    DataRegionConfiguration persistentRegion = Arrays.stream(dsCfg.getDataRegionConfigurations()).filter(region -> ADDITIONAL_PERSISTENT_DATA_REGION.equals(region.getName())).findFirst().orElse(null);
    assertTrue("It is assumed that the '" + ADDITIONAL_PERSISTENT_DATA_REGION + "' data storage region exists and persistent.", persistentRegion != null && persistentRegion.isPersistenceEnabled());
    final UUID srv1NodeId = srv1.localNode().id();
    // Create a new cache that is placed into persistent data region.
    srv.getOrCreateCache(new CacheConfiguration<>("test-client-cache").setDataRegionName(persistentRegion.getName()).setAffinity(new RendezvousAffinityFunction(false, 1)).setNodeFilter(node -> node.id().equals(srv1NodeId)));
    // Try to deactivate the cluster without the `force` flag.
    IgniteInternalFuture<?> deactivateFut = srv.context().state().changeGlobalState(INACTIVE, false, Collections.emptyList(), false);
    try {
        deactivateFut.get(10, SECONDS);
    } catch (IgniteCheckedException e) {
        log.error("Failed to deactivate the cluster.", e);
        fail("Failed to deactivate the cluster. [err=" + e.getMessage() + ']');
    }
    awaitPartitionMapExchange();
    // Let's check that all nodes in the cluster have the same state.
    for (Ignite node : G.allGrids()) {
        IgniteEx n = (IgniteEx) node;
        ClusterState state = n.context().state().clusterState().state();
        assertTrue("Node must be in inactive state. " + "[node=" + n.configuration().getIgniteInstanceName() + ", actual=" + state + ']', INACTIVE == state);
    }
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Arrays(java.util.Arrays) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ClusterState(org.apache.ignite.cluster.ClusterState) GridTestUtils.assertThrows(org.apache.ignite.testframework.GridTestUtils.assertThrows) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) GridTestUtils.assertActive(org.apache.ignite.testframework.GridTestUtils.assertActive) LinkedHashMap(java.util.LinkedHashMap) ACTIVE_READ_ONLY(org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Assume(org.junit.Assume) GridTestUtils.assertThrowsAnyCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsAnyCause) G(org.apache.ignite.internal.util.typedef.G) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteClusterReadOnlyException(org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) MvccFeatureChecker(org.apache.ignite.testframework.MvccFeatureChecker) CU(org.apache.ignite.internal.util.typedef.internal.CU) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) Assert(org.junit.Assert) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ClusterState(org.apache.ignite.cluster.ClusterState) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Aggregations

ClusterState (org.apache.ignite.cluster.ClusterState)20 Map (java.util.Map)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 IgniteEx (org.apache.ignite.internal.IgniteEx)8 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 Test (org.junit.Test)7 Ignite (org.apache.ignite.Ignite)6 DiscoveryDataClusterState (org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState)6 Collection (java.util.Collection)5 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5 Set (java.util.Set)5 UUID (java.util.UUID)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 F (org.apache.ignite.internal.util.typedef.F)5 List (java.util.List)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 CU (org.apache.ignite.internal.util.typedef.internal.CU)4