Search in sources :

Example 11 with FileWriteAheadLogManager

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

the class IgniteWalHistoryReservationsTest method isReserveListEmpty.

/**
 * @return {@code true} if reserve list is empty.
 */
private boolean isReserveListEmpty(IgniteEx ig) {
    FileWriteAheadLogManager wal = (FileWriteAheadLogManager) ig.context().cache().context().wal();
    Object segmentAware = GridTestUtils.getFieldValue(wal, "segmentAware");
    synchronized (segmentAware) {
        Map reserved = GridTestUtils.getFieldValue(GridTestUtils.getFieldValue(segmentAware, "reservationStorage"), "reserved");
        if (reserved.isEmpty())
            return true;
    }
    return false;
}
Also used : FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) Map(java.util.Map)

Example 12 with FileWriteAheadLogManager

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

the class IgniteWalFlushFailoverTest method flushingErrorTest.

/**
 * @throws Exception if failed.
 */
private void flushingErrorTest() throws Exception {
    final IgniteEx grid = startGrid(0);
    FileWriteAheadLogManager wal = (FileWriteAheadLogManager) grid.context().cache().context().wal();
    boolean mmap = GridTestUtils.getFieldValue(wal, "mmap");
    if (mmap)
        return;
    wal.setFileIOFactory(new FailingFileIOFactory(canFail));
    try {
        grid.active(true);
        IgniteCache<Object, Object> cache = grid.cache(TEST_CACHE);
        final int iterations = 100;
        canFail.set(true);
        for (int i = 0; i < iterations; i++) {
            Transaction tx = grid.transactions().txStart(TransactionConcurrency.PESSIMISTIC, TransactionIsolation.READ_COMMITTED);
            cache.put(i, "testValue" + i);
            Thread.sleep(100L);
            tx.commitAsync().get();
        }
    } catch (Exception expected) {
    // There can be any exception. Do nothing.
    }
    // We should await successful stop of node.
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return grid.context().gateway().getState() == GridKernalState.STOPPED;
        }
    }, getTestTimeout());
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) IOException(java.io.IOException)

Example 13 with FileWriteAheadLogManager

use of org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager 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 14 with FileWriteAheadLogManager

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

the class IgnitePdsRecoveryAfterFileCorruptionTest method testPageRecoveryAfterFileCorruption.

/**
 * @throws Exception if failed.
 */
@Test
public void testPageRecoveryAfterFileCorruption() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().state(ClusterState.ACTIVE);
    IgniteCache<Integer, Integer> cache = ig.cache(cacheName);
    // Put for create data store and init meta page.
    cache.put(1, 1);
    GridCacheSharedContext sharedCtx = ig.context().cache().context();
    GridCacheDatabaseSharedManager psMgr = (GridCacheDatabaseSharedManager) sharedCtx.database();
    FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore();
    U.sleep(1_000);
    // Disable integrated checkpoint thread.
    psMgr.enableCheckpoints(false).get();
    PageMemory mem = sharedCtx.database().dataRegion(policyName).pageMemory();
    DummyPageIO pageIO = new DummyPageIO();
    int cacheId = sharedCtx.cache().cache(cacheName).context().cacheId();
    int pagesCnt = getTotalPagesToTest();
    FullPageId[] pages = new FullPageId[pagesCnt];
    // Get lock to prevent assertion. A new page should be allocated under checkpoint lock.
    psMgr.checkpointReadLock();
    try {
        for (int i = 0; i < pagesCnt; i++) {
            pages[i] = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId);
            initPage(mem, pageIO, pages[i]);
        }
        generateWal((PageMemoryImpl) mem, sharedCtx.pageStore(), sharedCtx.wal(), cacheId, pages);
    } finally {
        psMgr.checkpointReadUnlock();
    }
    eraseDataFromDisk(pageStore, cacheId, pages[0]);
    stopAllGrids();
    ig = startGrid(0);
    ig.cluster().state(ClusterState.ACTIVE);
    checkRestore(ig, pages);
    // It is necessary to clear the current WAL history to make sure that the restored pages have been saved.
    GridCacheSharedContext<Object, Object> cctx = ig.context().cache().context();
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) cctx.database();
    FileWriteAheadLogManager wal = (FileWriteAheadLogManager) cctx.wal();
    // Force checkpoint.
    dbMgr.enableCheckpoints(true).get(getTestTimeout());
    dbMgr.checkpointReadLock();
    try {
        WALPointer lastWalPtr = dbMgr.checkpointHistory().lastCheckpoint().checkpointMark();
        // Move current WAL segment into the archive.
        wal.log(new CheckpointRecord(null), RolloverType.NEXT_SEGMENT);
        assertTrue(waitForCondition(() -> wal.lastArchivedSegment() >= lastWalPtr.index(), getTestTimeout()));
        wal.truncate(lastWalPtr);
        dbMgr.onWalTruncated(lastWalPtr);
    } finally {
        dbMgr.checkpointReadUnlock();
    }
    stopAllGrids();
    ig = startGrid(0);
    ig.cluster().state(ClusterState.ACTIVE);
    checkRestore(ig, pages);
}
Also used : PageMemory(org.apache.ignite.internal.pagemem.PageMemory) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 15 with FileWriteAheadLogManager

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

the class IgniteDataStorageMetricsSelfTest method checkWalArchiveAndTotalSize.

/**
 * Check the state of wal archive, and whether the total size of
 * wal (and possibly wal archive) match what is expected.
 *
 * @param igniteEx Node.
 * @param hasWalArchive Whether wal archiving is enabled.
 * @throws Exception If failed.
 */
private void checkWalArchiveAndTotalSize(IgniteEx igniteEx, boolean hasWalArchive) throws Exception {
    FileWriteAheadLogManager walMgr = walMgr(igniteEx);
    SegmentRouter router = walMgr.getSegmentRouter();
    assertEquals(router.hasArchive(), hasWalArchive);
    // Wait to avoid race condition where new segments(and corresponding .tmp files) are created after totalSize has been calculated.
    if (router.hasArchive()) {
        int expWalWorkSegements = igniteEx.configuration().getDataStorageConfiguration().getWalSegments();
        assertTrue(waitForCondition(() -> walFiles(router.getWalWorkDir()).length == expWalWorkSegements, 3000l));
        assertTrue(waitForCondition(() -> walMgr.lastArchivedSegment() == walMgr.currentSegment() - 1, 3000l));
    }
    long totalSize = walMgr.totalSize(walFiles(router.getWalWorkDir()));
    if (router.hasArchive())
        totalSize += walMgr.totalSize(walFiles(router.getWalArchiveDir()));
    assertEquals(totalSize, dbMgr(igniteEx).persistentStoreMetrics().getWalTotalSize());
    assertEquals(totalSize, dsMetricsMXBean(igniteEx).getWalTotalSize());
    assertEquals(totalSize, ((LongGauge) dsMetricRegistry(igniteEx).findMetric("WalTotalSize")).value());
}
Also used : SegmentRouter(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentRouter) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager)

Aggregations

FileWriteAheadLogManager (org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager)23 IgniteEx (org.apache.ignite.internal.IgniteEx)12 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)8 Test (org.junit.Test)8 File (java.io.File)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 IOException (java.io.IOException)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)4 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)4 Arrays (java.util.Arrays)3 Ignite (org.apache.ignite.Ignite)3 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)3 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)3 Collection (java.util.Collection)2 Map (java.util.Map)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2