Search in sources :

Example 1 with GridMultiCollectionWrapper

use of org.apache.ignite.internal.util.GridMultiCollectionWrapper in project ignite by apache.

the class PageMemoryImpl method beginCheckpoint.

/**
 * {@inheritDoc}
 */
@Override
public GridMultiCollectionWrapper<FullPageId> beginCheckpoint() throws IgniteException {
    if (segments == null)
        return new GridMultiCollectionWrapper<>(Collections.<FullPageId>emptyList());
    Collection[] collections = new Collection[segments.length];
    for (int i = 0; i < segments.length; i++) {
        Segment seg = segments[i];
        if (seg.segCheckpointPages != null)
            throw new IgniteException("Failed to begin checkpoint (it is already in progress).");
        collections[i] = seg.segCheckpointPages = seg.dirtyPages;
        seg.dirtyPages = new GridConcurrentHashSet<>();
    }
    memMetrics.resetDirtyPages();
    if (throttlingPlc != ThrottlingPolicy.DISABLED)
        writeThrottle.onBeginCheckpoint();
    return new GridMultiCollectionWrapper<>(collections);
}
Also used : IgniteException(org.apache.ignite.IgniteException) Collection(java.util.Collection) GridMultiCollectionWrapper(org.apache.ignite.internal.util.GridMultiCollectionWrapper) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 2 with GridMultiCollectionWrapper

use of org.apache.ignite.internal.util.GridMultiCollectionWrapper in project ignite by apache.

the class CheckpointWorkflow method splitAndSortCpPagesIfNeeded.

/**
 * Reorders list of checkpoint pages and splits them into appropriate number of sublists according to {@link
 * DataStorageConfiguration#getCheckpointThreads()} and {@link DataStorageConfiguration#getCheckpointWriteOrder()}.
 *
 * @param cpPages Checkpoint pages with overall count and user pages info.
 */
private GridConcurrentMultiPairQueue<PageMemoryEx, FullPageId> splitAndSortCpPagesIfNeeded(CheckpointPagesInfoHolder cpPages) throws IgniteCheckedException {
    Set<T2<PageMemoryEx, FullPageId[]>> cpPagesPerRegion = new HashSet<>();
    int realPagesArrSize = 0;
    int totalPagesCnt = cpPages.pagesNum();
    for (Map.Entry<PageMemoryEx, GridMultiCollectionWrapper<FullPageId>> regPages : cpPages.cpPages()) {
        FullPageId[] pages = new FullPageId[regPages.getValue().size()];
        int pagePos = 0;
        for (int i = 0; i < regPages.getValue().collectionsSize(); i++) {
            for (FullPageId page : regPages.getValue().innerCollection(i)) {
                if (realPagesArrSize++ == totalPagesCnt)
                    throw new AssertionError("Incorrect estimated dirty pages number: " + totalPagesCnt);
                pages[pagePos++] = page;
            }
        }
        // Some pages may have been already replaced.
        if (pagePos != pages.length)
            cpPagesPerRegion.add(new T2<>(regPages.getKey(), Arrays.copyOf(pages, pagePos)));
        else
            cpPagesPerRegion.add(new T2<>(regPages.getKey(), pages));
    }
    if (checkpointWriteOrder == CheckpointWriteOrder.SEQUENTIAL) {
        Comparator<FullPageId> cmp = Comparator.comparingInt(FullPageId::groupId).thenComparingLong(FullPageId::effectivePageId);
        ForkJoinPool pool = null;
        for (T2<PageMemoryEx, FullPageId[]> pagesPerReg : cpPagesPerRegion) {
            if (pagesPerReg.getValue().length >= parallelSortThreshold)
                pool = parallelSortInIsolatedPool(pagesPerReg.get2(), cmp, pool);
            else
                Arrays.sort(pagesPerReg.get2(), cmp);
        }
        if (pool != null)
            pool.shutdown();
    }
    return new GridConcurrentMultiPairQueue<>(cpPagesPerRegion);
}
Also used : PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) GridMultiCollectionWrapper(org.apache.ignite.internal.util.GridMultiCollectionWrapper) GridConcurrentMultiPairQueue(org.apache.ignite.internal.util.GridConcurrentMultiPairQueue) Map(java.util.Map) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) PartitionAllocationMap(org.apache.ignite.internal.processors.cache.persistence.partstate.PartitionAllocationMap) T2(org.apache.ignite.internal.util.typedef.T2) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) HashSet(java.util.HashSet) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 3 with GridMultiCollectionWrapper

