hudi-agent commented on code in PR #19812:
URL: https://github.com/apache/hudi/pull/19812#discussion_r3906737830


##########
hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/ddl/HiveQueryDDLExecutor.java:
##########
@@ -318,12 +316,34 @@ public void close() {
     if (metaStoreClient != null) {
       Hive.closeCurrent();
     }
-    if (hiveDriver != null) {
-      try {
-        hiveDriver.close();
-      } finally {
-        destroyQuietly(hiveDriver);
+    try {
+      if (hiveDriver != null) {
+        try {
+          hiveDriver.close();
+        } finally {
+          destroyQuietly(hiveDriver);
+        }
       }
+    } finally {
+      closeQuietly(sessionState);
+    }
+  }
+
+  /**
+   * Closes the SessionState this executor started. Hive derives the session's 
four scratch
+   * directory roots from hive.session.id and only reclaims them in close(), 
so a HiveSyncTool that
+   * runs per commit leaves a directory set behind on every sync. Runs after 
the Driver teardown
+   * above, because close() detaches the session from this thread and {@code 
Driver.destroy()} can
+   * reach {@code SessionState.get()} while releasing locks.
+   */
+  private static void closeQuietly(SessionState sessionState) {
+    if (sessionState == null) {
+      return;
+    }
+    try {
+      sessionState.close();
+    } catch (Exception e) {
+      log.error("Error while closing SessionState", e);
     }
   }

Review Comment:
   🤖 nit: could you rename the parameter to avoid the same name as the instance 
field? Something like `state` would make it immediately clear this is a static 
helper and not accidentally referencing the field.
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



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