LuciferYang commented on code in PR #14407:
URL: https://github.com/apache/gravitino/pull/14407#discussion_r4572881672
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -223,18 +231,52 @@ static class FileSystemCacheKey {
* When the path is a path without scheme such as 'file','hdfs', etc.,
then the scheme and
* authority are both null
*
- * <p>NOTE: The filesystem cache key includes the schema, authority, and
current user. Changes
- * to the configuration of the fileset will not affect the cached
filesystem.
+ * <p>NOTE: The filesystem cache key includes the scheme, authority,
current user and the
+ * authentication settings of the configuration. Changes to other
configuration of the fileset
+ * will not affect the cached filesystem.
*/
@Nullable private final String scheme;
@Nullable private final String authority;
private final String currentUser;
+ private final Map<String, String> authenticationSettings;
- FileSystemCacheKey(String scheme, String authority) {
+ FileSystemCacheKey(String scheme, String authority, Map<String, String>
conf) {
this.scheme = scheme;
this.authority = authority;
this.currentUser = PrincipalUtils.getCurrentUserName();
+ this.authenticationSettings = resolveAuthenticationSettings(conf);
+ }
+
+ /**
+ * Resolves the settings that decide how an HDFS file system logs in from
the Hadoop
+ * configuration that {@code HDFSFileSystemProxy} builds, so that values
from {@code
+ * config.resources} files and variable expansion count. The authority
carries the principal
+ * only without its realm, and a location without a scheme has no
authority at all.
+ */
+ private static Map<String, String>
resolveAuthenticationSettings(Map<String, String> conf) {
+ Configuration configuration =
+ FileSystemUtils.createCompatibleConfiguration(
+ GRAVITINO_BYPASS, additionalHDFSConfig(conf));
+ AuthenticationConfig authenticationConfig = new
AuthenticationConfig(conf, configuration);
+ Map<String, String> settings = new HashMap<>();
+ settings.put(AuthenticationConfig.AUTH_TYPE_KEY,
authenticationConfig.getAuthType());
+ settings.put(
+ AuthenticationConfig.IMPERSONATION_ENABLE_KEY,
+ String.valueOf(authenticationConfig.isImpersonationEnabled()));
+ // A catalog, schema or fileset property overrides the Hadoop value, as
in KerberosConfig.
+ settings.put(
+ KerberosConfig.PRINCIPAL_KEY,
+ conf.getOrDefault(
+ KerberosConfig.PRINCIPAL_KEY,
configuration.get(HADOOP_SECURITY_PRINCIPAL, "")));
Review Comment:
Reproduced. The proxy now builds its Hadoop configuration in one place,
`HDFSFileSystemProxy.hadoopConfiguration`, which switches
`hadoop.security.authentication` to `kerberos` before anything reads the
principal. The cache key takes its values from
`HDFSFileSystemProxy.loginSettings`, which reads that same configuration.
`testFileSystemCacheResolvesPrincipalWithKerberosAuthentication` covers your
pair. `testLoginSettingsHoldWhatTheProxyLogsInWith` checks that the principal,
keytab URI and krb5.conf in the settings are the ones the proxy fetches and
logs in with.
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -223,18 +231,52 @@ static class FileSystemCacheKey {
* When the path is a path without scheme such as 'file','hdfs', etc.,
then the scheme and
* authority are both null
*
- * <p>NOTE: The filesystem cache key includes the schema, authority, and
current user. Changes
- * to the configuration of the fileset will not affect the cached
filesystem.
+ * <p>NOTE: The filesystem cache key includes the scheme, authority,
current user and the
+ * authentication settings of the configuration. Changes to other
configuration of the fileset
+ * will not affect the cached filesystem.
*/
@Nullable private final String scheme;
@Nullable private final String authority;
private final String currentUser;
+ private final Map<String, String> authenticationSettings;
- FileSystemCacheKey(String scheme, String authority) {
+ FileSystemCacheKey(String scheme, String authority, Map<String, String>
conf) {
this.scheme = scheme;
this.authority = authority;
this.currentUser = PrincipalUtils.getCurrentUserName();
+ this.authenticationSettings = resolveAuthenticationSettings(conf);
+ }
+
+ /**
+ * Resolves the settings that decide how an HDFS file system logs in from
the Hadoop
+ * configuration that {@code HDFSFileSystemProxy} builds, so that values
from {@code
+ * config.resources} files and variable expansion count. The authority
carries the principal
+ * only without its realm, and a location without a scheme has no
authority at all.
+ */
+ private static Map<String, String>
resolveAuthenticationSettings(Map<String, String> conf) {
+ Configuration configuration =
+ FileSystemUtils.createCompatibleConfiguration(
Review Comment:
Done. Non-HDFS paths get an empty settings map, so their key is scheme,
authority and user, as on main. For HDFS, the resolved settings are cached per
merged configuration (`maximumSize(1000)`, `expireAfterWrite(1h)`), so a
repeated lookup with the same configuration parses no XML, which
`testFileSystemCacheResolvesLoginSettingsOncePerConfiguration` checks. On a
miss, the lookup still reads `config.resources` outside the connection timeout.
Hadoop opens these resources with `java.io.File`, so it is a local read, and it
happens about once per configuration per hour, more often when a catalog has
more than 1000 active configurations or the file fails to parse. A side effect
is that a malformed resource file now fails the lookup whenever the settings
are resolved, even when a matching file system is cached.
--
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]