Skip to content
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

[SPARK-11000][YARN]Load metadata.Hive class only when hive.metastore.uris was set to avoid bootting the database twice #9026

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
21 changes: 17 additions & 4 deletions yarn/src/main/scala/org/apache/spark/deploy/yarn/Client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1272,11 +1272,24 @@ object Client extends Logging {
val mirror = universe.runtimeMirror(getClass.getClassLoader)

try {
val hiveClass = mirror.classLoader.loadClass("org.apache.hadoop.hive.ql.metadata.Hive")
val hive = hiveClass.getMethod("get").invoke(null)

val hiveConf = hiveClass.getMethod("getConf").invoke(hive)
val hiveConfClass = mirror.classLoader.loadClass("org.apache.hadoop.hive.conf.HiveConf")
val hiveConf = hiveConfClass.newInstance()

// Set metastore to be a local temp directory to avoid conflict of the `metaStore client`
// in `HiveContext` which will use the same derby dataBase by default.
val hiveConfSet = (param: String, value: String) => hiveConfClass
.getMethod("set", classOf[Unit])
.invoke(hiveConf, param, value)
val tempDir = Utils.createTempDir()
val localMetastore = new File(tempDir, "metastore")
hiveConfSet("hive.metastore.warehouse.dir", localMetastore.toURI.toString)
hiveConfSet("javax.jdo.option.ConnectionURL",
s"jdbc:derby:;databaseName=${localMetastore.getAbsolutePath};create=true")
hiveConfSet("datanucleus.rdbms.datastoreAdapterClassName",
"org.datanucleus.store.rdbms.adapter.DerbyAdapter")

val hiveClass = mirror.classLoader.loadClass("org.apache.hadoop.hive.ql.metadata.Hive")
val hive = hiveClass.getMethod("get").invoke(null, hiveConf.asInstanceOf[Object])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the original problem is caused by this line, right?

Since the hive object is only used inside the condition on L1301, can't you move the original line inside that if and fix the problem? You don't need delegation tokens when using Derby (and hive.metastore.uris would be empty in that case), so there's no point in even trying to call this class if Derby is being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea


val hiveConfGet = (param: String) => Option(hiveConfClass
.getMethod("get", classOf[java.lang.String])
Expand Down