-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-19084][sql] Ensure context class loader is set when initializing Hive. #17154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,16 +268,19 @@ private[hive] class HiveClientImpl( | |
| */ | ||
| def withHiveState[A](f: => A): A = retryLocked { | ||
| val original = Thread.currentThread().getContextClassLoader | ||
| // Set the thread local metastore client to the client associated with this HiveClientImpl. | ||
| Hive.set(client) | ||
| val originalConfLoader = state.getConf.getClassLoader | ||
| // The classloader in clientLoader could be changed after addJar, always use the latest | ||
| // classloader | ||
| Thread.currentThread().setContextClassLoader(clientLoader.classLoader) | ||
| state.getConf.setClassLoader(clientLoader.classLoader) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like we fixed 2 problems here: 1. set thread context class loader. 2. set class loader back for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes; I'm not sure the second one is strictly necessary, but from a cleanliness p.o.v. it looks like the right thing to do. |
||
| // Set the thread local metastore client to the client associated with this HiveClientImpl. | ||
| Hive.set(client) | ||
| // setCurrentSessionState will use the classLoader associated | ||
| // with the HiveConf in `state` to override the context class loader of the current | ||
| // thread. | ||
| shim.setCurrentSessionState(state) | ||
| val ret = try f finally { | ||
| state.getConf.setClassLoader(originalConfLoader) | ||
| Thread.currentThread().setContextClassLoader(original) | ||
| HiveCatalogMetrics.incrementHiveClientCalls(1) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we add some comments to say why we need to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.