Search in sources :

Example 56 with WALPointer

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()));
            }
        }
    }
}
Also used : IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) HashMap(java.util.HashMap) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteEx(org.apache.ignite.internal.IgniteEx) MetaPageUpdatePartitionDataRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 57 with WALPointer

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());
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) Collection(java.util.Collection) CountDownLatch(java.util.concurrent.CountDownLatch) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 58 with WALPointer

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();
        }
    }
}
Also used : IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 59 with WALPointer

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();
    }
}
Also used : IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteEx(org.apache.ignite.internal.IgniteEx) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 60 with WALPointer

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();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Aggregations

WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)122 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)44 Test (org.junit.Test)41 IgniteEx (org.apache.ignite.internal.IgniteEx)38 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)36 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)30 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)24 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)23 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)23 ArrayList (java.util.ArrayList)20 IgniteWalIteratorFactory (org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory)20 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)19 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)19 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)19 File (java.io.File)18 T2 (org.apache.ignite.internal.util.typedef.T2)16 ByteBuffer (java.nio.ByteBuffer)15 UUID (java.util.UUID)15 IOException (java.io.IOException)14