use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK 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");
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerDefragmentationTest method testDefragmentationCancelInProgress.
/**
* @throws Exception If failed.
*/
@Test
public void testDefragmentationCancelInProgress() throws Exception {
IgniteEx ig = startGrid(0);
ig.cluster().state(ClusterState.ACTIVE);
IgniteCache<Object, Object> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 1024; i++) cache.put(i, i);
forceCheckpoint(ig);
String grid0ConsId = ig.configuration().getConsistentId().toString();
ListeningTestLogger testLog = new ListeningTestLogger();
CommandHandler cmd = createCommandHandler(testLog);
assertEquals(EXIT_CODE_OK, execute(cmd, "--defragmentation", "schedule", "--nodes", grid0ConsId));
String port = grid(0).localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString();
stopGrid(0);
blockCdl = new CountDownLatch(128);
UnaryOperator<IgniteConfiguration> cfgOp = cfg -> {
DataStorageConfiguration dsCfg = cfg.getDataStorageConfiguration();
FileIOFactory delegate = dsCfg.getFileIOFactory();
dsCfg.setFileIOFactory((file, modes) -> {
if (file.getName().contains("dfrg")) {
if (blockCdl.getCount() == 0) {
try {
// Slow down defragmentation process.
// This'll be enough for the test since we have, like, 900 partitions left.
Thread.sleep(100);
} catch (InterruptedException ignore) {
// No-op.
}
} else
blockCdl.countDown();
}
return delegate.create(file, modes);
});
return cfg;
};
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(() -> {
try {
startGrid(0, cfgOp);
} catch (Exception e) {
// No-op.
throw new RuntimeException(e);
}
});
blockCdl.await();
LogListener logLsnr = LogListener.matches("Defragmentation cancelled successfully.").build();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "cancel"));
assertTrue(logLsnr.check());
fut.get();
testLog.clearListeners();
logLsnr = LogListener.matches("Defragmentation is already completed or has been cancelled previously.").build();
testLog.registerListener(logLsnr);
assertEquals(EXIT_CODE_OK, execute(cmd, "--port", port, "--defragmentation", "cancel"));
assertTrue(logLsnr.check());
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerIndexingCheckSizeTest method validateCheckSizes.
/**
* Checking whether cache and index size check is correct.
*
* @param node Node.
* @param cacheName Cache name.
* @param rmvByTbl Number of deleted items per table.
* @param cacheSizeExp Function for getting expected cache size.
* @param idxSizeExp Function for getting expected index size.
*/
private void validateCheckSizes(IgniteEx node, String cacheName, Map<String, AtomicInteger> rmvByTbl, Function<AtomicInteger, Integer> cacheSizeExp, Function<AtomicInteger, Integer> idxSizeExp) {
requireNonNull(node);
requireNonNull(cacheName);
requireNonNull(rmvByTbl);
requireNonNull(cacheSizeExp);
requireNonNull(idxSizeExp);
injectTestSystemOut();
assertEquals(EXIT_CODE_OK, execute(CACHE.text(), VALIDATE_INDEXES.text(), cacheName, CHECK_SIZES.argName()));
String out = testOut.toString();
assertContains(log, out, "issues found (listed above)");
assertContains(log, out, "Size check");
Map<String, ValidateIndexesCheckSizeResult> valIdxCheckSizeResults = ((VisorValidateIndexesTaskResult) lastOperationResult).results().get(node.localNode().id()).checkSizeResult();
assertEquals(rmvByTbl.size(), valIdxCheckSizeResults.size());
for (Map.Entry<String, AtomicInteger> rmvByTblEntry : rmvByTbl.entrySet()) {
ValidateIndexesCheckSizeResult checkSizeRes = valIdxCheckSizeResults.entrySet().stream().filter(e -> e.getKey().contains(rmvByTblEntry.getKey())).map(Map.Entry::getValue).findAny().orElse(null);
assertNotNull(checkSizeRes);
assertEquals((int) cacheSizeExp.apply(rmvByTblEntry.getValue()), checkSizeRes.cacheSize());
Collection<ValidateIndexesCheckSizeIssue> issues = checkSizeRes.issues();
assertFalse(issues.isEmpty());
issues.forEach(issue -> {
assertEquals((int) idxSizeExp.apply(rmvByTblEntry.getValue()), issue.indexSize());
Throwable err = issue.error();
assertNotNull(err);
assertEquals("Cache and index size not same.", err.getMessage());
});
}
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerTest method testPersistenceBackupAllCachesCommand.
/**
* Test verifies that persistence backup command to backup all caches backs up all cache directories.
*
* @throws Exception If failed.
*/
@Test
public void testPersistenceBackupAllCachesCommand() throws Exception {
String cacheName0 = DEFAULT_CACHE_NAME + "0";
String cacheName1 = DEFAULT_CACHE_NAME + "1";
File mntcNodeWorkDir = startGridAndPutNodeToMaintenance(new CacheConfiguration[] { cacheConfiguration(cacheName0), cacheConfiguration(cacheName1) }, s -> s.equals(cacheName0));
IgniteEx ig1 = startGrid(1);
String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString();
assertEquals(EXIT_CODE_OK, execute("--persistence", "backup", "all", "--host", "localhost", "--port", port));
Set<String> backedUpCacheDirs = Arrays.stream(mntcNodeWorkDir.listFiles()).filter(File::isDirectory).filter(f -> f.getName().startsWith("backup_")).map(f -> f.getName().substring("backup_".length())).collect(Collectors.toCollection(TreeSet::new));
Set<String> allCacheDirs = Arrays.stream(mntcNodeWorkDir.listFiles()).filter(File::isDirectory).filter(f -> f.getName().startsWith("cache-")).map(File::getName).collect(Collectors.toCollection(TreeSet::new));
assertEqualsCollections(backedUpCacheDirs, allCacheDirs);
checkCacheAndBackupDirsContent(mntcNodeWorkDir);
}
use of org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK in project ignite by apache.
the class GridCommandHandlerTest method testPersistenceCleanSpecifiedCachesCommand.
/**
* Test verifies persistence clean command with explicit list of caches to be cleaned.
*
* @throws Exception If failed.
*/
@Test
public void testPersistenceCleanSpecifiedCachesCommand() throws Exception {
String cacheName0 = DEFAULT_CACHE_NAME + "0";
String cacheName1 = DEFAULT_CACHE_NAME + "1";
String cacheName2 = DEFAULT_CACHE_NAME + "2";
String cacheName3 = DEFAULT_CACHE_NAME + "3";
String nonExistingCacheName = DEFAULT_CACHE_NAME + "4";
File mntcNodeWorkDir = startGridAndPutNodeToMaintenance(new CacheConfiguration[] { cacheConfiguration(cacheName0), cacheConfiguration(cacheName1), cacheConfiguration(cacheName2), cacheConfiguration(cacheName3) }, s -> !s.equals(cacheName3));
IgniteEx ig1 = startGrid(1);
String port = ig1.localNode().attribute(IgniteNodeAttributes.ATTR_REST_TCP_PORT).toString();
assertEquals(EXIT_CODE_INVALID_ARGUMENTS, execute("--persistence", "clean", "caches", nonExistingCacheName, "--host", "localhost", "--port", port));
assertEquals(EXIT_CODE_OK, execute("--persistence", "clean", "caches", cacheName0 + "," + cacheName1, "--host", "localhost", "--port", port));
boolean cleanedEmpty = Arrays.stream(mntcNodeWorkDir.listFiles()).filter(f -> f.getName().contains(cacheName0) || f.getName().contains(cacheName1)).map(f -> f.listFiles().length == 1).reduce(true, (t, u) -> t && u);
assertTrue(cleanedEmpty);
boolean nonCleanedNonEmpty = Arrays.stream(mntcNodeWorkDir.listFiles()).filter(f -> f.getName().contains(cacheName2) || f.getName().contains(cacheName3)).map(f -> f.listFiles().length > 1).reduce(true, (t, u) -> t && u);
assertTrue(nonCleanedNonEmpty);
stopGrid(1);
ig1 = startGrid(1);
assertTrue(ig1.context().maintenanceRegistry().isMaintenanceMode());
assertEquals(EXIT_CODE_OK, execute("--persistence", "clean", "caches", cacheName2, "--host", "localhost", "--port", port));
stopGrid(1);
ig1 = startGrid(1);
assertFalse(ig1.context().maintenanceRegistry().isMaintenanceMode());
}
Aggregations