Search in sources :

Example 61 with GridCacheDatabaseSharedManager

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

the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testPageWalEntries.

/**
 * @throws Exception if failed.
 */
@Test
public void testPageWalEntries() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.cluster().active(true);
    GridCacheSharedContext<Object, Object> sharedCtx = ig.context().cache().context();
    int cacheId = sharedCtx.cache().cache(CACHE_NAME).context().cacheId();
    GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) sharedCtx.database();
    PageMemory pageMem = sharedCtx.database().dataRegion(null).pageMemory();
    IgniteWriteAheadLogManager wal = sharedCtx.wal();
    db.enableCheckpoints(false).get();
    int pageCnt = 100;
    List<FullPageId> pageIds = new ArrayList<>();
    for (int i = 0; i < pageCnt; i++) {
        db.checkpointReadLock();
        try {
            pageIds.add(new FullPageId(pageMem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageIdAllocator.FLAG_IDX), cacheId));
        } finally {
            db.checkpointReadUnlock();
        }
    }
    UUID cpId = UUID.randomUUID();
    WALPointer start = wal.log(new CheckpointRecord(cpId, null));
    wal.flush(start, false);
    ig.context().cache().context().database().checkpointReadLock();
    try {
        for (FullPageId pageId : pageIds) writePageData(pageId, pageMem);
    } finally {
        ig.context().cache().context().database().checkpointReadUnlock();
    }
    // Data will not be written to the page store.
    stopAllGrids();
    ig = startGrid(0);
    ig.cluster().active(true);
    sharedCtx = ig.context().cache().context();
    db = (GridCacheDatabaseSharedManager) sharedCtx.database();
    wal = sharedCtx.wal();
    db.enableCheckpoints(false);
    try (PartitionMetaStateRecordExcludeIterator it = new PartitionMetaStateRecordExcludeIterator(wal.replay(start))) {
        IgniteBiTuple<WALPointer, WALRecord> tup = it.next();
        assert tup.get2() instanceof CheckpointRecord : tup.get2();
        assertEquals(start, tup.get1());
        CheckpointRecord cpRec = (CheckpointRecord) tup.get2();
        assertEquals(cpId, cpRec.checkpointId());
        assertNull(cpRec.checkpointMark());
        assertFalse(cpRec.end());
        int idx = 0;
        while (idx < pageIds.size()) {
            tup = it.next();
            assert tup.get2() instanceof PageSnapshot : tup.get2().getClass();
            PageSnapshot snap = (PageSnapshot) tup.get2();
            // there are extra tracking pages, skip them
            long trackingPageFor = TrackingPageIO.VERSIONS.latest().trackingPageFor(snap.fullPageId().pageId(), pageMem.pageSize());
            if (trackingPageFor == snap.fullPageId().pageId()) {
                tup = it.next();
                assertTrue(tup.get2() instanceof PageSnapshot);
                snap = (PageSnapshot) tup.get2();
            }
            assertEquals(pageIds.get(idx), snap.fullPageId());
            idx++;
        }
    }
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) ArrayList(java.util.ArrayList) CheckpointRecord(org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) UUID(java.util.UUID) 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 62 with GridCacheDatabaseSharedManager

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

the class IgniteNodeStoppedDuringDisableWALTest method testStopNodeWithDisableWAL.

/**
 * @param nodeStopPoint Stop point.
 * @throws Exception If failed.
 */
