Search in sources :

Example 26 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class CheckpointPagesWriter method createPageStoreWriter.

/**
 * Factory method for create {@link PageStoreWriter}.
 *
 * @param pageMemEx
 * @param pagesToRetry List pages for retry.
 * @return Checkpoint page write context.
 */
private PageStoreWriter createPageStoreWriter(PageMemoryEx pageMemEx, Map<PageMemoryEx, List<FullPageId>> pagesToRetry) {
    return new PageStoreWriter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void writePage(FullPageId fullPageId, ByteBuffer buf, int tag) throws IgniteCheckedException {
            if (tag == PageMemoryImpl.TRY_AGAIN_TAG) {
                pagesToRetry.computeIfAbsent(pageMemEx, k -> new ArrayList<>()).add(fullPageId);
                return;
            }
            int groupId = fullPageId.groupId();
            long pageId = fullPageId.pageId();
            assert getType(buf) != 0 : "Invalid state. Type is 0! pageId = " + hexLong(pageId);
            assert getVersion(buf) != 0 : "Invalid state. Version is 0! pageId = " + hexLong(pageId);
            if (persStoreMetrics.metricsEnabled()) {
                int pageType = getType(buf);
                if (PageIO.isDataPageType(pageType))
                    tracker.onDataPageWritten();
            }
            curCpProgress.updateWrittenPages(1);
            PageStore store = pageWriter.write(pageMemEx, fullPageId, buf, tag);
            updStores.computeIfAbsent(store, k -> new LongAdder()).increment();
        }
    };
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) DataStorageMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataStorageMetricsImpl) CheckpointMetricsTracker(org.apache.ignite.internal.processors.cache.persistence.pagemem.CheckpointMetricsTracker) IgniteUtils.hexLong(org.apache.ignite.internal.util.IgniteUtils.hexLong) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) PageIO.getVersion(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.getVersion) Map(java.util.Map) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) IgniteThrowableFunction(org.apache.ignite.internal.util.lang.IgniteThrowableFunction) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CountDownFuture(org.apache.ignite.internal.util.future.CountDownFuture) PageIO.getType(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO.getType) PageMemoryImpl(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl) List(java.util.List) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) PageStoreWriter(org.apache.ignite.internal.processors.cache.persistence.PageStoreWriter) IgniteCacheSnapshotManager(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteCacheSnapshotManager) GridConcurrentMultiPairQueue(org.apache.ignite.internal.util.GridConcurrentMultiPairQueue) LongAdder(java.util.concurrent.atomic.LongAdder) ArrayList(java.util.ArrayList) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) ByteBuffer(java.nio.ByteBuffer) PageStoreWriter(org.apache.ignite.internal.processors.cache.persistence.PageStoreWriter) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 27 with PageStore

use of org.apache.ignite.internal.pagemem.store.PageStore in project ignite by apache.

the class CheckpointWorkflow method finalizeCheckpointOnRecovery.

/**
 * This method makes sense if node was stopped during the checkpoint(Start marker was written to disk while end
 * marker are not). It is able to write all pages to disk and create end marker.
 *
 * @throws IgniteCheckedException If failed.
 */
public void finalizeCheckpointOnRecovery(long cpTs, UUID cpId, WALPointer walPtr, StripedExecutor exec, CheckpointPagesWriterFactory checkpointPagesWriterFactory) throws IgniteCheckedException {
    assert cpTs != 0;
    long start = System.currentTimeMillis();
    Collection<DataRegion> regions = dataRegions.get();
    CheckpointPagesInfoHolder cpPagesHolder = beginAllCheckpoints(regions, new GridFinishedFuture<>());
    // Sort and split all dirty pages set to several stripes.
    GridConcurrentMultiPairQueue<PageMemoryEx, FullPageId> pages = splitAndSortCpPagesIfNeeded(cpPagesHolder);
    // Identity stores set for future fsync.
    Collection<PageStore> updStores = new GridConcurrentHashSet<>();
    AtomicInteger cpPagesCnt = new AtomicInteger();
    // Shared refernce for tracking exception during write pages.
    AtomicReference<Throwable> writePagesError = new AtomicReference<>();
    for (int stripeIdx = 0; stripeIdx < exec.stripesCount(); stripeIdx++) exec.execute(stripeIdx, checkpointPagesWriterFactory.buildRecovery(pages, updStores, writePagesError, cpPagesCnt));
    // Await completion all write tasks.
    awaitApplyComplete(exec, writePagesError);
    long written = U.currentTimeMillis();
    // Fsync all touched stores.
    for (PageStore updStore : updStores) updStore.sync();
    long fsync = U.currentTimeMillis();
    for (DataRegion memPlc : regions) {
        if (memPlc.config().isPersistenceEnabled())
            ((PageMemoryEx) memPlc.pageMemory()).finishCheckpoint();
    }
    checkpointMarkersStorage.writeCheckpointEntry(cpTs, cpId, walPtr, null, CheckpointEntryType.END, skipSync);
    if (log.isInfoEnabled())
        log.info(String.format("Checkpoint finished [cpId=%s, pages=%d, markPos=%s, " + "pagesWrite=%dms, fsync=%dms, total=%dms]", cpId, cpPagesCnt.get(), walPtr, written - start, fsync - written, fsync - start));
}
Also used : PageStore(org.apache.ignite.internal.pagemem.store.PageStore) AtomicReference(java.util.concurrent.atomic.AtomicReference) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Aggregations

PageStore (org.apache.ignite.internal.pagemem.store.PageStore)27 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)10 FilePageStoreManager (org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager)9 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 IgniteException (org.apache.ignite.IgniteException)6 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Map (java.util.Map)5 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)5 GridCacheDatabaseSharedManager (org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager)5 PageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)5 File (java.io.File)4 ByteBuffer (java.nio.ByteBuffer)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 FailureContext (org.apache.ignite.failure.FailureContext)4 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)4 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)4