reswqa commented on code in PR #28402: URL: https://github.com/apache/flink/pull/28402#discussion_r3426456705
########## flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/history/FileArchiveStorage.java: ########## @@ -0,0 +1,129 @@ +/* + * 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.webmonitor.history; + +import org.apache.flink.util.FileUtils; + +import javax.annotation.Nullable; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.apache.flink.util.Preconditions.checkNotNull; + +/** + * A file-system backed implementation of {@link ArchiveStorage}. + * + * <p>Each storage key is treated as a relative path under the configured {@code rootPath}. + */ +public class FileArchiveStorage implements ArchiveStorage<File> { + + /** Root directory under which all archive files are stored. */ + private final File rootPath; + + /** + * Creates a new {@link FileArchiveStorage}. + * + * @param rootPath root directory for archive files; must not be {@code null} + * @throws IOException if the canonical path of {@code rootPath} cannot be resolved + */ + public FileArchiveStorage(File rootPath) throws IOException { + this.rootPath = checkNotNull(rootPath).getCanonicalFile(); + } + + @Override + public boolean exists(String key) throws IOException { + return new File(rootPath, key).exists(); Review Comment: I wonder could we avoid the allocation here(e.g. using `Files.exists`)? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
