danny0405 commented on code in PR #19812:
URL: https://github.com/apache/hudi/pull/19812#discussion_r3910567788
##########
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 {
Review Comment:
[P1] Bind the owned session during Driver teardown
`Driver.close()` and `destroy()` consult `SessionState.get()`—the former
clears the current session’s lineage state, and the latter can obtain its
transaction manager when releasing locks. If executor B was constructed or run
after executor A, calling `A.close()` here tears down A’s Driver while B’s
session is current, potentially clearing or operating on B’s state;
`A.sessionState.close()` then also detaches B. Capture the previous session,
bind `sessionState` before Driver/session teardown, and restore the previous
session afterward.
##########
hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/ddl/HiveQueryDDLExecutor.java:
##########
@@ -176,6 +169,11 @@ private List<CommandProcessorResponse>
updateHiveSQLs(List<String> sqls) {
List<CommandProcessorResponse> responses = new ArrayList<>();
HoodieTimer timer = HoodieTimer.start();
try {
+ // Driver.compile() resolves its session from a thread local that every
executor on this
+ // thread writes: the one constructed most recently wins, and one that
is closed clears it.
+ // Re-assert ours, as Hive documents a thread running several sessions
must, so these
+ // statements run under the session that owns hiveDriver.
+ SessionState.setCurrentSessionState(sessionState);
Review Comment:
[P2] Restore the previous thread-local session
This assignment remains in the thread local after `updateHiveSQLs` returns.
With interleaved executors—or an embedding application that already owns a Hive
session—subsequent Hive work silently runs under this executor’s database,
configuration, and transaction state. Make the binding scoped: save
`SessionState.get()`, bind this executor for the Driver calls, then restore the
saved session (or detach when it was null) in a `finally` block.
--
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]