use of org.apache.ignite.internal.util.GridMultiCollectionWrapper in project ignite by apache.

the class PageMemoryImplTest method runThrottlingEmptifyCpBufFirst.

/**
 * @throws Exception if failed.
 */
public void runThrottlingEmptifyCpBufFirst(PageMemoryImpl.ThrottlingPolicy plc) throws Exception {
    TestPageStoreManager pageStoreMgr = new TestPageStoreManager();
    final List<FullPageId> allocated = new ArrayList<>();
    int pagesForStartThrottling = 10;
    // Number of pages which were poll from checkpoint buffer for throttling.
    AtomicInteger cpBufferPollPages = new AtomicInteger();
    // Create a 1 mb page memory.
    PageMemoryImpl memory = createPageMemory(1, plc, pageStoreMgr, pageStoreMgr, (IgniteInClosure<FullPageId>) fullPageId -> {
        assertEquals(cpBufferPollPages.incrementAndGet(), pageStoreMgr.storedPages.size());
    });
    assert pagesForStartThrottling < memory.checkpointBufferPagesSize() / 3;
    for (int i = 0; i < pagesForStartThrottling + (memory.checkpointBufferPagesSize() * 2 / 3); i++) {
        long id = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
        FullPageId fullId = new FullPageId(id, 1);
        allocated.add(fullId);
        writePage(memory, fullId, (byte) 1);
    }
    GridMultiCollectionWrapper<FullPageId> markedPages = memory.beginCheckpoint(new GridFinishedFuture());
    for (int i = 0; i < pagesForStartThrottling + (memory.checkpointBufferPagesSize() * 2 / 3); i++) writePage(memory, allocated.get(i), (byte) 1);
    doCheckpoint(markedPages, memory, pageStoreMgr);
    // There is 'pagesForStartThrottling - 1' because we should write pagesForStartThrottling pages
    // from checkpoint buffer before throttling will be disabled but at least one page always would be written
    // outside of throttling and in our case we certainly know that this page is also contained in checkpoint buffer
    // (because all of our pages are in checkpoint buffer).
    assertEquals(pagesForStartThrottling - 1, cpBufferPollPages.get());
}
Also used : PageStore(org.apache.ignite.internal.pagemem.store.PageStore) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) ByteBuffer(java.nio.ByteBuffer) NoopMetricExporterSpi(org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi) GridSystemViewManager(org.apache.ignite.internal.managers.systemview.GridSystemViewManager) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IgnitePluginProcessor(org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) Map(java.util.Map) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) FailureProcessor(org.apache.ignite.internal.processors.failure.FailureProcessor) CheckpointProgressImpl(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgressImpl) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) ByteOrder(java.nio.ByteOrder) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) PerformanceStatisticsProcessor(org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteOutOfMemoryException(org.apache.ignite.internal.mem.IgniteOutOfMemoryException) JmxSystemViewExporterSpi(org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) CHECKPOINT_POOL_OVERFLOW_ERROR_MSG(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl.CHECKPOINT_POOL_OVERFLOW_ERROR_MSG) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) GridMultiCollectionWrapper(org.apache.ignite.internal.util.GridMultiCollectionWrapper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) NoopEncryptionSpi(org.apache.ignite.spi.encryption.noop.NoopEncryptionSpi) Test(org.junit.Test) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) Mockito(org.mockito.Mockito) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) PluginProvider(org.apache.ignite.plugin.PluginProvider) DummyPageIO(org.apache.ignite.internal.processors.cache.persistence.DummyPageIO) PageStoreWriter(org.apache.ignite.internal.processors.cache.persistence.PageStoreWriter) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture)

Example 4 with GridMultiCollectionWrapper

use of org.apache.ignite.internal.util.GridMultiCollectionWrapper in project ignite by apache.

the class PageMemoryImpl method beginCheckpoint.

/**
 * {@inheritDoc}
 */
