use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class WalCompactionTest method testSeekingStartInCompactedSegment.
/**
* @throws Exception If failed.
*/
public void testSeekingStartInCompactedSegment() throws Exception {
IgniteEx ig = (IgniteEx) startGrids(3);
ig.active(true);
IgniteCache<Integer, byte[]> cache = ig.cache("cache");
for (int i = 0; i < 100; i++) {
final byte[] val = new byte[20000];
val[i] = 1;
cache.put(i, val);
}
ig.context().cache().context().database().wakeupForCheckpoint("Forced checkpoint").get();
ig.context().cache().context().database().wakeupForCheckpoint("Forced checkpoint").get();
String nodeFolderName = ig.context().pdsFolderResolver().resolveFolders().folderName();
File dbDir = U.resolveWorkDirectory(U.defaultWorkDirectory(), "db", false);
File nodeLfsDir = new File(dbDir, nodeFolderName);
File cpMarkersDir = new File(nodeLfsDir, "cp");
final File[] cpMarkersToSave = cpMarkersDir.listFiles();
assert cpMarkersToSave != null;
assertTrue(cpMarkersToSave.length >= 2);
Arrays.sort(cpMarkersToSave, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (int i = 100; i < ENTRIES; i++) {
// At least 20MB of raw data in total.
final byte[] val = new byte[20000];
val[i] = 1;
cache.put(i, val);
}
// Spam WAL to move all data records to compressible WAL zone.
for (int i = 0; i < WAL_SEGMENT_SIZE / DFLT_PAGE_SIZE * 2; i++) ig.context().cache().context().wal().log(new PageSnapshot(new FullPageId(-1, -1), new byte[DFLT_PAGE_SIZE]));
// WAL archive segment is allowed to be compressed when it's at least one checkpoint away from current WAL head.
ig.context().cache().context().database().wakeupForCheckpoint("Forced checkpoint").get();
ig.context().cache().context().database().wakeupForCheckpoint("Forced checkpoint").get();
// Allow compressor to archive WAL segments.
Thread.sleep(15_000);
File walDir = new File(dbDir, "wal");
File archiveDir = new File(walDir, "archive");
File nodeArchiveDir = new File(archiveDir, nodeFolderName);
File walSegment = new File(nodeArchiveDir, FileWriteAheadLogManager.FileDescriptor.fileName(0) + ".zip");
assertTrue(walSegment.exists());
// Should be compressed at least in half.
assertTrue(walSegment.length() < WAL_SEGMENT_SIZE / 2);
stopAllGrids();
File[] cpMarkers = cpMarkersDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return !(name.equals(cpMarkersToSave[0].getName()) || name.equals(cpMarkersToSave[1].getName()) || name.equals(cpMarkersToSave[2].getName()) || name.equals(cpMarkersToSave[3].getName()) || name.equals(cpMarkersToSave[4].getName()));
}
});
assertNotNull(cpMarkers);
assertTrue(cpMarkers.length > 0);
File cacheDir = new File(nodeLfsDir, "cache-" + CACHE_NAME);
File[] lfsFiles = cacheDir.listFiles();
assertNotNull(lfsFiles);
assertTrue(lfsFiles.length > 0);
// Enforce reading WAL from the very beginning at the next start.
for (File f : cpMarkers) f.delete();
for (File f : lfsFiles) f.delete();
ig = (IgniteEx) startGrids(3);
ig.active(true);
cache = ig.cache(CACHE_NAME);
int missing = 0;
for (int i = 0; i < 100; i++) {
if (!cache.containsKey(i))
missing++;
}
System.out.println(">>> Missing " + missing + " entries logged before WAL iteration start");
assertTrue(missing > 0);
boolean fail = false;
// Check that all data is recovered from compacted WAL.
for (int i = 100; i < ENTRIES; i++) {
byte[] arr = cache.get(i);
if (arr == null) {
System.out.println(">>> Missing: " + i);
fail = true;
} else if (arr[i] != 1) {
System.out.println(">>> Corrupted: " + i);
fail = true;
}
}
assertFalse(fail);
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgnitePdsCacheAssignmentNodeRestartsTest method testAssignmentAfterRestarts.
/**
* @throws Exception If failed.
*/
public void testAssignmentAfterRestarts() throws Exception {
try {
System.setProperty(IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC, "true");
final int gridsCnt = 5;
final int groupsCnt = 2;
final IgniteEx node = (IgniteEx) startGridsMultiThreaded(gridsCnt);
final List<CacheConfiguration> cfgs = Arrays.asList(cacheConfiguration("g1c1", TRANSACTIONAL, PARTITIONED, gridsCnt, "testGrp1"), cacheConfiguration("g1c2", TRANSACTIONAL, PARTITIONED, gridsCnt, "testGrp1"), cacheConfiguration("g2c1", TRANSACTIONAL, PARTITIONED, gridsCnt, "testGrp2"), cacheConfiguration("g2c2", TRANSACTIONAL, PARTITIONED, gridsCnt, "testGrp2"));
node.getOrCreateCaches(cfgs);
validateDepIds(groupsCnt);
stopAllGrids();
IgniteEx node2 = (IgniteEx) startGridsMultiThreaded(gridsCnt);
// Deployment ids must be the same on all nodes.
validateDepIds(groupsCnt);
final int restartIdxFrom = 2;
final AtomicInteger idx = new AtomicInteger(restartIdxFrom);
IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int nodeIdx = idx.getAndIncrement();
stopGrid(nodeIdx);
return null;
}
}, gridsCnt - restartIdxFrom, "stop-node");
fut.get();
awaitPartitionMapExchange();
checkAffinity();
idx.set(restartIdxFrom);
fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int nodeIdx = idx.getAndIncrement();
startGrid(nodeIdx);
return null;
}
}, gridsCnt - restartIdxFrom, "start-node");
fut.get();
awaitPartitionMapExchange();
AffinityTopologyVersion topVer = node2.context().cache().context().exchange().readyAffinityVersion();
log.info("Using version: " + topVer);
checkAffinity();
} finally {
System.clearProperty(IGNITE_PDS_CHECKPOINT_TEST_SKIP_SYNC);
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgnitePdsExchangeDuringCheckpointTest method testExchangeOnNodeJoin.
/**
*/
public void testExchangeOnNodeJoin() throws Exception {
for (int i = 0; i < 5; i++) {
startGrids(2);
IgniteEx ignite = grid(1);
ignite.active(true);
awaitPartitionMapExchange();
IgniteEx ex = startGrid(2);
awaitPartitionMapExchange();
ex.context().cache().context().database().wakeupForCheckpoint("test").get(10000);
afterTest();
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgnitePdsExchangeDuringCheckpointTest method testExchangeOnNodeLeft.
/**
*/
public void testExchangeOnNodeLeft() throws Exception {
for (int i = 0; i < 5; i++) {
startGrids(3);
IgniteEx ignite = grid(1);
ignite.active(true);
awaitPartitionMapExchange();
stopGrid(0, true);
awaitPartitionMapExchange();
ignite.context().cache().context().database().wakeupForCheckpoint("test").get(10000);
afterTest();
}
}
use of org.apache.ignite.internal.IgniteEx in project ignite by apache.
the class IgnitePdsMultiNodePutGetRestartTest method testPutGetSimple.
/**
* @throws Exception if failed.
*/
public void testPutGetSimple() throws Exception {
info(">>> Will use path: " + allocPath);
startGrids(GRID_CNT);
try {
IgniteEx ig = grid(0);
ig.active(true);
checkPutGetSql(ig, true);
} finally {
stopAllGrids();
}
info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
startGrids(GRID_CNT);
try {
IgniteEx ig = grid(0);
ig.active(true);
checkPutGetSql(ig, false);
} finally {
stopAllGrids();
}
}
Aggregations