echauchot commented on a change in pull request #13040: URL: https://github.com/apache/flink/pull/13040#discussion_r492597386
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/CheckpointsCleaner.java ########## @@ -0,0 +1,79 @@ +/* + * 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.flink.runtime.checkpoint; + +import org.apache.flink.runtime.jobgraph.OperatorID; +import org.apache.flink.runtime.state.CheckpointStorageLocation; +import org.apache.flink.runtime.state.StateUtil; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.Serializable; +import java.util.Map; +import java.util.concurrent.Executor; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * Delegate class responsible for checkpoints cleaning and counting the number of checkpoints yet + * to clean. + */ +public class CheckpointsCleaner implements Serializable{ + private final AtomicInteger numberOfCheckpointsToClean; + private static final Logger LOG = LoggerFactory.getLogger(CheckpointsCleaner.class); + + public CheckpointsCleaner() { + this.numberOfCheckpointsToClean = new AtomicInteger(0); + } + + int getNumberOfCheckpointsToClean() { + return numberOfCheckpointsToClean.get(); + } + + public void cleanCheckpoint(Runnable cleanAction, Runnable postCleanAction, Executor executor) { + numberOfCheckpointsToClean.incrementAndGet(); + executor.execute(() -> { + try { + cleanAction.run(); + } finally { + numberOfCheckpointsToClean.decrementAndGet(); + postCleanAction.run(); + } + }); + } + + public void cleanStates(Runnable postCleanAction, Map<OperatorID, OperatorState> operatorStates, PendingCheckpoint pendingCheckpoint, CheckpointStorageLocation targetLocation, Executor executor){ + numberOfCheckpointsToClean.incrementAndGet(); + executor.execute(() -> { + // discard the private states. + // unregistered shared states are still considered private at this point. + try { + StateUtil.bestEffortDiscardAllStateObjects(operatorStates.values()); + targetLocation.disposeOnFailure(); Review comment: @rkhachatryan can you confirm that this is indeed the refactoring that you want before I code it ? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org