mchades commented on code in PR #14407:
URL: https://github.com/apache/gravitino/pull/14407#discussion_r4608820729


##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1481,17 +1509,82 @@ FileSystem getFileSystemWithCache(Path path, 
Map<String, String> conf) {
     FileSystemProvider provider = fileSystemProvidersMap.get(scheme);
     String authority =
         provider != null ? provider.getFullAuthority(path, conf) : 
path.toUri().getAuthority();
+    // Only an HDFS file system logs in with the settings of the 
configuration, see
+    // createFileSystem.
+    String fsScheme = scheme != null ? scheme : 
defaultFileSystemProvider.scheme();
+    if (!SCHEME_HDFS.equals(fsScheme)) {
+      return fileSystemCache.get(
+          new FileSystemCacheKey(scheme, authority, Collections.emptyMap()),
+          cacheKey -> newFileSystem(path, conf, cacheKey, null));
+    }
+
+    Map<String, String> hdfsConf = Collections.unmodifiableMap(new 
HashMap<>(conf));
+    FileSystem fs = getHdfsFileSystemWithCache(path, hdfsConf, scheme, 
authority);
+    if (fs == null) {
+      // The config.resources files changed after their login settings were 
cached.
+      hdfsLoginSettingsCache.invalidate(hdfsConf);
+      fs = getHdfsFileSystemWithCache(path, hdfsConf, scheme, authority);
+    }
+    if (fs == null) {
+      throw new GravitinoRuntimeException(
+          "The login settings in config.resources changed while getting 
FileSystem for fileset:"
+              + " path: %s",
+          path);
+    }
+    return fs;
+  }
+
+  // Returns null if the config.resources files no longer resolve to the 
cached login settings: a
+  // file system is cached only under the settings of the configuration it is 
created with.
+  @Nullable
+  private FileSystem getHdfsFileSystemWithCache(
+      Path path, Map<String, String> conf, @Nullable String scheme, @Nullable 
String authority) {
+    Map<String, String> settings =
+        hdfsLoginSettingsCache.get(conf, c -> loginSettings(path, c, 
hdfsConfiguration(path, c)));

Review Comment:
   **[P2] Apply the connection timeout to initial login settings resolution**
   
   On a settings-cache miss, this reads `config.resources` on the request 
thread before `filesystem-conn-timeout-secs` starts. With a 1-second timeout 
and a simulated 1.5-second delay in configuration loading, the lookup still 
succeeded after 1.58 seconds. Could we run the initial resolution under the 
connection timeout? This is the remaining cache-miss case from [the earlier 
discussion](https://github.com/apache/gravitino/pull/14407#discussion_r4572881788).



##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1481,17 +1509,82 @@ FileSystem getFileSystemWithCache(Path path, 
Map<String, String> conf) {
     FileSystemProvider provider = fileSystemProvidersMap.get(scheme);
     String authority =
         provider != null ? provider.getFullAuthority(path, conf) : 
path.toUri().getAuthority();
+    // Only an HDFS file system logs in with the settings of the 
configuration, see
+    // createFileSystem.
+    String fsScheme = scheme != null ? scheme : 
defaultFileSystemProvider.scheme();
+    if (!SCHEME_HDFS.equals(fsScheme)) {
+      return fileSystemCache.get(
+          new FileSystemCacheKey(scheme, authority, Collections.emptyMap()),
+          cacheKey -> newFileSystem(path, conf, cacheKey, null));
+    }
+
+    Map<String, String> hdfsConf = Collections.unmodifiableMap(new 
HashMap<>(conf));

Review Comment:
   **[P2] Share login settings across filesets with equivalent configuration**
   
   The merged map contains a unique `gravitino.identifier` for each fileset, so 
filesets inheriting the same Kerberos configuration still compete for the 1,000 
settings-cache entries. After warming 5,000 such filesets in a local test, 
2,426 of 3,000 random lookups parsed XML again while all reused one 
`FileSystem`. Could we share the parsed settings when the inputs to login 
resolution are equivalent, while preserving Hadoop variable expansion?



##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -352,7 +367,18 @@ public void initialize(
       this.fileSystemCache = cacheBuilder.build();
     }
 
-    this.catalogStorageLocations = getAndCheckCatalogStorageLocations(config);
+    try {
+      this.catalogStorageLocations = 
getAndCheckCatalogStorageLocations(config);
+    } catch (RuntimeException | Error e) {
+      // A catalog keeps no operations whose initialization failed, so nothing 
else closes the file
+      // systems created to check the locations.
+      try {
+        close();

Review Comment:
   **[P2] Keep closing cached file systems when one close fails**
   
   This catch preserves the initialization error, but `close()` only catches 
`IOException` inside its loop. In a local test with two already-open clients, 
the first `close()` threw `IllegalStateException`, and the other client was 
never closed. Could we handle runtime exceptions per client so initialization 
cleanup attempts to close every cached file system?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to