use of org.apache.ignite.spi.systemview.view.SystemView in project ignite by apache.
the class SystemViewSelfTest method testContinuousQuery.
/**
*/
@Test
public void testContinuousQuery() throws Exception {
try (IgniteEx originNode = startGrid(0);
IgniteEx remoteNode = startGrid(1)) {
IgniteCache<Integer, Integer> cache = originNode.createCache("cache-1");
SystemView<ContinuousQueryView> origQrys = originNode.context().systemView().view(CQ_SYS_VIEW);
SystemView<ContinuousQueryView> remoteQrys = remoteNode.context().systemView().view(CQ_SYS_VIEW);
assertEquals(0, origQrys.size());
assertEquals(0, remoteQrys.size());
try (QueryCursor qry = cache.query(new ContinuousQuery<>().setInitialQuery(new ScanQuery<>()).setPageSize(100).setTimeInterval(1000).setLocalListener(evts -> {
// No-op.
}).setRemoteFilterFactory(() -> evt -> true))) {
for (int i = 0; i < 100; i++) cache.put(i, i);
checkContinuousQueryView(originNode, origQrys, true);
checkContinuousQueryView(originNode, remoteQrys, false);
}
assertEquals(0, origQrys.size());
assertTrue(waitForCondition(() -> remoteQrys.size() == 0, getTestTimeout()));
}
}
use of org.apache.ignite.spi.systemview.view.SystemView in project ignite by apache.
the class SystemViewSelfTest method testBaselineNodes.
/**
*/
@Test
public void testBaselineNodes() throws Exception {
cleanPersistenceDir();
try (IgniteEx ignite0 = startGrid(getConfiguration(getTestIgniteInstanceName(0)).setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true))).setConsistentId("consId0"));
IgniteEx ignite1 = startGrid(getConfiguration(getTestIgniteInstanceName(1)).setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true))).setConsistentId("consId1"))) {
ignite0.cluster().state(ClusterState.ACTIVE);
ignite1.close();
awaitPartitionMapExchange();
SystemView<BaselineNodeView> view = ignite0.context().systemView().view(BASELINE_NODES_SYS_VIEW);
assertEquals(2, view.size());
assertEquals(1, F.size(view.iterator(), row -> "consId0".equals(row.consistentId()) && row.online()));
assertEquals(1, F.size(view.iterator(), row -> "consId1".equals(row.consistentId()) && !row.online()));
}
}
use of org.apache.ignite.spi.systemview.view.SystemView 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.spi.systemview.view.SystemView in project ignite by apache.
the class SystemViewCommandTest method testPartitionStates.
/**
*/
@Test
public void testPartitionStates() throws Exception {
String nodeName0 = getTestIgniteInstanceName(0);
String nodeName1 = getTestIgniteInstanceName(1);
String nodeName2 = getTestIgniteInstanceName(2);
IgniteCache<Integer, Integer> cache1 = ignite0.createCache(new CacheConfiguration<Integer, Integer>().setName("cache1").setCacheMode(CacheMode.PARTITIONED).setAffinity(new TestAffinityFunction(new String[][] { { nodeName0, nodeName1 }, { nodeName1, nodeName2 }, { nodeName2, nodeName0 } })));
IgniteCache<Integer, Integer> cache2 = ignite0.createCache(new CacheConfiguration<Integer, Integer>().setName("cache2").setCacheMode(CacheMode.PARTITIONED).setAffinity(new TestAffinityFunction(new String[][] { { nodeName0, nodeName1, nodeName2 }, { nodeName1 } })));
for (int i = 0; i < 100; i++) {
cache1.put(i, i);
cache2.put(i, i);
}
try (IgniteEx ignite2 = startGrid(nodeName2)) {
ignite2.rebalanceEnabled(false);
ignite0.cluster().setBaselineTopology(ignite0.cluster().topologyVersion());
String nodeId0 = ignite0.cluster().localNode().id().toString();
String nodeId1 = ignite(1).cluster().localNode().id().toString();
String nodeId2 = ignite2.cluster().localNode().id().toString();
String cacheGrpId1 = Integer.toString(ignite0.cachex("cache1").context().groupId());
String cacheGrpId2 = Integer.toString(ignite0.cachex("cache2").context().groupId());
String owningState = GridDhtPartitionState.OWNING.name();
String movingState = GridDhtPartitionState.MOVING.name();
for (int i = 0; i < 3; i++) {
List<List<String>> partStatesView = systemView(ignite(i), PART_STATES_VIEW);
// Check partitions for cache1.
checkPartitionStatesView(partStatesView, owningState, true, cacheGrpId1, nodeId0, 0);
checkPartitionStatesView(partStatesView, owningState, false, cacheGrpId1, nodeId1, 0);
checkPartitionStatesView(partStatesView, owningState, true, cacheGrpId1, nodeId1, 1);
checkPartitionStatesView(partStatesView, movingState, false, cacheGrpId1, nodeId2, 1);
checkPartitionStatesView(partStatesView, owningState, true, cacheGrpId1, nodeId0, 2);
checkPartitionStatesView(partStatesView, movingState, false, cacheGrpId1, nodeId2, 2);
checkPartitionStatesView(partStatesView, owningState, true, cacheGrpId2, nodeId0, 0);
checkPartitionStatesView(partStatesView, owningState, false, cacheGrpId2, nodeId1, 0);
checkPartitionStatesView(partStatesView, movingState, false, cacheGrpId2, nodeId2, 0);
checkPartitionStatesView(partStatesView, owningState, true, cacheGrpId2, nodeId1, 1);
}
AffinityTopologyVersion topVer = ignite0.context().discovery().topologyVersionEx();
ignite2.rebalanceEnabled(true);
// Wait until rebalance complete.
assertTrue(waitForCondition(() -> ignite0.context().discovery().topologyVersionEx().compareTo(topVer) > 0, getTestTimeout()));
for (int i = 0; i < 3; i++) {
List<List<String>> rows = systemView(ignite(i), PART_STATES_VIEW);
assertEquals(10, rows.stream().filter(row -> (cacheGrpId1.equals(row.get(0)) || cacheGrpId2.equals(row.get(0))) && owningState.equals(row.get(3))).count());
assertTrue(rows.stream().noneMatch(row -> (cacheGrpId1.equals(row.get(0)) || cacheGrpId2.equals(row.get(0))) && movingState.equals(row.get(3))));
}
// Check that assignment is now changed to ideal.
for (int i = 0; i < 3; i++) {
List<List<String>> rows = systemView(ignite(i), PART_STATES_VIEW);
checkPartitionStatesView(rows, owningState, false, cacheGrpId1, nodeId0, 2);
checkPartitionStatesView(rows, owningState, true, cacheGrpId1, nodeId2, 2);
}
} finally {
ignite0.cluster().setBaselineTopology(ignite0.cluster().topologyVersion());
}
}
use of org.apache.ignite.spi.systemview.view.SystemView in project ignite by apache.
the class KillCommandsCommandShTest method testCancelConsistencyTask.
/**
*/
@Test
public void testCancelConsistencyTask() throws InterruptedException {
String consistencyCacheName = "consistencyCache";
CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>();
cfg.setName(consistencyCacheName);
cfg.setBackups(SERVER_NODE_CNT - 1);
cfg.setAffinity(new RendezvousAffinityFunction().setPartitions(1));
IgniteCache<Integer, Integer> cache = client.getOrCreateCache(cfg);
int entries = 10_000;
for (int i = 0; i < entries; i++) cache.put(i, i);
AtomicInteger getCnt = new AtomicInteger();
CountDownLatch thLatch = new CountDownLatch(1);
Thread th = new Thread(() -> {
IgnitePredicate<ComputeJobView> repairJobFilter = job -> job.taskClassName().equals(VisorConsistencyRepairTask.class.getName());
for (IgniteEx node : srvs) {
SystemView<ComputeJobView> jobs = node.context().systemView().view(JOBS_VIEW);
// Found.
assertTrue(F.iterator0(jobs, true, repairJobFilter).hasNext());
}
int res = execute("--consistency", "status");
assertEquals(EXIT_CODE_OK, res);
assertContains(log, testOut.toString(), "Status: 1024/" + entries);
assertNotContains(log, testOut.toString(), VisorConsistencyStatusTask.NOTHING_FOUND);
testOut.reset();
res = execute("--kill", "consistency");
assertEquals(EXIT_CODE_OK, res);
try {
assertTrue(GridTestUtils.waitForCondition(() -> {
for (IgniteEx node : srvs) {
SystemView<ComputeJobView> jobs = node.context().systemView().view(JOBS_VIEW);
if (// Found.
F.iterator0(jobs, true, repairJobFilter).hasNext())
return false;
}
return true;
}, // Missed.
5000L));
} catch (IgniteInterruptedCheckedException e) {
fail();
}
thLatch.countDown();
});
// GridNearGetRequest messages count required to pefrom getAll() with readRepair from all nodes twice.
// First will be finished (which generates status), second will be frozen.
int twiceGetMsgCnt = SERVER_NODE_CNT * (SERVER_NODE_CNT - 1) * 2;
for (IgniteEx server : srvs) {
TestRecordingCommunicationSpi spi = ((TestRecordingCommunicationSpi) server.configuration().getCommunicationSpi());
AtomicInteger locLimit = new AtomicInteger(SERVER_NODE_CNT - 1);
spi.blockMessages((node, message) -> {
if (message instanceof GridNearGetRequest) {
// Each node should perform get twice.
if (getCnt.incrementAndGet() == twiceGetMsgCnt)
th.start();
// Cancellation should stop the process.
assertTrue(getCnt.get() <= twiceGetMsgCnt);
// Blocking to freeze '--consistency repair' operation (except first get).
return locLimit.decrementAndGet() < 0;
}
return false;
});
}
injectTestSystemOut();
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--consistency", "repair", ConsistencyCommand.STRATEGY, ReadRepairStrategy.LWW.toString(), ConsistencyCommand.PARTITION, "0", ConsistencyCommand.CACHE, consistencyCacheName));
assertContains(log, testOut.toString(), "Operation execution cancelled.");
assertContains(log, testOut.toString(), VisorConsistencyRepairTask.NOTHING_FOUND);
assertNotContains(log, testOut.toString(), VisorConsistencyRepairTask.CONSISTENCY_VIOLATIONS_FOUND);
thLatch.await();
for (IgniteEx server : srvs) {
// Restoring messaging for other tests.
TestRecordingCommunicationSpi spi = ((TestRecordingCommunicationSpi) server.configuration().getCommunicationSpi());
spi.stopBlock();
}
testOut.reset();
int res = execute("--consistency", "status");
assertEquals(EXIT_CODE_OK, res);
assertContains(log, testOut.toString(), VisorConsistencyStatusTask.NOTHING_FOUND);
assertNotContains(log, testOut.toString(), "Status");
}
Aggregations