Zakelly commented on code in PR #25818: URL: https://github.com/apache/flink/pull/25818#discussion_r1898232175
########## flink-state-backends/flink-statebackend-forst/src/main/java/org/apache/flink/state/forst/fs/filemapping/FileMappingManager.java: ########## @@ -0,0 +1,247 @@ +/* + * 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.state.forst.fs.filemapping; + +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.core.fs.FileStatus; +import org.apache.flink.core.fs.FileSystem; +import org.apache.flink.core.fs.Path; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * A manager to manage file mapping of forst file system, including misc file mapping (remote file + * -> local file) and linked mapping (remote file -> remote file). Directory link is not support + * now. + */ +public class FileMappingManager { + + private static final Logger LOG = LoggerFactory.getLogger(FileMappingManager.class); + + public static final String SST_SUFFIX = ".sst"; + + private final FileSystem fileSystem; + + private final FileSystem localFileSystem; + + private final HashMap<String, MappingEntry> mappingTable; + + private final String remoteBase; + + private final String localBase; + + public FileMappingManager( + FileSystem fileSystem, + FileSystem localFileSystem, + String remoteBase, + String localBase) { + this.fileSystem = fileSystem; + this.localFileSystem = localFileSystem; + this.mappingTable = new HashMap<>(); + this.remoteBase = remoteBase; + this.localBase = localBase; + } + + /** Create a mapping entry for a file, currently invoked by creating remote file. */ + public void createFile(String file) { + mappingTable.put(file, new MappingEntry(1, fileSystem, file, false)); + } + + /** Called by link/copy. Directory link is not supported now. */ + public int link(String src, String dst) { + if (src.equals(dst)) { + return -1; + } + // if dst already exist, not allow + if (mappingTable.containsKey(dst)) { + return -1; + } + MappingEntry sourceEntry = mappingTable.get(src); + if (sourceEntry != null) { + sourceEntry.retain(); + mappingTable.putIfAbsent(dst, sourceEntry); + } else { + sourceEntry = new MappingEntry(fileSystem, src); + mappingTable.put(src, sourceEntry); + mappingTable.put(dst, sourceEntry); + } + LOG.trace("link: {} -> {}", src, dst); Review Comment: `link` means `dst` is referencing the `src`, right? This log is confusing. ```suggestion LOG.trace("link: {} -> {}", dst, src); ``` ########## flink-state-backends/flink-statebackend-forst/src/main/java/org/apache/flink/state/forst/fs/filemapping/FileMappingManager.java: ########## @@ -0,0 +1,247 @@ +/* + * 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.state.forst.fs.filemapping; + +import org.apache.flink.annotation.VisibleForTesting; +import org.apache.flink.core.fs.FileStatus; +import org.apache.flink.core.fs.FileSystem; +import org.apache.flink.core.fs.Path; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * A manager to manage file mapping of forst file system, including misc file mapping (remote file + * -> local file) and linked mapping (remote file -> remote file). Directory link is not support + * now. + */ +public class FileMappingManager { + + private static final Logger LOG = LoggerFactory.getLogger(FileMappingManager.class); + + public static final String SST_SUFFIX = ".sst"; + + private final FileSystem fileSystem; + + private final FileSystem localFileSystem; + + private final HashMap<String, MappingEntry> mappingTable; + + private final String remoteBase; + + private final String localBase; + + public FileMappingManager( + FileSystem fileSystem, + FileSystem localFileSystem, + String remoteBase, + String localBase) { + this.fileSystem = fileSystem; + this.localFileSystem = localFileSystem; + this.mappingTable = new HashMap<>(); + this.remoteBase = remoteBase; + this.localBase = localBase; + } + + /** Create a mapping entry for a file, currently invoked by creating remote file. */ + public void createFile(String file) { + mappingTable.put(file, new MappingEntry(1, fileSystem, file, false)); + } + + /** Called by link/copy. Directory link is not supported now. */ + public int link(String src, String dst) { + if (src.equals(dst)) { + return -1; + } + // if dst already exist, not allow + if (mappingTable.containsKey(dst)) { + return -1; + } + MappingEntry sourceEntry = mappingTable.get(src); + if (sourceEntry != null) { + sourceEntry.retain(); + mappingTable.putIfAbsent(dst, sourceEntry); + } else { + sourceEntry = new MappingEntry(fileSystem, src); + mappingTable.put(src, sourceEntry); + mappingTable.put(dst, sourceEntry); + } + LOG.trace("link: {} -> {}", src, dst); + return 0; + } + + /** Get the real path of a file, the real path maybe a local file or a remote file/dir. */ + public RealPath realPath(Path file, boolean update) { Review Comment: This `update == true` code path can be moved to `createFile` -- 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