Search in sources :

Example 16 with FileWriteAheadLogManager

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

the class MockWalIteratorFactory method iterator.

/**
 * Creates iterator
 * @param wal WAL directory without node consistent id
 * @param walArchive WAL archive without node consistent id
 * @return iterator
 * @throws IgniteCheckedException if IO failed
 */
@SuppressWarnings("unchecked")
public WALIterator iterator(File wal, File walArchive) throws IgniteCheckedException {
    final DataStorageConfiguration persistentCfg1 = Mockito.mock(DataStorageConfiguration.class);
    when(persistentCfg1.getWalPath()).thenReturn(wal.getAbsolutePath());
    when(persistentCfg1.getWalArchivePath()).thenReturn(walArchive.getAbsolutePath());
    when(persistentCfg1.getWalSegments()).thenReturn(segments);
    when(persistentCfg1.getWalBufferSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_BUFF_SIZE);
    when(persistentCfg1.getWalRecordIteratorBufferSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_RECORD_ITERATOR_BUFFER_SIZE);
    when(persistentCfg1.getWalSegmentSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_SEGMENT_SIZE);
    final FileIOFactory fileIOFactory = new DataStorageConfiguration().getFileIOFactory();
    when(persistentCfg1.getFileIOFactory()).thenReturn(fileIOFactory);
    final IgniteConfiguration cfg = Mockito.mock(IgniteConfiguration.class);
    when(cfg.getDataStorageConfiguration()).thenReturn(persistentCfg1);
    final GridKernalContext ctx = Mockito.mock(GridKernalContext.class);
    when(ctx.config()).thenReturn(cfg);
    when(ctx.clientNode()).thenReturn(false);
    when(ctx.pdsFolderResolver()).thenReturn(new PdsFoldersResolver() {

        @Override
        public PdsFolderSettings resolveFolders() {
            return new PdsFolderSettings(new File("."), subfolderName, consistentId, null, false);
        }
    });
    final GridDiscoveryManager disco = Mockito.mock(GridDiscoveryManager.class);
    when(ctx.discovery()).thenReturn(disco);
    final IgniteWriteAheadLogManager mgr = new FileWriteAheadLogManager(ctx);
    final GridCacheSharedContext sctx = Mockito.mock(GridCacheSharedContext.class);
    when(sctx.kernalContext()).thenReturn(ctx);
    when(sctx.discovery()).thenReturn(disco);
    when(sctx.gridConfig()).thenReturn(cfg);
    final GridCacheDatabaseSharedManager db = Mockito.mock(GridCacheDatabaseSharedManager.class);
    when(db.pageSize()).thenReturn(pageSize);
    when(sctx.database()).thenReturn(db);
    when(sctx.logger(any(Class.class))).thenReturn(log);
    mgr.start(sctx);
    return mgr.replay(null);
}
Also used : FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) GridDiscoveryManager(org.apache.ignite.internal.managers.discovery.GridDiscoveryManager) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) PdsFoldersResolver(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFoldersResolver) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings) File(java.io.File)

Example 17 with FileWriteAheadLogManager

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

the class WalDeletionArchiveAbstractTest method testCheckpointHistoryRemovingByTruncate.

/**
 * Test for check deprecated removing checkpoint by deprecated walHistorySize parameter
 *
 * @deprecated Test old removing process depends on WalHistorySize.
 */
