diff --git a/fe/fe-core/src/main/java/org/apache/doris/fs/remote/RemoteFileSystem.java b/fe/fe-core/src/main/java/org/apache/doris/fs/remote/RemoteFileSystem.java index cefa97a78db6401..045b48573c858a4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/fs/remote/RemoteFileSystem.java +++ b/fe/fe-core/src/main/java/org/apache/doris/fs/remote/RemoteFileSystem.java @@ -36,11 +36,14 @@ import java.util.Arrays; import java.util.List; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; public abstract class RemoteFileSystem extends PersistentFileSystem implements Closeable { // this field will be visited by multi-threads, better use volatile qualifier protected volatile org.apache.hadoop.fs.FileSystem dfsFileSystem = null; + protected static final AtomicBoolean closed = new AtomicBoolean(false); + public RemoteFileSystem(String name, StorageBackend.StorageType type) { super(name, type); } @@ -123,7 +126,11 @@ public Status renameDir(String origFilePath, } @Override - public void close() throws IOException { + public synchronized void close() throws IOException { + if (closed.getAndSet(true)) { + return; + } + closed.set(true); if (dfsFileSystem != null) { dfsFileSystem.close(); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/fs/remote/dfs/DFSFileSystem.java b/fe/fe-core/src/main/java/org/apache/doris/fs/remote/dfs/DFSFileSystem.java index 59fbd73bda78cf1..de31dc40d508ad5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/fs/remote/dfs/DFSFileSystem.java +++ b/fe/fe-core/src/main/java/org/apache/doris/fs/remote/dfs/DFSFileSystem.java @@ -75,8 +75,14 @@ public DFSFileSystem(StorageBackend.StorageType type, Map proper @VisibleForTesting @Override public FileSystem nativeFileSystem(String remotePath) throws UserException { + if (closed.get()) { + throw new UserException("FileSystem is closed."); + } if (dfsFileSystem == null) { synchronized (this) { + if (closed.get()) { + throw new UserException("FileSystem is closed."); + } if (dfsFileSystem == null) { Configuration conf = getHdfsConf(ifNotSetFallbackToSimpleAuth()); for (Map.Entry propEntry : properties.entrySet()) {