use of org.apache.ignite.cluster.ClusterState in project ignite by apache.
the class IgniteClusterActivateDeactivateTest method checkCaches.
/**
* @param nodes Number of nodes.
* @param caches Number of caches.
*/
final void checkCaches(int nodes, int caches, boolean awaitExchange) throws InterruptedException {
if (awaitExchange)
awaitPartitionMapExchange();
ClusterState state = ignite(0).cluster().state();
assertActive(state);
for (int i = 0; i < nodes; i++) {
for (int c = 0; c < caches; c++) {
IgniteCache<Integer, Integer> cache = ignite(i).cache(CACHE_NAME_PREFIX + c);
for (int j = 0; j < 10; j++) {
Integer key = ThreadLocalRandom.current().nextInt(1000);
Integer value = j;
if (state == ACTIVE)
cache.put(key, j);
else
assertThrowsWithCause(() -> cache.put(key, value), IgniteClusterReadOnlyException.class);
assertEquals(state == ACTIVE ? value : null, cache.get(key));
}
}
}
}
use of org.apache.ignite.cluster.ClusterState in project ignite by apache.
the class IgniteClusterActivateDeactivateTest method checkClusterStateNotWaitForDeactivation.
/**
*/
private void checkClusterStateNotWaitForDeactivation(ClusterState initialState) throws Exception {
assertActive(initialState);
testSpi = true;
final int nodes = 2;
IgniteEx crd = startGrids(nodes);
crd.cluster().state(initialState);
AffinityTopologyVersion curTopVer = crd.context().discovery().topologyVersionEx();
AffinityTopologyVersion deactivationTopVer = new AffinityTopologyVersion(curTopVer.topologyVersion(), curTopVer.minorTopologyVersion() + 1);
for (int gridIdx = 0; gridIdx < nodes; gridIdx++) blockExchangeSingleMessage(TestRecordingCommunicationSpi.spi(grid(gridIdx)), deactivationTopVer);
IgniteInternalFuture deactivationFut = runAsync(() -> crd.cluster().state(INACTIVE));
// Wait for deactivation start.
assertTrue(GridTestUtils.waitForCondition(() -> {
DiscoveryDataClusterState clusterState = crd.context().state().clusterState();
return clusterState.transition() && !clusterState.state().active();
}, getTestTimeout()));
// Check that deactivation transition wait is not happened.
ClusterState state = crd.context().state().publicApiState(true);
assertInactive(state);
for (int gridIdx = 0; gridIdx < nodes; gridIdx++) TestRecordingCommunicationSpi.spi(grid(gridIdx)).stopBlock();
deactivationFut.get();
}
use of org.apache.ignite.cluster.ClusterState in project ignite by apache.
the class IgniteClusterActivateDeactivateTest method startNodeAndCheckCaches.
/**
*/
private void startNodeAndCheckCaches(int nodeIdx, boolean client, int cachesCount) throws Exception {
startGrid(nodeIdx, client);
ClusterState state = grid(0).cluster().state();
if (state.active()) {
checkCachesOnNode(nodeIdx, cachesCount, !client);
checkCaches(nodeIdx + 1, cachesCount);
}
}
use of org.apache.ignite.cluster.ClusterState in project ignite by apache.
the class IgniteClusterActivateDeactivateTestWithPersistence method testDeactivateClusterWithInMemoryCaches.
/**
* Tests "soft" deactivation (without using the --force flag)
* when the client node does not have the configured data storage and the cluster contains in-memory caches.
*
* Expected behavior: deactivation should fail due to potential data loss.
*
* @throws Exception If failed.
*/
@Test
public void testDeactivateClusterWithInMemoryCaches() throws Exception {
IgniteEx srv = startGrid(0);
IgniteEx clientNode = startClientGrid(1);
clientNode.cluster().state(ACTIVE);
DataStorageConfiguration dsCfg = srv.configuration().getDataStorageConfiguration();
DataRegionConfiguration nonPersistentRegion = Arrays.stream(dsCfg.getDataRegionConfigurations()).filter(region -> NO_PERSISTENCE_REGION.equals(region.getName())).findFirst().orElse(null);
assertTrue("It is assumed that the '" + NO_PERSISTENCE_REGION + "' data storage region exists and non-persistent.", nonPersistentRegion != null && !nonPersistentRegion.isPersistenceEnabled());
// Create a new cache that is placed into non persistent data region.
clientNode.getOrCreateCache(new CacheConfiguration<>("test-client-cache").setDataRegionName(nonPersistentRegion.getName()));
// Try to deactivate the cluster without the `force` flag.
IgniteInternalFuture<?> deactivateFut = srv.context().state().changeGlobalState(INACTIVE, false, Collections.emptyList(), false);
assertThrows(log, () -> deactivateFut.get(10, SECONDS), IgniteCheckedException.class, "Deactivation stopped. Deactivation clears in-memory caches (without persistence) including the system caches.");
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 active state. " + "[node=" + n.configuration().getIgniteInstanceName() + ", actual=" + state + ']', ACTIVE == state);
}
}
use of org.apache.ignite.cluster.ClusterState in project ignite by apache.
the class IgniteClusterImpl method validateBeforeBaselineChange.
/**
* Executes validation checks of cluster state and BaselineTopology before changing BaselineTopology to new one.
*/
private void validateBeforeBaselineChange(Collection<? extends BaselineNode> baselineTop) {
verifyBaselineTopologySupport(ctx.discovery().discoCache());
if (!ctx.state().clusterState().active())
throw new IgniteException("Changing BaselineTopology on inactive cluster is not allowed.");
if (baselineTop != null) {
if (baselineTop.isEmpty())
throw new IgniteException("BaselineTopology must contain at least one node.");
List<BaselineNode> currBlT = Optional.ofNullable(ctx.state().clusterState().baselineTopology()).map(BaselineTopology::currentBaseline).orElse(Collections.emptyList());
Collection<ClusterNode> srvrs = ctx.cluster().get().forServers().nodes();
for (BaselineNode node : baselineTop) {
Object consistentId = node.consistentId();
if (currBlT.stream().noneMatch(currBlTNode -> Objects.equals(currBlTNode.consistentId(), consistentId)) && srvrs.stream().noneMatch(currServersNode -> Objects.equals(currServersNode.consistentId(), consistentId)))
throw new IgniteException("Check arguments. Node with consistent ID [" + consistentId + "] not found in server nodes.");
}
Collection<Object> onlineNodes = onlineBaselineNodesRequestedForRemoval(baselineTop);
if (onlineNodes != null) {
if (!onlineNodes.isEmpty())
throw new IgniteException("Removing online nodes from BaselineTopology is not supported: " + onlineNodes);
}
}
}
Aggregations