Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/6912#discussion_r33110812
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/client/ClientWrapper.scala ---
    @@ -136,12 +137,62 @@ private[hive] class ClientWrapper(
     
       // TODO: should be a def?s
       // When we create this val client, the HiveConf of it (conf) is the one 
associated with state.
    -  private val client = Hive.get(conf)
    +  @GuardedBy("this")
    +  private var client = Hive.get(conf)
    +
    +  // We use hive's conf for compatibility.
    +  private val retryLimit = 
conf.getIntVar(HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES)
    +  private val retryDelayMillis = 
shim.getMetastoreClientConnectRetryDelayMillis(conf)
    +
    +  /**
    +   * Runs `f` with multiple retries in case the hive metastore is 
temporarily unreachable.
    +   */
    +  private def retryLocked[A](f: => A): A = synchronized {
    +    // Hive sometimes retries internally, so set a deadline to avoid 
compounding delays.
    +    val deadline = System.nanoTime + (retryLimit * retryDelayMillis * 
1e6).toLong
    +    var numTries = 0
    +    var caughtException: Exception = null
    +    do {
    +      numTries += 1
    +      try {
    +        return f
    +      } catch {
    +        case e: Exception if causedByThrift(e) =>
    +          caughtException = e
    +          logWarning(
    +            "HiveClientWrapper got thrift exception, destroying client and 
retrying " +
    +              s"(${retryLimit - numTries} tries remaining)", e)
    +          Thread.sleep(retryDelayMillis)
    +          try {
    +            client = Hive.get(conf, true)
    --- End diff --
    
    How about we use the hive conf returned by `state.getConf`. This is the 
conf we used to created the original `client`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to