Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi committed Dec 13, 2023
1 parent 0b59d1e commit 98380ff
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.apache.hadoop.fs.FileSystem;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* Hadoop {@link FileIO}.
Expand All @@ -39,7 +41,7 @@ public abstract class HadoopCompliantFileIO implements FileIO {

private static final long serialVersionUID = 1L;

protected transient volatile FileSystem fs;
protected transient volatile Map<String, FileSystem> fsMap;

@Override
public SeekableInputStream newInputStream(Path path) throws IOException {
Expand Down Expand Up @@ -105,13 +107,25 @@ private org.apache.hadoop.fs.Path path(Path path) {
}

private FileSystem getFileSystem(org.apache.hadoop.fs.Path path) throws IOException {
if (fs == null) {
if (fsMap == null) {
synchronized (this) {
if (fs == null) {
fs = createFileSystem(path);
if (fsMap == null) {
fsMap = new ConcurrentHashMap<>();
}
}
}

Map<String, FileSystem> map = fsMap;

String authority = path.toUri().getAuthority();
if (authority == null) {
authority = "DEFAULT";
}
FileSystem fs = map.get(authority);
if (fs == null) {
fs = createFileSystem(path);
map.put(authority, fs);
}
return fs;
}

Expand Down

0 comments on commit 98380ff

Please sign in to comment.