@Test
public void testCheckpointHistoryRemovingByTruncate() throws Exception {
    Ignite ignite = startGrid(dbCfg -> dbCfg.setMaxWalArchiveSize(2 * 1024 * 1024));
    GridCacheDatabaseSharedManager dbMgr = gridDatabase(ignite);
    IgniteCache<Integer, Object> cache = ignite.getOrCreateCache(cacheConfiguration());
    CheckpointHistory hist = dbMgr.checkpointHistory();
    assertNotNull(hist);
    int startHistSize = hist.checkpoints().size();
    int checkpointCnt = 10;
    for (int i = 0; i < checkpointCnt; i++) {
        cache.put(i, i);
        // and: wait for checkpoint finished
        forceCheckpoint();
        // Check that the history is growing.
        assertEquals(startHistSize + (i + 1), hist.checkpoints().size());
    }
    // Ensure rollover and wal archive cleaning.
    for (int i = 0; i < 6; i++) cache.put(i, new byte[ignite.configuration().getDataStorageConfiguration().getWalSegmentSize() / 2]);
    FileWriteAheadLogManager wal = wal(ignite);
    assertTrue(waitForCondition(() -> wal.lastTruncatedSegment() >= 0, 10_000));
    assertTrue(hist.checkpoints().size() < checkpointCnt + startHistSize);
    File[] cpFiles = dbMgr.checkpointDirectory().listFiles();
    // starts & ends + node_start
    assertTrue(cpFiles.length <= (checkpointCnt * 2 + 1));
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) CheckpointHistory(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointHistory) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) Ignite(org.apache.ignite.Ignite) File(java.io.File) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 18 with FileWriteAheadLogManager

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

the class GridCacheProcessor method createSharedContext.

/**
 * Creates shared context.
 *
 * @param kernalCtx Kernal context.
 * @param storeSesLsnrs Store session listeners.
 * @return Shared context.
 * @throws IgniteCheckedException If failed.
 */
@SuppressWarnings("unchecked")
private GridCacheSharedContext createSharedContext(GridKernalContext kernalCtx, Collection<CacheStoreSessionListener> storeSesLsnrs) throws IgniteCheckedException {
    IgniteTxManager tm = new IgniteTxManager();
    GridCacheMvccManager mvccMgr = new GridCacheMvccManager();
    GridCacheVersionManager verMgr = new GridCacheVersionManager();
    GridCacheDeploymentManager depMgr = new GridCacheDeploymentManager();
    GridCachePartitionExchangeManager exchMgr = new GridCachePartitionExchangeManager();
    IgniteCacheDatabaseSharedManager dbMgr;
    IgnitePageStoreManager pageStoreMgr = null;
    IgniteWriteAheadLogManager walMgr = null;
    if (CU.isPersistenceEnabled(ctx.config()) && !ctx.clientNode()) {
        dbMgr = new GridCacheDatabaseSharedManager(ctx);
        pageStoreMgr = ctx.plugins().createComponent(IgnitePageStoreManager.class);
        if (pageStoreMgr == null)
            pageStoreMgr = new FilePageStoreManager(ctx);
        walMgr = ctx.plugins().createComponent(IgniteWriteAheadLogManager.class);
        if (walMgr == null)
            walMgr = new FileWriteAheadLogManager(ctx);
    } else {
        if (CU.isPersistenceEnabled(ctx.config()) && ctx.clientNode()) {
            U.warn(log, "Persistent Store is not supported on client nodes (Persistent Store's" + " configuration will be ignored).");
        }
        dbMgr = new IgniteCacheDatabaseSharedManager();
    }
    WalStateManager walStateMgr = new WalStateManager(ctx);
    IgniteSnapshotManager snapshotMgr = new IgniteSnapshotManager(ctx);
    IgniteCacheSnapshotManager snpMgr = ctx.plugins().createComponent(IgniteCacheSnapshotManager.class);
    if (snpMgr == null)
        snpMgr = new IgniteCacheSnapshotManager();
    GridCacheIoManager ioMgr = new GridCacheIoManager();
    CacheAffinitySharedManager topMgr = new CacheAffinitySharedManager();
    GridCacheSharedTtlCleanupManager ttl = new GridCacheSharedTtlCleanupManager();
    PartitionsEvictManager evict = new PartitionsEvictManager();
    CacheJtaManagerAdapter jta = JTA.createOptional();
    MvccCachingManager mvccCachingMgr = new MvccCachingManager();
    DeadlockDetectionManager deadlockDetectionMgr = new DeadlockDetectionManager();
    CacheDiagnosticManager diagnosticMgr = new CacheDiagnosticManager();
    return new GridCacheSharedContext(kernalCtx, tm, verMgr, mvccMgr, pageStoreMgr, walMgr, walStateMgr, dbMgr, snapshotMgr, snpMgr, depMgr, exchMgr, topMgr, ioMgr, ttl, evict, jta, storeSesLsnrs, mvccCachingMgr, deadlockDetectionMgr, diagnosticMgr);
}
Also used : CacheJtaManagerAdapter(org.apache.ignite.internal.processors.cache.jta.CacheJtaManagerAdapter) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) IgniteCacheSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteCacheSnapshotManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) MvccCachingManager(org.apache.ignite.internal.processors.cache.mvcc.MvccCachingManager) IgniteTxManager(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) DeadlockDetectionManager(org.apache.ignite.internal.processors.cache.mvcc.DeadlockDetectionManager) GridCacheVersionManager(org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager) PartitionsEvictManager(org.apache.ignite.internal.processors.cache.distributed.dht.topology.PartitionsEvictManager) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) IgniteSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 19 with FileWriteAheadLogManager

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

