Search in sources :

Example 1 with GridInClosure3X

use of org.apache.ignite.internal.util.lang.GridInClosure3X in project ignite by apache.

the class GridCacheDatabaseSharedManager method createPageMemory.

/**
 * {@inheritDoc}
 */
@Override
protected PageMemory createPageMemory(DirectMemoryProvider memProvider, DataStorageConfiguration memCfg, DataRegionConfiguration plcCfg, DataRegionMetricsImpl memMetrics, final boolean trackable, PageReadWriteManager pmPageMgr) {
    if (!plcCfg.isPersistenceEnabled())
        return super.createPageMemory(memProvider, memCfg, plcCfg, memMetrics, trackable, pmPageMgr);
    memMetrics.persistenceEnabled(true);
    long cacheSize = plcCfg.getMaxSize();
    // Checkpoint buffer size can not be greater than cache size, it does not make sense.
    long chpBufSize = checkpointBufferSize(plcCfg);
    if (chpBufSize > cacheSize) {
        U.quietAndInfo(log, "Configured checkpoint page buffer size is too big, setting to the max region size [size=" + U.readableSize(cacheSize, false) + ",  memPlc=" + plcCfg.getName() + ']');
        chpBufSize = cacheSize;
    }
    GridInClosure3X<Long, FullPageId, PageMemoryEx> changeTracker;
    if (trackable)
        changeTracker = new GridInClosure3X<Long, FullPageId, PageMemoryEx>() {

            @Override
            public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) throws IgniteCheckedException {
                if (trackable)
                    snapshotMgr.onChangeTrackerPage(page, fullId, pageMem);
            }
        };
    else
        changeTracker = null;
    PageMemoryImpl pageMem = new PageMemoryImpl(wrapMetricsPersistentMemoryProvider(memProvider, memMetrics), calculateFragmentSizes(memCfg.getConcurrencyLevel(), cacheSize, chpBufSize), cctx, pmPageMgr, memCfg.getPageSize(), (fullId, pageBuf, tag) -> {
        memMetrics.onPageWritten();
        // We can write only page from disk into snapshot.
        snapshotMgr.beforePageWrite(fullId);
        // Write page to disk.
        pmPageMgr.write(fullId.groupId(), fullId.pageId(), pageBuf, tag, true);
        getCheckpointer().currentProgress().updateEvictedPages(1);
    }, changeTracker, this, memMetrics, resolveThrottlingPolicy(), () -> getCheckpointer().currentProgress());
    memMetrics.pageMemory(pageMem);
    return pageMem;
}
Also used : GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) AtomicLong(java.util.concurrent.atomic.AtomicLong) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 2 with GridInClosure3X

use of org.apache.ignite.internal.util.lang.GridInClosure3X in project ignite by apache.

the class PageMemoryImplTest method createPageMemory.

/**
 * @param throttlingPlc Throttling Policy.
 * @throws Exception If creating mock failed.
 */
private PageMemoryImpl createPageMemory(int maxSize, PageMemoryImpl.ThrottlingPolicy throttlingPlc, IgnitePageStoreManager mgr, PageStoreWriter replaceWriter, @Nullable IgniteInClosure<FullPageId> cpBufChecker) throws Exception {
    long[] sizes = new long[5];
    for (int i = 0; i < sizes.length; i++) sizes[i] = maxSize * MB / 4;
    sizes[4] = maxSize * MB / 4;
    DirectMemoryProvider provider = new UnsafeMemoryProvider(log);
    IgniteConfiguration igniteCfg = new IgniteConfiguration();
    igniteCfg.setDataStorageConfiguration(new DataStorageConfiguration());
    igniteCfg.setFailureHandler(new NoOpFailureHandler());
    igniteCfg.setEncryptionSpi(new NoopEncryptionSpi());
    igniteCfg.setMetricExporterSpi(new NoopMetricExporterSpi());
    igniteCfg.setSystemViewExporterSpi(new JmxSystemViewExporterSpi());
    igniteCfg.setEventStorageSpi(new NoopEventStorageSpi());
    GridTestKernalContext kernalCtx = new GridTestKernalContext(new GridTestLog4jLogger(), igniteCfg);
    kernalCtx.add(new IgnitePluginProcessor(kernalCtx, igniteCfg, Collections.<PluginProvider>emptyList()));
    kernalCtx.add(new GridInternalSubscriptionProcessor(kernalCtx));
    kernalCtx.add(new PerformanceStatisticsProcessor(kernalCtx));
    kernalCtx.add(new GridEncryptionManager(kernalCtx));
    kernalCtx.add(new GridMetricManager(kernalCtx));
    kernalCtx.add(new GridSystemViewManager(kernalCtx));
    kernalCtx.add(new GridEventStorageManager(kernalCtx));
    FailureProcessor failureProc = new FailureProcessor(kernalCtx);
    failureProc.start();
    kernalCtx.add(failureProc);
    GridCacheSharedContext<Object, Object> sharedCtx = new GridCacheSharedContext<>(kernalCtx, null, null, null, mgr, new NoOpWALManager(), null, new IgniteCacheDatabaseSharedManager(), null, null, null, null, null, null, null, null, null, null, null, null, null);
    CheckpointProgressImpl cl0 = Mockito.mock(CheckpointProgressImpl.class);
    IgniteOutClosure<CheckpointProgress> noThrottle = Mockito.mock(IgniteOutClosure.class);
    Mockito.when(noThrottle.apply()).thenReturn(cl0);
    Mockito.when(cl0.currentCheckpointPagesCount()).thenReturn(1_000_000);
    Mockito.when(cl0.evictedPagesCounter()).thenReturn(new AtomicInteger(0));
    Mockito.when(cl0.syncedPagesCounter()).thenReturn(new AtomicInteger(1_000_000));
    Mockito.when(cl0.writtenPagesCounter()).thenReturn(new AtomicInteger(1_000_000));
    PageMemoryImpl mem = cpBufChecker == null ? new PageMemoryImpl(provider, sizes, sharedCtx, sharedCtx.pageStore(), PAGE_SIZE, replaceWriter, new GridInClosure3X<Long, FullPageId, PageMemoryEx>() {

        @Override
        public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) {
        }
    }, () -> true, new DataRegionMetricsImpl(igniteCfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration(), kernalCtx), throttlingPlc, noThrottle) : new PageMemoryImpl(provider, sizes, sharedCtx, sharedCtx.pageStore(), PAGE_SIZE, replaceWriter, new GridInClosure3X<Long, FullPageId, PageMemoryEx>() {

        @Override
        public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) {
        }
    }, () -> true, new DataRegionMetricsImpl(igniteCfg.getDataStorageConfiguration().getDefaultDataRegionConfiguration(), kernalCtx), throttlingPlc, noThrottle) {

        @Override
        public FullPageId pullPageFromCpBuffer() {
            FullPageId pageId = super.pullPageFromCpBuffer();
            cpBufChecker.apply(pageId);
            return pageId;
        }
    };
    mem.metrics().enableMetrics();
    mem.start();
    return mem;
}
Also used : GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) IgnitePluginProcessor(org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) CheckpointProgressImpl(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgressImpl) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) NoopEncryptionSpi(org.apache.ignite.spi.encryption.noop.NoopEncryptionSpi) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) PluginProvider(org.apache.ignite.plugin.PluginProvider) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) JmxSystemViewExporterSpi(org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi) PerformanceStatisticsProcessor(org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor) GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridSystemViewManager(org.apache.ignite.internal.managers.systemview.GridSystemViewManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NoopMetricExporterSpi(org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) FailureProcessor(org.apache.ignite.internal.processors.failure.FailureProcessor) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)

