Search in sources :

Example 21 with DataRegion

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);
}
Also used : PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion)

Example 22 with DataRegion

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);
}
Also used : GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) CacheFreeList(org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeList) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) PageLockTrackerManager(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTrackerManager) PerformanceStatisticsProcessor(org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) NoOpPageEvictionTracker(org.apache.ignite.internal.processors.cache.persistence.evict.NoOpPageEvictionTracker) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) NoopMetricExporterSpi(org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion)

Example 23 with DataRegion

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.");
}
Also used : CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridKernalContext(org.apache.ignite.internal.GridKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) PluginContext(org.apache.ignite.plugin.PluginContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion)

Example 24 with DataRegion

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);
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion)

Example 25 with DataRegion

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

DataRegion (org.apache.ignite.internal.processors.cache.persistence.DataRegion)29 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)6 PageMetrics (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Test (org.junit.Test)6 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)5 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)5 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)5 File (java.io.File)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)4 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 IgniteCache (org.apache.ignite.IgniteCache)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 Collection (java.util.Collection)2 List (java.util.List)2