the class CdcCacheVersionTest method testOrderIncrease.

/**
 */
@Test
public void testOrderIncrease() throws Exception {
    walProvider = (ctx) -> new FileWriteAheadLogManager(ctx) {

        /**
         */
        private long prevOrder = -1;

        @Override
        public WALPointer log(WALRecord rec) throws IgniteCheckedException {
            if (rec.type() != DATA_RECORD_V2)
                return super.log(rec);
            DataRecord dataRec = (DataRecord) rec;
            for (int i = 0; i < dataRec.entryCount(); i++) {
                assertEquals(CU.cacheId(DEFAULT_CACHE_NAME), dataRec.get(i).cacheId());
                assertEquals(KEY_TO_UPD, (int) dataRec.get(i).key().value(null, false));
                assertTrue(dataRec.get(i).writeVersion().order() > prevOrder);
                prevOrder = dataRec.get(i).writeVersion().order();
                walRecCheckedCntr.incrementAndGet();
            }
            return super.log(rec);
        }
    };
    IgniteConfiguration cfg = getConfiguration("ignite-0");
    IgniteEx ign = startGrid(cfg);
    ign.cluster().state(ACTIVE);
    IgniteCache<Integer, User> cache = ign.getOrCreateCache(new CacheConfiguration<Integer, User>(DEFAULT_CACHE_NAME).setAtomicityMode(atomicityMode).setCacheMode(cacheMode));
    walRecCheckedCntr.set(0);
    // Expect {@link CacheEntryVersion#order()} will monotically increase.
    for (int i = 0; i < KEYS_CNT; i++) cache.put(KEY_TO_UPD, createUser(i));
    assertTrue(waitForCondition(() -> walRecCheckedCntr.get() == KEYS_CNT, getTestTimeout()));
}
Also used : WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) Test(org.junit.Test)

Example 20 with FileWriteAheadLogManager

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

the class DiagnosticProcessorTest method expWalDirs.

/**
 * Getting expected WAL directories.
 *
 * @param n Node.
 * @return WAL directories.
 */
@Nullable
private File[] expWalDirs(IgniteEx n) {
    FileWriteAheadLogManager walMgr = walMgr(n);
    if (walMgr != null) {
        SegmentRouter sr = walMgr.getSegmentRouter();
        assertNotNull(sr);
        File workDir = sr.getWalWorkDir();
        return sr.hasArchive() ? F.asArray(workDir, sr.getWalArchiveDir()) : F.asArray(workDir);
    }
    return null;
}
Also used : SegmentRouter(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentRouter) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) DiagnosticProcessor.corruptedPagesFile(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.corruptedPagesFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

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