Search in sources :

Example 1 with LightweightCheckpointManager

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

the class GridCacheDatabaseSharedManager method prepareCacheDefragmentation.

/**
 */
private void prepareCacheDefragmentation(List<String> cacheNames) throws IgniteCheckedException {
    GridKernalContext kernalCtx = cctx.kernalContext();
    DataStorageConfiguration dsCfg = kernalCtx.config().getDataStorageConfiguration();
    assert CU.isPersistenceEnabled(dsCfg);
    List<DataRegion> regions = Arrays.asList(dataRegion(DEFRAGMENTATION_MAPPING_REGION_NAME), dataRegion(DEFRAGMENTATION_PART_REGION_NAME));
    LightweightCheckpointManager lightCheckpointMgr = new LightweightCheckpointManager(kernalCtx::log, cctx.igniteInstanceName(), "db-checkpoint-thread-defrag", kernalCtx.workersRegistry(), persistenceCfg, () -> regions, this::getPageMemoryForCacheGroup, resolveThrottlingPolicy(), snapshotMgr, persistentStoreMetricsImpl(), kernalCtx.longJvmPauseDetector(), kernalCtx.failure(), kernalCtx.cache());
    lightCheckpointMgr.start();
    defrgMgr = new CachePartitionDefragmentationManager(cacheNames, cctx, this, (FilePageStoreManager) cctx.pageStore(), checkpointManager, lightCheckpointMgr, persistenceCfg.getPageSize(), persistenceCfg.getDefragmentationThreadPoolSize());
}
Also used : DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) LightweightCheckpointManager(org.apache.ignite.internal.processors.cache.persistence.checkpoint.LightweightCheckpointManager) GridKernalContext(org.apache.ignite.internal.GridKernalContext) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) CachePartitionDefragmentationManager(org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager)

Example 2 with LightweightCheckpointManager

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

the class LightweightCheckpointTest method testLightCheckpointAbleToStoreOnlyGivenDataRegion.

/**
 * 1. Start the one node with disabled WAL and with two caches.
 * 2. Disable default checkpoint.
 * 3. Create light checkpoint for one cache and configure checkpoint listener for it.
 * 4. Fill the both caches.
 * 5. Trigger the light checkpoint and wait for the finish.
 * 6. Stop the node and start it again.
 * 7. Expected: Cache which was checkpointed would have the all data meanwhile second cache would be empty.
 *
 * @throws Exception if fail.
 */
@Test
public void testLightCheckpointAbleToStoreOnlyGivenDataRegion() throws Exception {
    // given: One started node with default cache and cache which won't be checkpointed.
    IgniteEx ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    IgniteCache<Integer, Object> checkpointedCache = ignite0.cache(DEFAULT_CACHE_NAME);
    IgniteCache<Integer, Object> notCheckpointedCache = ignite0.cache(NOT_CHECKPOINTED_CACHE);
    GridKernalContext context = ignite0.context();
    GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) (context.cache().context().database());
    waitForCondition(() -> !db.getCheckpointer().currentProgress().inProgress(), 10_000);
    // and: disable the default checkpoint.
    db.enableCheckpoints(false);
    DataRegion regionForCheckpoint = db.dataRegion(DFLT_DATA_REG_DEFAULT_NAME);
    // and: Create light checkpoint with only one region.
    LightweightCheckpointManager lightweightCheckpointManager = new LightweightCheckpointManager(context::log, context.igniteInstanceName(), "light-test-checkpoint", context.workersRegistry(), context.config().getDataStorageConfiguration(), () -> Arrays.asList(regionForCheckpoint), grpId -> getPageMemoryForCacheGroup(grpId, db, context), PageMemoryImpl.ThrottlingPolicy.CHECKPOINT_BUFFER_ONLY, context.cache().context().snapshot(), db.persistentStoreMetricsImpl(), context.longJvmPauseDetector(), context.failure(), context.cache());
    // and: Add checkpoint listener for DEFAULT_CACHE in order of storing the meta pages.
    lightweightCheckpointManager.addCheckpointListener((CheckpointListener) context.cache().cacheGroup(groupIdForCache(ignite0, DEFAULT_CACHE_NAME)).offheap(), regionForCheckpoint);
    lightweightCheckpointManager.start();
    // when: Fill the caches
    for (int j = 0; j < 1024; j++) {
        checkpointedCache.put(j, j);
        notCheckpointedCache.put(j, j);
    }
    // and: Trigger and wait for the checkpoint.
    lightweightCheckpointManager.forceCheckpoint("test", null).futureFor(CheckpointState.FINISHED).get();
    // and: Stop and start node.
    stopAllGrids();
    ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    checkpointedCache = ignite0.cache(DEFAULT_CACHE_NAME);
    notCheckpointedCache = ignite0.cache(NOT_CHECKPOINTED_CACHE);
    // then: Checkpointed cache should have all data meanwhile uncheckpointed cache should be empty.
    for (int j = 1; j < 1024; j++) {
        assertEquals(j, checkpointedCache.get(j));
        assertNull(notCheckpointedCache.get(j));
    }
    GridCacheDatabaseSharedManager db2 = (GridCacheDatabaseSharedManager) (ignite0.context().cache().context().database());
    waitForCondition(() -> !db2.getCheckpointer().currentProgress().inProgress(), 10_000);
    String nodeFolderName = ignite0.context().pdsFolderResolver().resolveFolders().folderName();
    File cpMarkersDir = Paths.get(U.defaultWorkDirectory(), "db", nodeFolderName, "cp").toFile();
    // then: Expected only two pairs checkpoint markers - both from the start of node.
    assertEquals(4, cpMarkersDir.listFiles().length);
}
Also used : LightweightCheckpointManager(org.apache.ignite.internal.processors.cache.persistence.checkpoint.LightweightCheckpointManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteEx(org.apache.ignite.internal.IgniteEx) File(java.io.File) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridKernalContext (org.apache.ignite.internal.GridKernalContext)2 LightweightCheckpointManager (org.apache.ignite.internal.processors.cache.persistence.checkpoint.LightweightCheckpointManager)2 File (java.io.File)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 DataRegion (org.apache.ignite.internal.processors.cache.persistence.DataRegion)1 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)1 CachePartitionDefragmentationManager (org.apache.ignite.internal.processors.cache.persistence.defragmentation.CachePartitionDefragmentationManager)1 FilePageStoreManager (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1