Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,7 @@ public void run() {
@Override
public Object run() throws HiveSQLException {
assert (!parentHive.allowClose());
try {
Hive.set(parentSessionState.getHiveDb());
} catch (HiveException e) {
throw new HiveSQLException(e);
}
Hive.set(parentHive);
// TODO: can this result in cross-thread reuse of session state?
SessionState.setCurrentSessionState(parentSessionState);
PerfLogger.setPerfLogger(SessionState.getPerfLogger());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ private synchronized void acquireAfterOpLock(boolean userAccess) {
// set the thread name with the logging prefix.
sessionState.updateThreadName();

try {
setSessionHive();
} catch (HiveSQLException e) {
throw new RuntimeException(e);
}
// If Hive.get() is being shared across different sessions,
// SessionState#getHiveDb() and Hive.get() may be different, in such case,
// the risk of deadlock on HiveMetaStoreClient#SynchronizedHandler can happen.
// Refresh the thread-local Hive to avoid the problem.
Hive.set(sessionHive);
}

/**
Expand All @@ -432,6 +432,14 @@ private synchronized void releaseBeforeOpLock(boolean userAccess) {
sessionState.resetThreadName();
}

// We have already set the thread-local Hive belonging to the current session,
// if the thread-local Hive has been changed after running the operation,
// the Hive after should belong to the same session, and we should update the sessionHive.
// The thread-local hive would be closed and recreated only when the underlying
// HiveMetaStoreClient is incompatible with the newest session conf.
if (Hive.getThreadLocal() != null && Hive.getThreadLocal() != sessionHive) {
sessionHive = Hive.getThreadLocal();
}
SessionState.detachSession();
if (ThreadWithGarbageCleanup.currentThread() instanceof ThreadWithGarbageCleanup) {
ThreadWithGarbageCleanup currentThread =
Expand Down