Example 3 with GridInClosure3X

use of org.apache.ignite.internal.util.lang.GridInClosure3X in project ignite by apache.

the class GridCacheDatabaseSharedManager method createPageMemory.

/**
 * {@inheritDoc}
 */
@Override
protected PageMemory createPageMemory(DirectMemoryProvider memProvider, DataStorageConfiguration memCfg, DataRegionConfiguration plcCfg, DataRegionMetricsImpl memMetrics, final boolean trackable) {
    if (!plcCfg.isPersistenceEnabled())
        return super.createPageMemory(memProvider, memCfg, plcCfg, memMetrics, trackable);
    memMetrics.persistenceEnabled(true);
    long cacheSize = plcCfg.getMaxSize();
    // Checkpoint buffer size can not be greater than cache size, it does not make sense.
    long chpBufSize = checkpointBufferSize(plcCfg);
    if (chpBufSize > cacheSize) {
        U.quietAndInfo(log, "Configured checkpoint page buffer size is too big, setting to the max region size [size=" + U.readableSize(cacheSize, false) + ",  memPlc=" + plcCfg.getName() + ']');
        chpBufSize = cacheSize;
    }
    GridInClosure3X<Long, FullPageId, PageMemoryEx> changeTracker;
    if (trackable)
        changeTracker = new GridInClosure3X<Long, FullPageId, PageMemoryEx>() {

            @Override
            public void applyx(Long page, FullPageId fullId, PageMemoryEx pageMem) throws IgniteCheckedException {
                if (trackable)
                    snapshotMgr.onChangeTrackerPage(page, fullId, pageMem);
            }
        };
    else
        changeTracker = null;
    PageMemoryImpl pageMem = new PageMemoryImpl(memProvider, calculateFragmentSizes(memCfg.getConcurrencyLevel(), cacheSize, chpBufSize), cctx, memCfg.getPageSize(), (fullId, pageBuf, tag) -> {
        // First of all, write page to disk.
        storeMgr.write(fullId.groupId(), fullId.pageId(), pageBuf, tag);
        // Only after write we can write page into snapshot.
        snapshotMgr.flushDirtyPageHandler(fullId, pageBuf, tag);
        AtomicInteger cntr = evictedPagesCntr;
        if (cntr != null)
            cntr.incrementAndGet();
    }, changeTracker, this, memMetrics, resolveThrottlingPolicy(), this);
    memMetrics.pageMemory(pageMem);
    return pageMem;
}
Also used : GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Aggregations

FullPageId (org.apache.ignite.internal.pagemem.FullPageId)3 GridInClosure3X (org.apache.ignite.internal.util.lang.GridInClosure3X)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)2 PageMemoryImpl (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 NoOpFailureHandler (org.apache.ignite.failure.NoOpFailureHandler)1 GridEncryptionManager (org.apache.ignite.internal.managers.encryption.GridEncryptionManager)1 GridEventStorageManager (org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager)1 GridSystemViewManager (org.apache.ignite.internal.managers.systemview.GridSystemViewManager)1 JmxSystemViewExporterSpi (org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi)1 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)1 UnsafeMemoryProvider (org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)1 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)1 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)1 IgniteCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager)1 CheckpointProgress (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress)1 CheckpointProgressImpl (org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgressImpl)1