use of org.apache.ignite.internal.processors.cache.persistence.DataRegion in project ignite by apache.
the class CheckpointWorkflow method markCheckpointEnd.
/**
* Do some actions on checkpoint finish(After all pages were written to disk).
*
* @param chp Checkpoint snapshot.
*/
public void markCheckpointEnd(Checkpoint chp) throws IgniteCheckedException {
synchronized (this) {
chp.progress.clearCounters();
for (DataRegion memPlc : dataRegions.get()) {
if (!memPlc.config().isPersistenceEnabled())
continue;
((PageMemoryEx) memPlc.pageMemory()).finishCheckpoint();
}
}
if (chp.hasDelta()) {
if (checkpointMarkersStorage != null)
checkpointMarkersStorage.writeCheckpointEntry(chp.cpEntry.timestamp(), chp.cpEntry.checkpointId(), chp.cpEntry.checkpointMark(), null, CheckpointEntryType.END, skipSync);
if (wal != null)
wal.notchLastCheckpointPtr(chp.cpEntry.checkpointMark());
}
if (checkpointMarkersStorage != null)
checkpointMarkersStorage.onCheckpointFinished(chp);
CheckpointContextImpl emptyCtx = new CheckpointContextImpl(chp.progress, null, null, null);
Collection<DataRegion> checkpointedRegions = dataRegions.get();
List<CheckpointListener> dbLsnrs = getRelevantCheckpointListeners(checkpointedRegions);
for (CheckpointListener lsnr : dbLsnrs) lsnr.afterCheckpointEnd(emptyCtx);
chp.progress.transitTo(FINISHED);
}
use of org.apache.ignite.internal.processors.cache.persistence.DataRegion in project ignite by apache.
the class CacheFreeListSelfTest method createFreeList.
/**
* @param pageSize Page size.
* @return Free list.
* @throws Exception If failed.
*/
private FreeList<CacheDataRow> createFreeList(int pageSize) throws Exception {
DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
pageMem = createPageMemory(pageSize, plcCfg);
long metaPageId = pageMem.allocatePage(1, 1, PageIdAllocator.FLAG_DATA);
IgniteConfiguration cfg = new IgniteConfiguration().setMetricExporterSpi(new NoopMetricExporterSpi());
GridTestKernalContext ctx = new GridTestKernalContext(new GridTestLog4jLogger(), cfg);
ctx.add(new GridMetricManager(ctx));
ctx.add(new PerformanceStatisticsProcessor(ctx));
DataRegionMetricsImpl regionMetrics = new DataRegionMetricsImpl(plcCfg, ctx);
DataRegion dataRegion = new DataRegion(pageMem, plcCfg, regionMetrics, new NoOpPageEvictionTracker());
PageLockTrackerManager pageLockTrackerManager = mock(PageLockTrackerManager.class);
when(pageLockTrackerManager.createPageLockTracker(anyString())).thenReturn(PageLockTrackerManager.NOOP_LSNR);
return new CacheFreeList(1, "freelist", dataRegion, null, metaPageId, true, pageLockTrackerManager, new GridTestKernalContext(log), null, PageIdAllocator.FLAG_IDX);
}
use of org.apache.ignite.internal.processors.cache.persistence.DataRegion in project ignite by apache.
the class PageMemoryTracker method start.
/**
* Start tracking pages.
*/
synchronized void start() {
if (!isEnabled() || started)
return;
pageSize = ctx.igniteConfiguration().getDataStorageConfiguration().getPageSize();
pageMemoryMock = mockPageMemory();
GridCacheSharedContext sharedCtx = gridCtx.cache().context();
// Initialize one memory region for all data regions of target ignite node.
long maxMemorySize = 0;
for (DataRegion dataRegion : sharedCtx.database().dataRegions()) {
if (dataRegion.pageMemory() instanceof PageMemoryImpl)
maxMemorySize += dataRegion.config().getMaxSize();
}
long[] chunks = new long[] { maxMemorySize };
memoryProvider = new UnsafeMemoryProvider(log);
memoryProvider.initialize(chunks);
memoryRegion = memoryProvider.nextRegion();
GridUnsafe.setMemory(memoryRegion.address(), memoryRegion.size(), (byte) 0);
maxPages = (int) (maxMemorySize / pageSize);
pageSlots = new DirectMemoryPageSlot[maxPages];
freeSlotsCnt = maxPages;
tmpBuf1 = ByteBuffer.allocateDirect(pageSize);
tmpBuf2 = ByteBuffer.allocateDirect(pageSize);
if (cfg.isCheckPagesOnCheckpoint()) {
checkpointLsnr = new CheckpointListener() {
@Override
public void onMarkCheckpointBegin(Context ctx) throws IgniteCheckedException {
if (!checkPages(false, true))
throw new IgniteCheckedException("Page memory is inconsistent after applying WAL delta records.");
}
@Override
public void beforeCheckpointBegin(Context ctx) {
/* No-op. */
}
@Override
public void onCheckpointBegin(Context ctx) {
/* No-op. */
}
};
((GridCacheDatabaseSharedManager) gridCtx.cache().context().database()).addCheckpointListener(checkpointLsnr);
}
lastPageIdx = 0;
started = true;
log.info("PageMemory tracker started, " + U.readableSize(maxMemorySize, false) + " offheap memory allocated.");
}
use of org.apache.ignite.internal.processors.cache.persistence.DataRegion in project ignite by apache.
the class MetricsClusterActivationTest method checkDataRegionMetrics.
/**
* Checks data region metrics.
*/
private void checkDataRegionMetrics(IgniteEx ignite) throws IgniteCheckedException {
DataRegion region = ignite.context().cache().context().database().dataRegion(DFLT_DATA_REG_DEFAULT_NAME);
MetricRegistry mreg = ignite.context().metric().registry(metricName(DATAREGION_METRICS_PREFIX, DFLT_DATA_REG_DEFAULT_NAME));
if (!ignite.cluster().state().active()) {
assertEquals(0, F.size(mreg.iterator()));
return;
}
long offHeapSize = mreg.<LongMetric>findMetric("OffHeapSize").value();
long initialSize = mreg.<LongMetric>findMetric("InitialSize").value();
long maxSize = mreg.<LongMetric>findMetric("MaxSize").value();
assertTrue(offHeapSize > 0);
assertTrue(offHeapSize <= region.config().getMaxSize());
assertEquals(region.config().getInitialSize(), initialSize);
assertEquals(region.config().getMaxSize(), maxSize);
}
use of org.apache.ignite.internal.processors.cache.persistence.DataRegion 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