Skip to content

Commit

Permalink
Cache Hadoop Filesystem instance on Gravitino server to improve the p…
Browse files Browse the repository at this point in the history
…erformance
  • Loading branch information
sunxiaojian committed Mar 6, 2025
1 parent 7f5085d commit 69dd91f
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO

hadoopConfMap.forEach(configuration::set);

return AliyunOSSFileSystem.newInstance(path.toUri(), configuration);
return AliyunOSSFileSystem.get(path.toUri(), configuration);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
// Hadoop-aws 2 does not support IAMInstanceCredentialsProvider
checkAndSetCredentialProvider(configuration);

return S3AFileSystem.newInstance(path.toUri(), configuration);
return S3AFileSystem.get(path.toUri(), configuration);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public FileSystem getFileSystem(@Nonnull Path path, @Nonnull Map<String, String>

hadoopConfMap.forEach(configuration::set);

return FileSystem.newInstance(path.toUri(), configuration);
return FileSystem.get(path.toUri(), configuration);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
FileSystemUtils.toHadoopConfigMap(config, GRAVITINO_KEY_TO_GCS_HADOOP_KEY)
.forEach(configuration::set);

return FileSystem.newInstance(path.toUri(), configuration);
return FileSystem.get(path.toUri(), configuration);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ public interface FileSystemProvider {
FileSystem getFileSystem(@Nonnull Path path, @Nonnull Map<String, String> config)
throws IOException;

/**
* Get the FileSystem instance according to the configuration map and file path.
*
* @param config The configuration for the FileSystem instance.
* @param path The path to the file system.
* @param disableCache Whether to cache the FileSystem instance.
* @return The FileSystem instance.
* @throws IOException If the FileSystem instance cannot be created.
*/
default FileSystem getFileSystem(
@Nonnull Path path, @Nonnull Map<String, String> config, boolean disableCache)
throws IOException {
// disable cache
config.put(String.format("fs.%s.impl.disable.cache", scheme()), String.valueOf(disableCache));
return getFileSystem(path, config);
}

/**
* Scheme of this FileSystem provider. The value is 'file' for LocalFileSystem, 'hdfs' for HDFS,
* etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public FileSystem getFileSystem(@Nonnull Path path, @Nonnull Map<String, String>
(k, v) -> {
configuration.set(k.replace(GRAVITINO_BYPASS, ""), v);
});
return FileSystem.newInstance(path.toUri(), configuration);
return FileSystem.get(path.toUri(), configuration);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
configuration.set(k.replace(BUILTIN_HDFS_FS_PROVIDER, ""), v);
});

return FileSystem.newInstance(path.toUri(), configuration);
return FileSystem.get(path.toUri(), configuration);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ private FilesetContextPair getFilesetContext(Path virtualPath, FilesetDataOperat

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

return provider.getFileSystem(filePath, totalProperty);
return provider.getFileSystem(filePath, totalProperty, true);
} catch (IOException ioe) {
throw new GravitinoRuntimeException(
ioe,
Expand Down

0 comments on commit 69dd91f

Please sign in to comment.