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());
}
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);
}
Aggregations