@Override
public GridMultiCollectionWrapper<FullPageId> beginCheckpoint(IgniteInternalFuture allowToReplace) throws IgniteException {
    if (segments == null)
        return new GridMultiCollectionWrapper<>(Collections.emptyList());
    Collection[] collections = new Collection[segments.length];
    for (int i = 0; i < segments.length; i++) {
        Segment seg = segments[i];
        if (seg.checkpointPages != null)
            throw new IgniteException("Failed to begin checkpoint (it is already in progress).");
        Collection<FullPageId> dirtyPages = seg.dirtyPages;
        collections[i] = dirtyPages;
        seg.checkpointPages = new CheckpointPages(dirtyPages, allowToReplace);
        seg.resetDirtyPages();
    }
    safeToUpdate.set(true);
    dataRegionMetrics.resetDirtyPages();
    if (throttlingPlc != ThrottlingPolicy.DISABLED)
        writeThrottle.onBeginCheckpoint();
    return new GridMultiCollectionWrapper<>(collections);
}
Also used : IgniteException(org.apache.ignite.IgniteException) Collection(java.util.Collection) GridMultiCollectionWrapper(org.apache.ignite.internal.util.GridMultiCollectionWrapper) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 5 with GridMultiCollectionWrapper

use of org.apache.ignite.internal.util.GridMultiCollectionWrapper in project ignite by apache.

the class PageMemoryImplTest method doCheckpoint.

/**
 * @param cpPages Checkpoint pages acuiqred by {@code beginCheckpoint()}.
 * @param memory Page memory.
 * @param pageStoreMgr Test page store manager.
 * @throws Exception If failed.
 */
private void doCheckpoint(GridMultiCollectionWrapper<FullPageId> cpPages, PageMemoryImpl memory, TestPageStoreManager pageStoreMgr) throws Exception {
    PageStoreWriter pageStoreWriter = (fullPageId, buf, tag) -> {
        assertNotNull(tag);
        pageStoreMgr.write(fullPageId.groupId(), fullPageId.pageId(), buf, 1, false);
    };
    for (FullPageId cpPage : cpPages) {
        byte[] data = new byte[PAGE_SIZE];
        ByteBuffer buf = ByteBuffer.wrap(data);
        memory.checkpointWritePage(cpPage, buf, pageStoreWriter, null);
        while (memory.isCpBufferOverflowThresholdExceeded()) {
            FullPageId cpPageId = memory.pullPageFromCpBuffer();
            if (cpPageId.equals(FullPageId.NULL_PAGE))
                break;
            ByteBuffer tmpWriteBuf = ByteBuffer.allocateDirect(memory.pageSize());
            tmpWriteBuf.order(ByteOrder.nativeOrder());
            tmpWriteBuf.rewind();
            memory.checkpointWritePage(cpPageId, tmpWriteBuf, pageStoreWriter, null);
        }
    }
    memory.finishCheckpoint();
}
Also used : PageStore(org.apache.ignite.internal.pagemem.store.PageStore) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) ByteBuffer(java.nio.ByteBuffer) NoopMetricExporterSpi(org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi) GridSystemViewManager(org.apache.ignite.internal.managers.systemview.GridSystemViewManager) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IgnitePluginProcessor(org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) Map(java.util.Map) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) FailureProcessor(org.apache.ignite.internal.processors.failure.FailureProcessor) CheckpointProgressImpl(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgressImpl) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) ByteOrder(java.nio.ByteOrder) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) PerformanceStatisticsProcessor(org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsProcessor) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteOutOfMemoryException(org.apache.ignite.internal.mem.IgniteOutOfMemoryException) JmxSystemViewExporterSpi(org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) CHECKPOINT_POOL_OVERFLOW_ERROR_MSG(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl.CHECKPOINT_POOL_OVERFLOW_ERROR_MSG) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) GridMultiCollectionWrapper(org.apache.ignite.internal.util.GridMultiCollectionWrapper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) NoopEncryptionSpi(org.apache.ignite.spi.encryption.noop.NoopEncryptionSpi) Test(org.junit.Test) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) Mockito(org.mockito.Mockito) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) PluginProvider(org.apache.ignite.plugin.PluginProvider) DummyPageIO(org.apache.ignite.internal.processors.cache.persistence.DummyPageIO) PageStoreWriter(org.apache.ignite.internal.processors.cache.persistence.PageStoreWriter) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) Collections(java.util.Collections) ByteBuffer(java.nio.ByteBuffer) PageStoreWriter(org.apache.ignite.internal.processors.cache.persistence.PageStoreWriter) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Aggregations

FullPageId (org.apache.ignite.internal.pagemem.FullPageId)5 GridMultiCollectionWrapper (org.apache.ignite.internal.util.GridMultiCollectionWrapper)5 Map (java.util.Map)3 ByteBuffer (java.nio.ByteBuffer)2 ByteOrder (java.nio.ByteOrder)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteException (org.apache.ignite.IgniteException)2 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 NoOpFailureHandler (org.apache.ignite.failure.NoOpFailureHandler)2 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)2