Zakelly commented on code in PR #25818: URL: https://github.com/apache/flink/pull/25818#discussion_r1895442486
########## flink-state-backends/flink-statebackend-forst/src/main/java/org/apache/flink/state/forst/fs/filemapping/FileMappingManager.java: ########## @@ -0,0 +1,148 @@ +/* + * 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.apache.flink.util.Preconditions; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * A manager to manage file mapping of forst file system. Only interact with + * copy()/link()/exist()/delete()/list(), create() won't use file mapping. + */ +public class FileMappingManager { + + private static final Logger LOG = LoggerFactory.getLogger(FileMappingManager.class); + + private FileSystem fileSystem; + + private HashMap<String, MappingEntry> mappingTable; + + public FileMappingManager(FileSystem fileSystem) { + this.fileSystem = fileSystem; + this.mappingTable = new HashMap<>(); + } + + /** Called by link/copy. */ + public int put(String src, String dst) { + if (src == dst) { // self link is not supported + 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("put: {} -> {}", src, dst); + return 0; + } + + public String originalPath(String fileName) { + MappingEntry entry = mappingTable.getOrDefault(fileName, null); + if (entry != null) { + return entry.sourcePath; + } + return fileName; + } + + public List<String> listByPrefix(String path) { Review Comment: Thanks for the clarification! Is there any more safe and precise way check whether a file is under a specified directory? I mean, instead of just `startWith`. e.g. `file:///a/bfile` contains `file:///a/bfilesuffix` but actually they are under same directory. Maybe trim the ending '/' of folder string and check `startWith`, then check whether the suffix part of fileString that is more than folderString starts with a '/'? -- 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