jerryshao commented on code in PR #14407:
URL: https://github.com/apache/gravitino/pull/14407#discussion_r4585207443
##########
catalogs/hadoop-common/src/main/java/org/apache/gravitino/catalog/hadoop/fs/HDFSFileSystemProxy.java:
##########
@@ -182,6 +246,83 @@ private synchronized void close() {
}
kerberosClient = null;
}
+ if (keytabFile != null) {
+ try {
+ Files.deleteIfExists(keytabFile.toPath());
+ LIVE_KEYTAB_FILES.remove(keytabFile);
+ } 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.
+ try {
+ keytabFile.deleteOnExit();
+ } catch (RuntimeException ex) {
+ LOG.warn("Failed to delete the keytab file {} on exit", keytabFile,
ex);
+ }
+ }
+ keytabFile = null;
+ }
+ }
+
+ private synchronized void recordKeytabFile(File file) {
+ if (keytabFile != null) {
+ LIVE_KEYTAB_FILES.remove(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) {
+ LOG.warn("The JVM is shutting down, {} is not deleted on exit",
file);
+ }
+ }
+ }
+ LIVE_KEYTAB_FILES.add(file);
Review Comment:
[P2] If another shutdown hook opens a Kerberos fileset after this cleaner
has run, the new keytab goes into `LIVE_KEYTAB_FILES` with nobody left to
process it. On first use during shutdown, `addShutdownHook()` fails and
produces the same result. Could you coordinate registration with the cleaner so
that once shutdown cleanup starts, new paths go directly to
`File.deleteOnExit()`? The failed `addShutdownHook()` branch can use that
fallback too. A regression that records a second proxy’s keytab after running
the cleaner would cover the missed handoff.
--
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]