Skip to content

Commit 9b7d19b

Browse files
committed
Cache Hadoop Filesystem instance on Gravitino server to improve the performance
1 parent 38ffa85 commit 9b7d19b

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
@@ -65,7 +65,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
6565

6666
Configuration configuration = FileSystemUtils.createConfiguration(hadoopConfMap);
6767

68-
return AliyunOSSFileSystem.newInstance(path.toUri(), configuration);
68+
return AliyunOSSFileSystem.get(path.toUri(), configuration);
6969
}
7070

7171
@Override

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
7373
checkAndSetCredentialProvider(hadoopConfMap);
7474

7575
Configuration configuration = FileSystemUtils.createConfiguration(hadoopConfMap);
76-
return S3AFileSystem.newInstance(path.toUri(), configuration);
76+
return S3AFileSystem.get(path.toUri(), configuration);
7777
}
7878

7979
@Override

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public FileSystem getFileSystem(@Nonnull Path path, @Nonnull Map<String, String>
7272
}
7373

7474
Configuration configuration = FileSystemUtils.createConfiguration(hadoopConfMap);
75-
return FileSystem.newInstance(path.toUri(), configuration);
75+
return FileSystem.get(path.toUri(), configuration);
7676
}
7777

7878
@Override

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
4848
Map<String, String> hadoopConfMap =
4949
FileSystemUtils.toHadoopConfigMap(config, GRAVITINO_KEY_TO_GCS_HADOOP_KEY);
5050
Configuration configuration = FileSystemUtils.createConfiguration(hadoopConfMap);
51-
return FileSystem.newInstance(path.toUri(), configuration);
51+
return FileSystem.get(path.toUri(), configuration);
5252
}
5353

5454
@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
@@ -33,7 +33,7 @@ public class HDFSFileSystemProvider implements FileSystemProvider {
3333
public FileSystem getFileSystem(@Nonnull Path path, @Nonnull Map<String, String> config)
3434
throws IOException {
3535
Configuration configuration = FileSystemUtils.createConfiguration(GRAVITINO_BYPASS, config);
36-
return FileSystem.newInstance(path.toUri(), configuration);
36+
return FileSystem.get(path.toUri(), configuration);
3737
}
3838

3939
@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
@@ -33,7 +33,7 @@ public class LocalFileSystemProvider implements FileSystemProvider {
3333
public FileSystem getFileSystem(Path path, Map<String, String> config) throws IOException {
3434
Configuration configuration =
3535
FileSystemUtils.createConfiguration(BUILTIN_HDFS_FS_PROVIDER, config);
36-
return FileSystem.newInstance(path.toUri(), configuration);
36+
return FileSystem.get(path.toUri(), configuration);
3737
}
3838

3939
@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)