use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.
the class IgniteWalReplayingAfterRestartTest method testWalRecordsAfterRestart.
/**
* @throws Exception If failed.
*/
@Test
public void testWalRecordsAfterRestart() throws Exception {
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
IgniteCache<Integer, byte[]> cache = ignite.getOrCreateCache(CACHE_NAME);
int key = 0;
while (ignite.context().cache().context().wal().lastArchivedSegment() < SEGMENTS_CNT) cache.put(key++ % PART_NUM, new byte[1024]);
ignite.context().cache().context().database().waitForCheckpoint("test-checkpoint");
long lastArchived = ignite.context().cache().context().wal().lastArchivedSegment();
while (ignite.context().cache().context().wal().lastArchivedSegment() < lastArchived + 1) cache.put(key++ % PART_NUM, new byte[1024]);
stopGrid(0);
// There are no exceptions should be thrown here.
ignite = startGrid(0);
ignite.cluster().active();
// delta records should always follow PageSnapshot records.
String workDir = U.defaultWorkDirectory();
IteratorParametersBuilder builder = new IteratorParametersBuilder().filesOrDirs(workDir).filter((rec, ptr) -> rec.purpose() == PHYSICAL);
Map<FullPageId, PageSnapshot> snapshots = new HashMap<>();
try (WALIterator it = new IgniteWalIteratorFactory().iterator(builder)) {
while (it.hasNext()) {
IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
WALRecord rec = tup.get2();
if (rec.type() == CHECKPOINT_RECORD)
snapshots.clear();
// let's check partition meta pages.
if (rec instanceof PageSnapshot) {
PageSnapshot snpRec = (PageSnapshot) rec;
assertFalse(snapshots.containsKey(snpRec.fullPageId()));
snapshots.put(snpRec.fullPageId(), snpRec);
} else if (rec instanceof MetaPageUpdatePartitionDataRecord) {
MetaPageUpdatePartitionDataRecord metaRec = (MetaPageUpdatePartitionDataRecord) rec;
assertTrue(snapshots.containsKey(metaRec.fullPageId()));
}
}
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.
the class WriteAheadLogManagerSelfTest method testGetWalFilesFromArchive.
/**
* Checking the correctness of the method {@link FileWriteAheadLogManager#getWalFilesFromArchive}.
*
* @throws Exception If failed.
*/
@Test
public void testGetWalFilesFromArchive() throws Exception {
IgniteEx n = startGrids(1);
WALPointer segment0WalPtr = new WALPointer(0, 0, 0);
WALPointer segment1WalPtr = new WALPointer(1, 0, 0);
WALPointer segment2WalPtr = new WALPointer(2, 0, 0);
CountDownLatch startLatch = new CountDownLatch(1);
IgniteInternalFuture<Collection<File>> fut = runAsync(() -> {
startLatch.countDown();
return walMgr(n).getWalFilesFromArchive(segment0WalPtr, segment2WalPtr);
});
startLatch.await();
// Check that the expected archiving segment 1.
assertThrows(log, () -> fut.get(1_000), IgniteCheckedException.class, null);
for (int i = 0; walMgr(n).lastArchivedSegment() < 2; i++) n.cache(DEFAULT_CACHE_NAME).put(i, new byte[(int) (10 * U.KB)]);
assertEquals(2, fut.get(getTestTimeout()).size());
forceCheckpoint();
assertEquals(1, walMgr(n).truncate(segment1WalPtr));
assertEquals(0, walMgr(n).getWalFilesFromArchive(segment0WalPtr, segment2WalPtr).size());
assertEquals(1, walMgr(n).getWalFilesFromArchive(segment1WalPtr, segment2WalPtr).size());
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.
the class IgniteWalRebalanceLoggingTest method forceCheckpointAndRollOwerWal.
/**
* Invokes checkpoint forcibly and rollovers WAL segment.
* It might be need for simulate long checkpoint history in test.
*
* @throws Exception If failed.
*/
private void forceCheckpointAndRollOwerWal() throws Exception {
forceCheckpoint();
for (Ignite ignite : G.allGrids()) {
if (ignite.cluster().localNode().isClient())
continue;
IgniteEx ig = (IgniteEx) ignite;
IgniteWriteAheadLogManager walMgr = ig.context().cache().context().wal();
ig.context().cache().context().database().checkpointReadLock();
try {
WALPointer ptr = walMgr.log(new AdHocWALRecord(), CURRENT_SEGMENT);
} finally {
ig.context().cache().context().database().checkpointReadUnlock();
}
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.
the class WalRolloverTypesTest method checkNextSegmentType.
/**
*/
private void checkNextSegmentType(WALMode mode, boolean disableArch) throws Exception {
walMode = mode;
disableWALArchiving = disableArch;
IgniteEx ig = startGrid(0);
ig.cluster().active(true);
IgniteWriteAheadLogManager walMgr = ig.context().cache().context().wal();
ig.context().cache().context().database().checkpointReadLock();
try {
WALPointer ptr = walMgr.log(new AdHocWALRecord(), NEXT_SEGMENT);
assertEquals(1, ptr.index());
} finally {
ig.context().cache().context().database().checkpointReadUnlock();
}
}
use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.
the class WalRolloverTypesTest method checkNextSegmentTypeWithCacheActivity.
/**
* Under load, ensures the record gets into very beginning of the segment in {@code NEXT_SEGMENT} log mode.
*/
private void checkNextSegmentTypeWithCacheActivity(WALMode mode, boolean disableArch) throws Exception {
walMode = mode;
disableWALArchiving = disableArch;
IgniteEx ig = startGrid(0);
ig.cluster().active(true);
IgniteCache<Integer, Integer> cache = ig.getOrCreateCache(DEFAULT_CACHE_NAME);
final long testDuration = 30_000;
long startTime = U.currentTimeMillis();
IgniteInternalFuture<Long> fut = GridTestUtils.runMultiThreadedAsync(() -> {
ThreadLocalRandom random = ThreadLocalRandom.current();
while (U.currentTimeMillis() - startTime < testDuration) cache.put(random.nextInt(100), random.nextInt(100_000));
}, 8, "cache-put-thread");
IgniteWriteAheadLogManager walMgr = ig.context().cache().context().wal();
IgniteCacheDatabaseSharedManager dbMgr = ig.context().cache().context().database();
AdHocWALRecord markerRecord = new AdHocWALRecord();
WALPointer ptr0;
WALPointer ptr1;
do {
try {
U.sleep(1000);
ptr0 = walMgr.log(markerRecord);
dbMgr.checkpointReadLock();
try {
ptr1 = walMgr.log(markerRecord, NEXT_SEGMENT);
} finally {
dbMgr.checkpointReadUnlock();
}
assertTrue(ptr0.index() < ptr1.index());
assertEquals(HEADER_RECORD_SIZE, ptr1.fileOffset());
} catch (IgniteCheckedException e) {
log.error(e.getMessage(), e);
}
} while (U.currentTimeMillis() - startTime < testDuration);
fut.get();
}
Aggregations