Zakelly commented on code in PR #22590: URL: https://github.com/apache/flink/pull/22590#discussion_r1205081339
########## flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/filemerging/WithinCheckpointFileMergingSnapshotManager.java: ########## @@ -0,0 +1,97 @@ +/* + * 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.filemerging; + +import org.apache.flink.api.java.tuple.Tuple3; +import org.apache.flink.core.fs.FSDataOutputStream; +import org.apache.flink.runtime.state.CheckpointedStateScope; + +import javax.annotation.Nonnull; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Executor; + +/** A {@link FileMergingSnapshotManager} that merging files within a checkpoint. */ +public class WithinCheckpointFileMergingSnapshotManager extends FileMergingSnapshotManagerBase { + + /** A dummy subtask key to reuse files among subtasks for private states. */ + private static final SubtaskKey dummySubtaskKey = new SubtaskKey("dummy", -1, -1); + + /** + * OutputStreams to be reused when writing checkpoint files. For WITHIN_BOUNDARY mode, physical + * files are NOT shared among multiple checkpoints. + */ + private final Map<Tuple3<Long, SubtaskKey, CheckpointedStateScope>, PhysicalFile> fileMap; + + public WithinCheckpointFileMergingSnapshotManager(String id, Executor ioExecutor) { + // currently there is no file size limit For WITHIN_BOUNDARY mode + super(id, ioExecutor); + fileMap = new HashMap<>(); + } + + @Override + @Nonnull + protected PhysicalFile getOrCreatePhysicalFileForCheckpoint( + SubtaskKey subtaskKey, long checkpointId, CheckpointedStateScope scope) + throws IOException { + // TODO: FLINK-32076 will add a file pool for each subtask key. + Tuple3<Long, SubtaskKey, CheckpointedStateScope> fileKey = + Tuple3.of( + checkpointId, + scope == CheckpointedStateScope.SHARED ? subtaskKey : dummySubtaskKey, + scope); + PhysicalFile file; + synchronized (fileMap) { + file = fileMap.remove(fileKey); + if (file == null) { + file = createPhysicalFile(subtaskKey, scope); + } + } + return file; + } + + @Override + protected void tryReusingPhysicalFile( + SubtaskKey subtaskKey, long checkpointId, PhysicalFile physicalFile) + throws IOException { + // TODO: FLINK-32076 will add a file pool for reusing. + CheckpointedStateScope scope = physicalFile.getScope(); + Tuple3<Long, SubtaskKey, CheckpointedStateScope> fileKey = + Tuple3.of( + checkpointId, + scope == CheckpointedStateScope.SHARED ? subtaskKey : dummySubtaskKey, + scope); + PhysicalFile current; + synchronized (fileMap) { + current = fileMap.putIfAbsent(fileKey, physicalFile); + } + if (syncAfterClosingLogicalFile) { + FSDataOutputStream os = physicalFile.getOutputStream(); + if (os != null) { + os.flush(); Review Comment: According to the JavaDoc of `org.apache.flink.core.fs.FSDataOutputStream::sync()`, the implementation should ensure all the data (including those in cache and buffer) can be persisted in non-volatile storage. So I removed the call of `flush()`. -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org