Skip to content

Commit 69dd91f

Browse files
committed
Cache Hadoop Filesystem instance on Gravitino server to improve the performance
1 parent 7f5085d commit 69dd91f

File tree

8 files changed

+24
-7
lines changed

8 files changed

+24
-7
lines changed

bundles/aliyun/src/main/java/org/apache/gravitino/oss/fs/OSSFileSystemProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
6767

6868
hadoopConfMap.forEach(configuration::set);
6969

70-
return AliyunOSSFileSystem.newInstance(path.toUri(), configuration);
70+
return AliyunOSSFileSystem.get(path.toUri(), configuration);
7171
}
7272

7373
@Override

bundles/aws/src/main/java/org/apache/gravitino/s3/fs/S3FileSystemProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
7474
// Hadoop-aws 2 does not support IAMInstanceCredentialsProvider
7575
checkAndSetCredentialProvider(configuration);
7676

77-
return S3AFileSystem.newInstance(path.toUri(), configuration);
77+
return S3AFileSystem.get(path.toUri(), configuration);
7878
}
7979

8080
@Override

bundles/azure/src/main/java/org/apache/gravitino/abs/fs/AzureFileSystemProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public FileSystem getFileSystem(@Nonnull Path path, @Nonnull Map<String, String>
7474

7575
hadoopConfMap.forEach(configuration::set);
7676

77-
return FileSystem.newInstance(path.toUri(), configuration);
77+
return FileSystem.get(path.toUri(), configuration);
7878
}
7979

8080
@Override

bundles/gcp/src/main/java/org/apache/gravitino/gcs/fs/GCSFileSystemProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
4949
FileSystemUtils.toHadoopConfigMap(config, GRAVITINO_KEY_TO_GCS_HADOOP_KEY)
5050
.forEach(configuration::set);
5151

52-
return FileSystem.newInstance(path.toUri(), configuration);
52+
return FileSystem.get(path.toUri(), configuration);
5353
}
5454

5555
@Override

catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/FileSystemProvider.java

+17
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ public interface FileSystemProvider {
6565
FileSystem getFileSystem(@Nonnull Path path, @Nonnull Map<String, String> config)
6666
throws IOException;
6767

68+
/**
69+
* Get the FileSystem instance according to the configuration map and file path.
70+
*
71+
* @param config The configuration for the FileSystem instance.
72+
* @param path The path to the file system.
73+
* @param disableCache Whether to cache the FileSystem instance.
74+
* @return The FileSystem instance.
75+
* @throws IOException If the FileSystem instance cannot be created.
76+
*/
77+
default FileSystem getFileSystem(
78+
@Nonnull Path path, @Nonnull Map<String, String> config, boolean disableCache)
79+
throws IOException {
80+
// disable cache
81+
config.put(String.format("fs.%s.impl.disable.cache", scheme()), String.valueOf(disableCache));
82+
return getFileSystem(path, config);
83+
}
84+
6885
/**
6986
* Scheme of this FileSystem provider. The value is 'file' for LocalFileSystem, 'hdfs' for HDFS,
7087
* etc.

catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public FileSystem getFileSystem(@Nonnull Path path, @Nonnull Map<String, String>
3737
(k, v) -> {
3838
configuration.set(k.replace(GRAVITINO_BYPASS, ""), v);
3939
});
40-
return FileSystem.newInstance(path.toUri(), configuration);
40+
return FileSystem.get(path.toUri(), configuration);
4141
}
4242

4343
@Override

catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/LocalFileSystemProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
3737
configuration.set(k.replace(BUILTIN_HDFS_FS_PROVIDER, ""), v);
3838
});
3939

40-
return FileSystem.newInstance(path.toUri(), configuration);
40+
return FileSystem.get(path.toUri(), configuration);
4141
}
4242

4343
@Override

clients/filesystem-hadoop3/src/main/java/org/apache/gravitino/filesystem/hadoop/GravitinoVirtualFileSystem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private FilesetContextPair getFilesetContext(Path virtualPath, FilesetDataOperat
319319

320320
totalProperty.putAll(getCredentialProperties(provider, catalog, identifier));
321321

322-
return provider.getFileSystem(filePath, totalProperty);
322+
return provider.getFileSystem(filePath, totalProperty, true);
323323
} catch (IOException ioe) {
324324
throw new GravitinoRuntimeException(
325325
ioe,

0 commit comments

Comments
 (0)