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