Search in sources :

Example 1 with CountDownFuture

use of org.apache.ignite.internal.util.future.CountDownFuture in project ignite by apache.

the class Checkpointer method writePages.

/**
 * @param workProgressDispatcher Work progress dispatcher.
 * @param tracker Checkpoint metrics tracker.
 * @param cpPages List of pages to write.
 * @param curCpProgress Current checkpoint data.
 * @param shutdownNow Checker of stop operation.
 */
boolean writePages(CheckpointMetricsTracker tracker, GridConcurrentMultiPairQueue<PageMemoryEx, FullPageId> cpPages, CheckpointProgressImpl curCpProgress, WorkProgressDispatcher workProgressDispatcher, BooleanSupplier shutdownNow) throws IgniteCheckedException {
    IgniteThreadPoolExecutor pageWritePool = checkpointWritePagesPool;
    int checkpointWritePageThreads = pageWritePool == null ? 1 : pageWritePool.getMaximumPoolSize();
    // Identity stores set.
    ConcurrentLinkedHashMap<PageStore, LongAdder> updStores = new ConcurrentLinkedHashMap<>();
    CountDownFuture doneWriteFut = new CountDownFuture(checkpointWritePageThreads);
    tracker.onPagesWriteStart();
    for (int i = 0; i < checkpointWritePageThreads; i++) {
        Runnable write = checkpointPagesWriterFactory.build(tracker, cpPages, updStores, doneWriteFut, workProgressDispatcher::updateHeartbeat, curCpProgress, shutdownNow);
        if (pageWritePool == null)
            write.run();
        else {
            try {
                pageWritePool.execute(write);
            } catch (RejectedExecutionException ignore) {
                // Run the task synchronously.
                write.run();
            }
        }
    }
    workProgressDispatcher.updateHeartbeat();
    // Wait and check for errors.
    doneWriteFut.get();
    // If so, we should not put finish checkpoint mark.
    if (shutdownNow.getAsBoolean()) {
        curCpProgress.fail(new NodeStoppingException("Node is stopping."));
        return false;
    }
    tracker.onFsyncStart();
    if (!skipSync) {
        for (Map.Entry<PageStore, LongAdder> updStoreEntry : updStores.entrySet()) {
            if (shutdownNow.getAsBoolean()) {
                curCpProgress.fail(new NodeStoppingException("Node is stopping."));
                return false;
            }
            workProgressDispatcher.blockingSectionBegin();
            try {
                updStoreEntry.getKey().sync();
            } finally {
                workProgressDispatcher.blockingSectionEnd();
            }
            curCpProgress.updateSyncedPages(updStoreEntry.getValue().intValue());
        }
    }
    return true;
}
Also used : CountDownFuture(org.apache.ignite.internal.util.future.CountDownFuture) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IgniteThreadPoolExecutor(org.apache.ignite.thread.IgniteThreadPoolExecutor) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap) LongAdder(java.util.concurrent.atomic.LongAdder) Map(java.util.Map) ConcurrentLinkedHashMap(org.jsr166.ConcurrentLinkedHashMap)

Aggregations

Map (java.util.Map)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 LongAdder (java.util.concurrent.atomic.LongAdder)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 PageStore (org.apache.ignite.internal.pagemem.store.PageStore)1 CountDownFuture (org.apache.ignite.internal.util.future.CountDownFuture)1 IgniteThreadPoolExecutor (org.apache.ignite.thread.IgniteThreadPoolExecutor)1 ConcurrentLinkedHashMap (org.jsr166.ConcurrentLinkedHashMap)1