Skip to content

Commit

Permalink
add closed flag
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinKirs committed Jul 31, 2024
1 parent 44b6719 commit 2a4fafb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ public DFSFileSystem(StorageBackend.StorageType type, Map<String, String> 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<String, String> propEntry : properties.entrySet()) {
Expand Down

0 comments on commit 2a4fafb

Please sign in to comment.