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());
}
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);
}
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());
}
}
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);
}
}
}
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);
}
}
Aggregations