use of org.apache.ignite.cluster.ClusterState.INACTIVE in project ignite by apache.
the class SystemViewCommandTest method testPagesList.
/**
*/
@Test
public void testPagesList() throws Exception {
String cacheName = "cacheFL";
IgniteCache<Integer, byte[]> cache = ignite0.getOrCreateCache(new CacheConfiguration<Integer, byte[]>().setName(cacheName).setAffinity(new RendezvousAffinityFunction().setPartitions(1)));
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ignite0.context().cache().context().database();
int pageSize = dbMgr.pageSize();
try {
dbMgr.enableCheckpoints(false).get();
int key = 0;
// Fill up different free-list buckets.
for (int j = 0; j < pageSize / 2; j++) cache.put(key++, new byte[j + 1]);
// Put some pages to one bucket to overflow pages cache.
for (int j = 0; j < 1000; j++) cache.put(key++, new byte[pageSize / 2]);
List<List<String>> cacheGrpView = systemView(ignite0, CACHE_GRP_PAGE_LIST_VIEW);
List<List<String>> dataRegionView = systemView(ignite0, DATA_REGION_PAGE_LIST_VIEW);
String cacheId = Integer.toString(cacheId(cacheName));
// Test filtering by 3 columns.
assertFalse(cacheGrpView.stream().noneMatch(row -> cacheId.equals(row.get(0)) && "0".equals(row.get(1)) && "0".equals(row.get(3))));
// Test filtering with invalid cache group id.
assertTrue(cacheGrpView.stream().noneMatch(row -> "-1".equals(row.get(0))));
// Test filtering with invalid partition id.
assertTrue(cacheGrpView.stream().noneMatch(row -> "-1".equals(row.get(1))));
// Test filtering with invalid bucket number.
assertTrue(cacheGrpView.stream().noneMatch(row -> "-1".equals(row.get(3))));
assertFalse(cacheGrpView.stream().noneMatch(row -> Integer.parseInt(row.get(4)) > 0 && cacheId.equals(row.get(0))));
assertFalse(cacheGrpView.stream().noneMatch(row -> Integer.parseInt(row.get(5)) > 0 && cacheId.equals(row.get(0))));
assertFalse(cacheGrpView.stream().noneMatch(row -> Integer.parseInt(row.get(6)) > 0 && cacheId.equals(row.get(0))));
assertFalse(dataRegionView.stream().noneMatch(row -> row.get(0).startsWith(DATA_REGION_NAME)));
assertTrue(dataRegionView.stream().noneMatch(row -> row.get(0).startsWith(DATA_REGION_NAME) && Integer.parseInt(row.get(4)) > 0));
} finally {
dbMgr.enableCheckpoints(true).get();
}
ignite0.cluster().state(INACTIVE);
ignite0.cluster().state(ACTIVE);
IgniteCache<Integer, Integer> cacheInMemory = ignite0.getOrCreateCache(new CacheConfiguration<Integer, Integer>().setName("cacheFLInMemory").setDataRegionName(DATA_REGION_NAME));
cacheInMemory.put(0, 0);
// After activation/deactivation new view for data region pages lists should be created, check that new view
// correctly reflects changes in free-lists.
assertTrue(systemView(ignite0, DATA_REGION_PAGE_LIST_VIEW).stream().noneMatch(row -> row.get(0).startsWith(DATA_REGION_NAME) && Integer.parseInt(row.get(4)) > 0));
}
use of org.apache.ignite.cluster.ClusterState.INACTIVE 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);
}
}
}
use of org.apache.ignite.cluster.ClusterState.INACTIVE in project ignite by apache.
the class GridCommandHandlerTest method testBaselineAddOnNotActiveCluster.
/**
* Test baseline add items works via control.sh
*
* @throws Exception If failed.
*/
@Test
public void testBaselineAddOnNotActiveCluster() throws Exception {
Ignite ignite = startGrid(1);
assertFalse(ignite.cluster().active());
String consistentIDs = getTestIgniteInstanceName(1);
injectTestSystemOut();
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--baseline", "add", consistentIDs));
assertContains(log, testOut.toString(), "Changing BaselineTopology on inactive cluster is not allowed.");
consistentIDs = getTestIgniteInstanceName(1) + ", " + getTestIgniteInstanceName(2) + "," + getTestIgniteInstanceName(3);
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--baseline", "add", consistentIDs));
String testOutStr = testOut.toString();
// Ignite instase 1 can be logged only in arguments list.
boolean isInstanse1Found = Arrays.stream(testOutStr.split("\n")).filter(s -> s.contains("Arguments:")).noneMatch(s -> s.contains(getTestIgniteInstanceName() + "1"));
assertTrue(testOutStr, testOutStr.contains("Node not found for consistent ID:"));
assertFalse(testOutStr, isInstanse1Found);
}
use of org.apache.ignite.cluster.ClusterState.INACTIVE in project ignite by apache.
the class ClusterStateChangeEventTest method test.
/**
*/
@Test
public void test() throws Exception {
IgniteEx crd = grid(0);
crd.cluster().state(ACTIVE);
Map<Integer, Integer> data = IntStream.range(0, 1000).boxed().collect(Collectors.toMap(i -> i, i -> i));
crd.cache(DEFAULT_CACHE_NAME).putAll(data);
for (Ignite node : G.allGrids()) assertEquals(node.name(), ACTIVE, node.cluster().state());
// ACTIVE -> READ_ONLY
changeStateAndCheckEvents(ACTIVE_READ_ONLY);
// READ_ONLY -> ACTIVE
changeStateAndCheckEvents(ACTIVE);
// ACTIVE -> INACTIVE
changeStateAndCheckEvents(INACTIVE);
// INACTIVE -> READ_ONLY
changeStateAndCheckEvents(ACTIVE_READ_ONLY);
// READ_ONLY -> INACTIVE
changeStateAndCheckEvents(INACTIVE);
// INACTIVE -> ACTIVE
changeStateAndCheckEvents(ACTIVE);
}
use of org.apache.ignite.cluster.ClusterState.INACTIVE 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