This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-fs-spi in repository https://gitbox.apache.org/repos/asf/doris.git
commit 13dc273b565cecb38e2b0732c58659adb75c32d6 Author: morningman <[email protected]> AuthorDate: Wed Apr 1 14:42:18 2026 +0800 [refactor](fs-spi) P4.8-A: delete LegacyToNewFsAdapter and LegacyFileSystemAdapter ### What problem does this PR solve? Issue Number: N/A Problem Summary: Phase A of the P4.8 legacy filesystem class deletion. Both LegacyToNewFsAdapter and LegacyFileSystemAdapter have no external callers (confirmed by grep). LegacyToNewFsAdapter was a concrete adapter wrapping LegacyFileSystemApi; LegacyFileSystemAdapter was the abstract Status→IOException bridge. Both are now dead code after the P4.1–P4.7 caller migrations. Also removes the stale @see LegacyFileSystemAdapter javadoc tag from FileSystem.java. ### Release note None ### Check List (For Author) - Test: No need to test (deleting dead code with no callers) - Behavior changed: No - Does this need documentation: No Co-authored-by: Copilot <[email protected]> --- .../main/java/org/apache/doris/fs/FileSystem.java | 1 - .../apache/doris/fs/LegacyFileSystemAdapter.java | 221 --------------------- .../org/apache/doris/fs/LegacyToNewFsAdapter.java | 92 --------- 3 files changed, 314 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/fs/FileSystem.java b/fe/fe-core/src/main/java/org/apache/doris/fs/FileSystem.java index 2404068a2ff..3d95c1f7e6f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/fs/FileSystem.java +++ b/fe/fe-core/src/main/java/org/apache/doris/fs/FileSystem.java @@ -33,7 +33,6 @@ import java.util.Set; * <p> * Implementations must be thread-safe. Instances may be shared and cached. * - * @see LegacyFileSystemAdapter for adapting existing Status-based implementations * @see MemoryFileSystem for in-memory testing * @see LegacyFileSystemApi for the legacy Status-based interface (deprecated) */ diff --git a/fe/fe-core/src/main/java/org/apache/doris/fs/LegacyFileSystemAdapter.java b/fe/fe-core/src/main/java/org/apache/doris/fs/LegacyFileSystemAdapter.java deleted file mode 100644 index c3b53f44f43..00000000000 --- a/fe/fe-core/src/main/java/org/apache/doris/fs/LegacyFileSystemAdapter.java +++ /dev/null @@ -1,221 +0,0 @@ -// 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.doris.fs; - -import org.apache.doris.backup.Status; -import org.apache.doris.fs.io.DorisInputFile; -import org.apache.doris.fs.io.DorisOutputFile; -import org.apache.doris.fs.io.ParsedPath; -import org.apache.doris.fs.remote.RemoteFile; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * Bridge adapter that implements the new {@link FileSystem} interface by delegating - * to existing Status-based legacy methods. - * <p> - * Subclasses override the {@code legacy*()} methods (which have the old Status-based - * signatures) and gain the new IOException-based interface for free. - * <p> - * Migration path: - * <ol> - * <li>Existing classes that extend {@link org.apache.doris.fs.remote.RemoteFileSystem} - * (or its subclasses) should be gradually updated to extend this class instead.</li> - * <li>In Phase 3, when {@code RemoteFileSystem} is removed, all subclasses will directly - * extend this class and implement {@code legacy*()} methods.</li> - * </ol> - */ -public abstract class LegacyFileSystemAdapter implements FileSystem { - - // ─────────────────────────── ABSTRACT LEGACY METHODS ─────────────────────────── - - /** Checks file/directory existence. Returns {@link Status.ErrCode#NOT_FOUND} if absent. */ - protected abstract Status legacyExists(String remotePath); - - /** Deletes a file at {@code remotePath}. */ - protected abstract Status legacyDelete(String remotePath); - - /** Renames (moves) a file from {@code orig} to {@code dest}. */ - protected abstract Status legacyRename(String orig, String dest); - - /** Creates a directory at {@code remotePath} (including parents). */ - protected abstract Status legacyMakeDir(String remotePath); - - /** - * Lists files under {@code remotePath}. - * Results are appended to {@code result}. - */ - protected abstract Status legacyListFiles(String remotePath, boolean recursive, - List<RemoteFile> result); - - /** - * Lists immediate child directories under {@code remotePath}. - * Results are appended to {@code result}. - * Default implementation throws UnsupportedOperationException. - */ - protected Status legacyListDirectories(String remotePath, Set<String> result) { - throw new UnsupportedOperationException( - "listDirectories not supported by " + getClass().getSimpleName()); - } - - /** - * Creates a new output file. Subclasses must implement. - */ - protected abstract DorisOutputFile legacyNewOutputFile(ParsedPath path); - - /** Creates a new input file with optional length hint (-1 = unknown). */ - protected abstract DorisInputFile legacyNewInputFile(ParsedPath path, long length); - - // ─────────────────────────── NEW INTERFACE IMPLEMENTATIONS ─────────────────────────── - - @Override - public DorisInputFile newInputFile(Location location) { - return legacyNewInputFile(new ParsedPath(location.toString()), -1L); - } - - @Override - public DorisInputFile newInputFile(Location location, long length) { - return legacyNewInputFile(new ParsedPath(location.toString()), length); - } - - @Override - public DorisOutputFile newOutputFile(Location location) { - return legacyNewOutputFile(new ParsedPath(location.toString())); - } - - @Override - public boolean exists(Location location) throws IOException { - Status status = legacyExists(location.toString()); - if (status.ok()) { - return true; - } - if (Status.ErrCode.NOT_FOUND.equals(status.getErrCode())) { - return false; - } - throw new IOException("exists(" + location + ") failed: " + status.getErrMsg()); - } - - @Override - public void deleteFile(Location location) throws IOException { - Status status = legacyDelete(location.toString()); - if (!status.ok()) { - throw new IOException("deleteFile(" + location + ") failed: " + status.getErrMsg()); - } - } - - @Override - public void renameFile(Location source, Location target) throws IOException { - Status status = legacyRename(source.toString(), target.toString()); - if (!status.ok()) { - throw new IOException("renameFile(" + source + " -> " + target + ") failed: " - + status.getErrMsg()); - } - } - - @Override - public void deleteDirectory(Location location) throws IOException { - Status status = legacyDelete(location.toString()); - if (!status.ok()) { - throw new IOException("deleteDirectory(" + location + ") failed: " + status.getErrMsg()); - } - } - - @Override - public void createDirectory(Location location) throws IOException { - Status status = legacyMakeDir(location.toString()); - if (!status.ok()) { - throw new IOException("createDirectory(" + location + ") failed: " + status.getErrMsg()); - } - } - - @Override - public void renameDirectory(Location source, Location target) throws IOException { - Status status = legacyRename(source.toString(), target.toString()); - if (!status.ok()) { - throw new IOException("renameDirectory(" + source + " -> " + target + ") failed: " - + status.getErrMsg()); - } - } - - @Override - public FileIterator listFiles(Location location, boolean recursive) throws IOException { - List<RemoteFile> remoteFiles = new ArrayList<>(); - Status status = legacyListFiles(location.toString(), recursive, remoteFiles); - if (!status.ok()) { - throw new IOException("listFiles(" + location + ") failed: " + status.getErrMsg()); - } - String base = location.toString(); - List<FileEntry> entries = remoteFiles.stream() - .map(rf -> convertRemoteFile(rf, base)) - .collect(Collectors.toList()); - return FileIterator.ofList(entries); - } - - @Override - public Set<Location> listDirectories(Location location) throws IOException { - Set<String> dirs = new HashSet<>(); - Status status = legacyListDirectories(location.toString(), dirs); - if (!status.ok()) { - throw new IOException("listDirectories(" + location + ") failed: " + status.getErrMsg()); - } - Set<Location> result = new HashSet<>(dirs.size() * 2); - for (String dir : dirs) { - result.add(Location.of(dir)); - } - return result; - } - - // ─────────────────────────── HELPERS ─────────────────────────── - - private static FileEntry convertRemoteFile(RemoteFile rf, String baseUri) { - org.apache.hadoop.fs.Path hadoopPath = rf.getPath(); - Location loc = hadoopPath != null - ? Location.of(hadoopPath.toString()) - : Location.of(baseUri.endsWith("/") ? baseUri + rf.getName() - : baseUri + "/" + rf.getName()); - - FileEntry.Builder builder = FileEntry.builder(loc) - .directory(rf.isDirectory()) - .length(rf.getSize()) - .blockSize(rf.getBlockSize()) - .modificationTime(rf.getModificationTime()); - - if (rf.getBlockLocations() != null) { - List<FileEntry.BlockInfo> blocks = new ArrayList<>(); - for (org.apache.hadoop.fs.BlockLocation bl : rf.getBlockLocations()) { - try { - String[] hostsArr = bl.getHosts(); - List<String> hosts = hostsArr != null - ? java.util.Arrays.asList(hostsArr) - : java.util.Collections.emptyList(); - blocks.add(new FileEntry.BlockInfo(bl.getOffset(), bl.getLength(), hosts)); - } catch (IOException e) { - blocks.add(new FileEntry.BlockInfo(bl.getOffset(), bl.getLength(), - java.util.Collections.emptyList())); - } - } - builder.blocks(blocks); - } - return builder.build(); - } -} diff --git a/fe/fe-core/src/main/java/org/apache/doris/fs/LegacyToNewFsAdapter.java b/fe/fe-core/src/main/java/org/apache/doris/fs/LegacyToNewFsAdapter.java deleted file mode 100644 index cf1e7e3b540..00000000000 --- a/fe/fe-core/src/main/java/org/apache/doris/fs/LegacyToNewFsAdapter.java +++ /dev/null @@ -1,92 +0,0 @@ -// 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.doris.fs; - -import org.apache.doris.backup.Status; -import org.apache.doris.fs.io.DorisInputFile; -import org.apache.doris.fs.io.DorisOutputFile; -import org.apache.doris.fs.io.ParsedPath; -import org.apache.doris.fs.remote.RemoteFile; - -import java.io.IOException; -import java.util.List; -import java.util.Set; - -/** - * Adapts any old-style {@link LegacyFileSystemApi} implementation to the new - * {@link FileSystem} interface via {@link LegacyFileSystemAdapter}. - * <p> - * This avoids modifying existing class hierarchies in Phase 1. - * In Phase 3, when RemoteFileSystem is removed, direct subclassing of - * LegacyFileSystemAdapter will replace this adapter. - */ -public final class LegacyToNewFsAdapter extends LegacyFileSystemAdapter { - - private final LegacyFileSystemApi delegate; - - public LegacyToNewFsAdapter(LegacyFileSystemApi delegate) { - this.delegate = delegate; - } - - @Override - protected Status legacyExists(String remotePath) { - return delegate.exists(remotePath); - } - - @Override - protected Status legacyDelete(String remotePath) { - return delegate.delete(remotePath); - } - - @Override - protected Status legacyRename(String orig, String dest) { - return delegate.rename(orig, dest); - } - - @Override - protected Status legacyMakeDir(String remotePath) { - return delegate.makeDir(remotePath); - } - - @Override - protected Status legacyListFiles(String remotePath, boolean recursive, List<RemoteFile> result) { - return delegate.listFiles(remotePath, recursive, result); - } - - @Override - protected Status legacyListDirectories(String remotePath, Set<String> result) { - return delegate.listDirectories(remotePath, result); - } - - @Override - protected DorisOutputFile legacyNewOutputFile(ParsedPath path) { - return delegate.newOutputFile(path); - } - - @Override - protected DorisInputFile legacyNewInputFile(ParsedPath path, long length) { - return delegate.newInputFile(path, length); - } - - @Override - public void close() throws IOException { - if (delegate instanceof java.io.Closeable) { - ((java.io.Closeable) delegate).close(); - } - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
