jerryshao commented on code in PR #14407:
URL: https://github.com/apache/gravitino/pull/14407#discussion_r4665166876
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -198,6 +224,26 @@ public class FilesetCatalogOperations extends
ManagedSchemaOperations
}
};
+ // A pool of its own, so that resolving login settings, which only reads
files, does not wait
+ // behind file system creations and logins that may hang.
+ @VisibleForTesting
+ final ThreadPoolExecutor loginSettingsExecutor =
+ new ThreadPoolExecutor(
+ Math.max(2, Math.min(Runtime.getRuntime().availableProcessors(), 4)),
+ Math.max(2, Math.min(Runtime.getRuntime().availableProcessors(), 4)),
+ 5L,
+ TimeUnit.SECONDS,
+ new ArrayBlockingQueue<>(100),
Review Comment:
With 2-4 threads, a queue of 100 and AbortPolicy, a burst of cold-cache HDFS
lookups (for example after a restart, or with per-fileset variable expansion)
now fails with 'Failed to start resolving the login settings' instead of
waiting. Consider a larger queue, or running the resolution in the caller when
the pool rejects it, since the caller's deadline already bounds the wait.
##########
catalogs/catalog-fileset/src/main/java/org/apache/gravitino/catalog/fileset/FilesetCatalogOperations.java:
##########
@@ -1481,17 +1691,188 @@ FileSystem getFileSystemWithCache(Path path,
Map<String, String> conf) {
FileSystemProvider provider = fileSystemProvidersMap.get(scheme);
String authority =
provider != null ? provider.getFullAuthority(path, conf) :
path.toUri().getAuthority();
- return fileSystemCache.get(
- new FileSystemCacheKey(scheme, authority),
- cacheKey -> {
- try {
+ // Resolving the settings and creating the file system share one
connection timeout.
+ long deadlineNanos =
+ System.nanoTime() +
TimeUnit.SECONDS.toNanos(connectionTimeoutSeconds(conf));
+ // 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 cachedFileSystem(
+ path,
+ conf,
+ new FileSystemCacheKey(scheme, authority, Collections.emptyMap()),
+ null,
+ deadlineNanos);
+ }
+
+ Map<String, String> hdfsConf = Collections.unmodifiableMap(new
HashMap<>(conf));
Review Comment:
Every HDFS getFileSystemWithCache call, cache hits included, now copies the
full conf map, copies it again in withoutIdentifier, and hashes both copies to
look up the settings caches. Consider caching the settings per fileset or
catalog conf object, or skipping the copies when the map is already immutable,
so this hot path stays cheap.
##########
catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProxy.java:
##########
@@ -182,6 +340,108 @@ private synchronized void close() {
}
kerberosClient = null;
}
+ if (keytabFile != null) {
+ try {
+ Files.deleteIfExists(keytabFile.toPath());
+ LIVE_KEYTAB_FILES.remove(keytabFile);
+ releaseKeytabSlot();
+ } catch (IOException | RuntimeException e) {
+ LOG.warn("Failed to delete the keytab file {}", keytabFile, e);
+ // Deleted at exit instead. The shutdown hook would hand it over too,
but a catalog class
+ // loader removes that hook when it is closed. Only failed deletes get
here.
+ deleteOnExit(keytabFile);
+ // Its name stays taken while the file may still be there.
+ keytabSlotPrefix = null;
+ }
+ keytabFile = null;
+ }
+ }
+
+ private synchronized void recordKeytabFile(File file) {
+ File previous = keytabFile;
+ keytabFile = file;
+ if (KEYTAB_CLEANER.get() == null) {
+ Thread cleaner =
+ new Thread(HDFSFileSystemProxy::deleteLiveKeytabFilesOnExit,
"gravitino-keytab-cleaner");
+ // A catalog class loader removes, when it is closed, the hooks whose
context class loader is
+ // its own.
+
cleaner.setContextClassLoader(HDFSFileSystemProxy.class.getClassLoader());
+ if (KEYTAB_CLEANER.compareAndSet(null, cleaner)) {
+ try {
+ Runtime.getRuntime().addShutdownHook(cleaner);
+ } catch (IllegalStateException e) {
+ // The JVM is shutting down, so no hook will hand the files over.
+ deleteLiveKeytabFilesOnExit();
+ }
+ }
+ }
+ // The hook sets the flag and goes through the set under the same
LIVE_KEYTAB_FILES lock, so
+ // either the hook sees the file or this method sees the flag.
+ synchronized (LIVE_KEYTAB_FILES) {
+ if (previous != null) {
+ LIVE_KEYTAB_FILES.remove(previous);
+ }
+ LIVE_KEYTAB_FILES.add(file);
+ if (keytabFilesHandedOver) {
+ deleteOnExit(file);
+ }
+ }
+ }
+
+ // Takes the lowest free name for the identifier, the keytab URI and its
content, and moves the
+ // fetched file there. See KeytabNames for when a name is reused.
+ private synchronized File moveToKeytabName(String identifier, String
keytabUri, File fetched)
Review Comment:
Per-proxy keytab files, KeytabNames slot reuse and the shutdown-hook cleaner
go beyond fixing the cache key and add a lot of new concurrency and lifecycle
code. Could this part, and the TimedTask/AsyncCache rewrite, go into separate
PRs so each can be reviewed on its own?
--
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]