tkalkirill commented on code in PR #800: URL: https://github.com/apache/ignite-3/pull/800#discussion_r870207963
########## modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/checkpoint/CheckpointProgressImpl.java: ########## @@ -0,0 +1,263 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.pagememory.persistence.checkpoint; + +import static org.apache.ignite.internal.pagememory.persistence.checkpoint.CheckpointState.FINISHED; +import static org.apache.ignite.internal.pagememory.persistence.checkpoint.CheckpointState.LOCK_RELEASED; +import static org.apache.ignite.internal.pagememory.persistence.checkpoint.CheckpointState.SCHEDULED; + +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import org.jetbrains.annotations.Nullable; + +/** + * Data class representing the state of running/scheduled checkpoint. + */ +class CheckpointProgressImpl implements CheckpointProgress { + /** Checkpoint id. */ + private final UUID id = UUID.randomUUID(); + + /** Scheduled time of checkpoint. */ + private volatile long nextCheckpointNanos; + + /** Current checkpoint state. */ + private volatile AtomicReference<CheckpointState> state = new AtomicReference<>(SCHEDULED); + + /** Future which would be finished when corresponds state is set. */ + private final Map<CheckpointState, CompletableFuture<Void>> stateFutures = new ConcurrentHashMap<>(); + + /** Wakeup reason. */ + private volatile String reason; + + /** Number of dirty pages in current checkpoint at the beginning of checkpoint. */ + private volatile int currCheckpointPagesCnt; + + /** Cause of fail, which has happened during the checkpoint or {@code null} if checkpoint was successful. */ + @Nullable + private volatile Throwable failCause; + + /** Counter for written checkpoint pages. Not {@link null} only if checkpoint is running. */ + @Nullable + private volatile AtomicInteger writtenPagesCntr; + + /** Counter for fsynced checkpoint pages. Not {@link null} only if checkpoint is running. */ + @Nullable + private volatile AtomicInteger syncedPagesCntr; + + /** Counter for evicted checkpoint pages. Not {@link null} only if checkpoint is running. */ + @Nullable + private volatile AtomicInteger evictedPagesCntr; + + /** + * Constructor. + * + * @param nextCheckpointTimeout Timeout until next checkpoint in nanos. + */ + CheckpointProgressImpl(long nextCheckpointTimeout) { + nextCheckpointNanos(nextCheckpointTimeout); + } + + /** {@inheritDoc} */ + @Override + public UUID id() { + return id; + } + + /** {@inheritDoc} */ + @Override + public @Nullable String reason() { + return reason; + } + + /** + * Sets description of the reason of the current checkpoint. + * + * @param reason New wakeup reason. + */ + public void reason(String reason) { + this.reason = reason; + } + + /** {@inheritDoc} */ + @Override + public boolean inProgress() { + return greaterOrEqualTo(LOCK_RELEASED) && !greaterOrEqualTo(FINISHED); + } + + /** {@inheritDoc} */ + @Override + public CompletableFuture<Void> futureFor(CheckpointState state) { Review Comment: Added ticket link to class header -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