private void testStopNodeWithDisableWAL(NodeStopPoint nodeStopPoint) throws Exception {
    log.info("Start test crash " + nodeStopPoint);
    IgniteEx ig0 = startGrid(0);
    GridCacheSharedContext<Object, Object> sharedContext = ig0.context().cache().context();
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) sharedContext.database();
    IgniteWriteAheadLogManager WALmgr = sharedContext.wal();
    WALDisableContext walDisableContext = new WALDisableContext(dbMgr, sharedContext.pageStore(), log) {

        @Override
        protected void writeMetaStoreDisableWALFlag() throws IgniteCheckedException {
            if (nodeStopPoint == NodeStopPoint.BEFORE_WRITE_KEY_TO_META_STORE)
                failNode(nodeStopPoint);
            super.writeMetaStoreDisableWALFlag();
            if (nodeStopPoint == NodeStopPoint.AFTER_WRITE_KEY_TO_META_STORE)
                failNode(nodeStopPoint);
        }

        @Override
        protected void removeMetaStoreDisableWALFlag() throws IgniteCheckedException {
            if (nodeStopPoint == NodeStopPoint.AFTER_CHECKPOINT_AFTER_ENABLE_WAL)
                failNode(nodeStopPoint);
            super.removeMetaStoreDisableWALFlag();
            if (nodeStopPoint == NodeStopPoint.AFTER_REMOVE_KEY_TO_META_STORE)
                failNode(nodeStopPoint);
        }

        @Override
        protected void disableWAL(boolean disable) throws IgniteCheckedException {
            if (disable) {
                if (nodeStopPoint == NodeStopPoint.AFTER_CHECKPOINT_BEFORE_DISABLE_WAL)
                    failNode(nodeStopPoint);
                super.disableWAL(disable);
                if (nodeStopPoint == NodeStopPoint.AFTER_DISABLE_WAL)
                    failNode(nodeStopPoint);
            } else {
                super.disableWAL(disable);
                if (nodeStopPoint == NodeStopPoint.AFTER_ENABLE_WAL)
                    failNode(nodeStopPoint);
            }
        }
    };
    setFieldValue(sharedContext.walState(), "walDisableContext", walDisableContext);
    setFieldValue(WALmgr, "walDisableContext", walDisableContext);
    ig0.context().internalSubscriptionProcessor().registerMetastorageListener(walDisableContext);
    ig0.cluster().active(true);
    try (IgniteDataStreamer<Integer, Integer> st = ig0.dataStreamer(DEFAULT_CACHE_NAME)) {
        st.allowOverwrite(true);
        for (int i = 0; i < GridTestUtils.SF.apply(10_000); i++) st.addData(i, -i);
    }
    boolean fail = false;
    try (WALIterator it = sharedContext.wal().replay(null)) {
        dbMgr.applyUpdatesOnRecovery(it, (ptr, rec) -> true, (entry) -> true);
    } catch (IgniteCheckedException e) {
        if (nodeStopPoint.needCleanUp)
            fail = true;
    }
    Assert.assertEquals(nodeStopPoint.needCleanUp, fail);
    Ignite ig1 = startGrid(0);
    String msg = nodeStopPoint.toString();
    int pageSize = ig1.configuration().getDataStorageConfiguration().getPageSize();
    if (nodeStopPoint.needCleanUp) {
        PdsFoldersResolver foldersResolver = ((IgniteEx) ig1).context().pdsFolderResolver();
        File root = foldersResolver.resolveFolders().persistentStoreRootPath();
        walkFileTree(root.toPath(), new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
                String name = path.toFile().getName();
                String filePath = path.toString();
                String parentDirName = path.toFile().getParentFile().getName();
                if (parentDirName.equals(METASTORAGE_DIR_NAME) || parentDirName.equals(TxLog.TX_LOG_CACHE_NAME))
                    return CONTINUE;
                if (WAL_NAME_PATTERN.matcher(name).matches() || WAL_TEMP_NAME_PATTERN.matcher(name).matches())
                    return CONTINUE;
                boolean failed = false;
                if (name.endsWith(FilePageStoreManager.TMP_SUFFIX))
                    failed = true;
                if (CP_FILE_NAME_PATTERN.matcher(name).matches())
                    failed = true;
                if (name.startsWith(PART_FILE_PREFIX) && path.toFile().length() > pageSize)
                    failed = true;
                if (name.startsWith(INDEX_FILE_NAME) && path.toFile().length() > pageSize)
                    failed = true;
                if (failed)
                    fail(msg + " " + filePath + " " + path.toFile().length());
                return CONTINUE;
            }
        });
    }
}
Also used : Path(java.nio.file.Path) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) WALDisableContext(org.apache.ignite.internal.processors.cache.WalStateManager.WALDisableContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) IgniteEx(org.apache.ignite.internal.IgniteEx) PdsFoldersResolver(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFoldersResolver) Ignite(org.apache.ignite.Ignite) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 63 with GridCacheDatabaseSharedManager

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

the class IgniteSequentialNodeCrashRecoveryTest method triggerCheckpoint.

/**
 * @param ig Ignite instance.
 */
private void triggerCheckpoint(IgniteEx ig) {
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) ig.context().cache().context().database();
    dbMgr.wakeupForCheckpoint("test-should-fail");
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)

Example 64 with GridCacheDatabaseSharedManager

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

the class IgniteSequentialNodeCrashRecoveryTest method captureDirtyPages.

/**
 * @param g Ignite instance.
 * @throws IgniteCheckedException If failed.
 */
private Collection<FullPageId> captureDirtyPages(IgniteEx g) throws IgniteCheckedException {
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) g.context().cache().context().database();
    dbMgr.checkpointReadLock();
    try {
        // Moving free list pages to offheap.
        for (CacheGroupContext group : g.context().cache().cacheGroups()) {
            ((GridCacheOffheapManager) group.offheap()).onMarkCheckpointBegin(new DummyCheckpointContext());
        }
    } finally {
        dbMgr.checkpointReadUnlock();
    }
    // Capture a set of dirty pages.
    PageMemoryImpl pageMem = (PageMemoryImpl) dbMgr.dataRegion("default").pageMemory();
    return pageMem.dirtyPages();
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 65 with GridCacheDatabaseSharedManager

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

the class TxPartitionCounterStateAbstractTest method stopGrid.

/**
 * @param skipCheckpointOnStop Skip checkpoint on stop.
 * @param name Grid instance.
 */
protected void stopGrid(boolean skipCheckpointOnStop, String name) {
    IgniteEx grid = grid(name);
    if (skipCheckpointOnStop && persistenceEnabled()) {
        GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) grid.context().cache().context().database();
        db.enableCheckpoints(false);
    }
    stopGrid(grid.name(), skipCheckpointOnStop);
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteEx(org.apache.ignite.internal.IgniteEx)

Aggregations

GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)85 IgniteEx (org.apache.ignite.internal.IgniteEx)54 Test (org.junit.Test)48 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)33 Ignite (org.apache.ignite.Ignite)20 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)17 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)15 ArrayList (java.util.ArrayList)13 File (java.io.File)12 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)12 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)12 List (java.util.List)10 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)10 WALPointer (org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 IgniteCache (org.apache.ignite.IgniteCache)9 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)9 CheckpointListener (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener)9