Search in sources :

Example 41 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class PageMemoryTracker method createWalManager.

/**
 * Creates WAL manager.
 */
IgniteWriteAheadLogManager createWalManager() {
    if (isEnabled()) {
        return new FileWriteAheadLogManager(gridCtx) {

            @Override
            public WALPointer log(WALRecord record) throws IgniteCheckedException {
                WALPointer res = super.log(record);
                applyWalRecord(record);
                return res;
            }

            @Override
            public void resumeLogging(WALPointer lastPtr) throws IgniteCheckedException {
                super.resumeLogging(lastPtr);
                if (lastPtr == null)
                    emptyPds = true;
            }
        };
    }
    return null;
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)

Example 42 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class StandaloneWalRecordsIteratorTest method testNoNextIfLowBoundInTheEnd.

/**
 */
@Test
public void testNoNextIfLowBoundInTheEnd() throws Exception {
    String dir = createWalFiles(3);
    WALIterator iter = createWalIterator(dir, null, null, false);
    assertFalse(iter.lastRead().isPresent());
    assertTrue(iter.hasNext());
    while (iter.hasNext()) {
        IgniteBiTuple<WALPointer, WALRecord> curr = iter.next();
        assertEquals("Last read should point to the current record", curr.get1(), iter.lastRead().get());
    }
    iter.close();
    iter = createWalIterator(dir, iter.lastRead().get().next(), null, false);
    assertFalse(iter.lastRead().isPresent());
    assertFalse(iter.hasNext());
    iter.close();
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 43 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class StandaloneWalRecordsIteratorTest method testNextRecordReturnedForLowBounds.

/**
 */
@Test
public void testNextRecordReturnedForLowBounds() throws Exception {
    String dir = createWalFiles(3);
    WALIterator iter = createWalIterator(dir, null, null, false);
    IgniteBiTuple<WALPointer, WALRecord> prev = iter.next();
    assertEquals("Last read should point to the current record", prev.get1(), iter.lastRead().get());
    iter.close();
    iter = createWalIterator(dir, iter.lastRead().get().next(), null, false);
    assertFalse(iter.lastRead().isPresent());
    assertTrue(iter.hasNext());
    while (iter.hasNext()) {
        IgniteBiTuple<WALPointer, WALRecord> cur = iter.next();
        assertEquals("Last read should point to the current record", cur.get1(), iter.lastRead().get());
        assertFalse("Should read next record[prev=" + prev.get1() + ", cur=" + cur.get1() + ']', prev.get1().equals(cur.get1()));
        prev = cur;
        iter.close();
        iter = createWalIterator(dir, iter.lastRead().get().next(), null, false);
        assertFalse(iter.lastRead().isPresent());
    }
    iter.close();
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 44 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class StandaloneWalRecordsIteratorTest method testLastRecordFiltered.

/**
 */
@Test
public void testLastRecordFiltered() throws Exception {
    String dir = createWalFiles();
    WALIterator iter = createWalIterator(dir, null, null, false);
    IgniteBiTuple<WALPointer, WALRecord> lastRec = null;
    // Search for the last record.
    while (iter.hasNext()) lastRec = iter.next();
    iter.close();
    assertNotNull(lastRec);
    WALPointer lastPointer = iter.lastRead().get();
    WALRecord.RecordType lastRecType = lastRec.get2().type();
    // Iterating and filter out last record.
    iter = createWalIterator(dir, null, null, false, (type, ptr) -> type != lastRecType);
    assertTrue(iter.hasNext());
    while (iter.hasNext()) {
        lastRec = iter.next();
        // Type is null for filtered records.
        assertNotNull(lastRec.get2().type());
        assertTrue(lastRec.get2().type() != lastRecType);
    }
    iter.close();
    assertNotNull(lastRec);
    assertEquals("LastRead should point to the last WAL Record even it filtered", lastPointer, iter.lastRead().get());
    // Record on `lastPointer` is filtered so.
    assertEquals("Last returned record should be before lastPointer", -1, lastRec.get1().compareTo(lastPointer));
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) Arrays(java.util.Arrays) SnapshotRecord(org.apache.ignite.internal.pagemem.wal.record.SnapshotRecord) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) RandomAccessFileIO(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIO) U(org.apache.ignite.internal.util.typedef.internal.U) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NullLogger(org.apache.ignite.logger.NullLogger) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) RolloverType(org.apache.ignite.internal.pagemem.wal.record.RolloverType) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) OpenOption(java.nio.file.OpenOption) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) StandardOpenOption(java.nio.file.StandardOpenOption) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) File(java.io.File) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IteratorParametersBuilder(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 45 with WALPointer

use of org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer in project ignite by apache.

the class StandaloneWalRecordsIteratorTest method testStrictBounds.

/**
 * Check correct check bounds.
 *
 * @throws Exception if test failed.
 */
@Test
public void testStrictBounds() throws Exception {
    String dir = createWalFiles();
    WALPointer lowBound = null, highBound = null;
    for (IgniteBiTuple<WALPointer, WALRecord> p : createWalIterator(dir, null, null, false)) {
        if (lowBound == null)
            lowBound = p.get1();
        highBound = p.get1();
    }
    assertNotNull(lowBound);
    assertNotNull(highBound);
    createWalIterator(dir, lowBound, highBound, true);
    final WALPointer lBound = lowBound;
    final WALPointer hBound = highBound;
    // noinspection ThrowableNotThrown
    GridTestUtils.assertThrows(log, () -> {
        createWalIterator(dir, new WALPointer(lBound.index() - 1, 0, 0), hBound, true);
        return 0;
    }, IgniteCheckedException.class, null);
    // noinspection ThrowableNotThrown
    GridTestUtils.assertThrows(log, () -> {
        createWalIterator(dir, lBound, new WALPointer(hBound.index() + 1, 0, 0), true);
        return 0;
    }, IgniteCheckedException.class, null);
    List<FileDescriptor> walFiles = listWalFiles(dir);
    assertNotNull(walFiles);
    assertTrue(!walFiles.isEmpty());
    assertTrue(walFiles.get(new Random().nextInt(walFiles.size())).file().delete());
    // noinspection ThrowableNotThrown
    GridTestUtils.assertThrows(log, () -> {
        createWalIterator(dir, lBound, hBound, true);
        return 0;
    }, IgniteCheckedException.class, null);
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) Random(java.util.Random) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

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