Zakelly commented on code in PR #22590: URL: https://github.com/apache/flink/pull/22590#discussion_r1223810138
########## flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/filemerging/WithinCheckpointFileMergingSnapshotManager.java: ########## @@ -0,0 +1,100 @@ +/* + * 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. This map of file contains all files that are + * not being used and ready to be used. + */ + private final Map<Tuple3<Long, SubtaskKey, CheckpointedStateScope>, PhysicalFile> + availableFiles; + + public WithinCheckpointFileMergingSnapshotManager(String id, Executor ioExecutor) { + // currently there is no file size limit For WITHIN_BOUNDARY mode + super(id, ioExecutor); + availableFiles = 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 (availableFiles) { + file = availableFiles.remove(fileKey); Review Comment: > Is it possible that > > the same key can map to different physical files (it might not be possible at the task level). > > Let's discuss this offline. The same key CAN map to different files. e.g. A file is full under one key, a new file is created for further writing for this key. I think this is not a problem, since it is unnecessary to keep all written data in one file. -- 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