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


##########
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:
   Done. On a settings-cache miss, the settings are now resolved by a task on a 
small pool of their own, under `filesystem-conn-timeout-secs`, so they do not 
wait behind hanging logins. Resolving the settings and creating the file system 
share one deadline, which the retry after `config.resources` changed also uses. 
`testFileSystemCacheResolvesLoginSettingsUnderTheConnectionTimeout` makes the 
resolution hang and checks that the lookup fails on the settings step. 
`testFileSystemCacheGivesALookupOneConnectionTimeout` uses a 2-second timeout, 
takes 1 second for the settings and 1.5 for the file system, and checks that 
the creation times out. 
`testFileSystemCacheFindsCachedFileSystemWhileCreationsHang` holds every 
creation thread and checks that a lookup whose settings expired still finds its 
cached file system.
   



##########
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:
   Done. Settings that expand no Hadoop variable are now cached by the merged 
configuration without `gravitino.identifier`, so filesets whose configurations 
differ only in that identifier share one entry. If one of the Hadoop properties 
these settings come from (`hadoop.security.authentication`, the principal, the 
keytab or `hadoop.security.authentication.kerberos.krb5.conf`) contains `${`, 
the settings may depend on the identifier and are cached per configuration. 
That includes a `hadoop.security.authentication` variable that Gravitino 
normalizes to `kerberos`. 
`testFileSystemCacheSharesLoginSettingsAcrossFilesets` checks that a second 
fileset resolves nothing. 
`testFileSystemCacheResolvesLoginSettingsOfEachFilesetThatExpandsVariables` 
checks that with `svc-${gravitino.identifier}@EXAMPLE.COM` the second fileset 
gets its own file system, created with principal `[email protected]`, and 
`testLoginSettingsExpandVariablesWhereverTheirPropertiesComeFrom` covers each 
of these properties a
 nd a variable in a `config.resources` file.
   



##########
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:
   Done. `close()` now also catches runtime exceptions from each cached file 
system, logs them and goes on with the others, so a close that throws an 
exception no longer leaves the rest open. 
`testFailedInitializeClosesEveryFileSystemWhenClosingOneFails` makes the first 
close of both file systems throw and checks that both are closed.
   



-- 
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