Skip to content

Commit

Permalink
use shim properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ericl committed Jun 23, 2015
1 parent 980b3e5 commit 0e3a74e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,7 @@ private[hive] class ClientWrapper(

// We use hive's conf for compatibility.
private val retryLimit = conf.getIntVar(HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES)
private val retryDelayMillis = 1000 * {
val strRep = conf.getVar(HiveConf.ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY)
if (strRep.endsWith("s")) {
strRep.dropRight(1).toInt // hive 0.14+
} else {
strRep.toInt // pre-0.14
}
}
private val retryDelayMillis = shim.getMetastoreClientConnectRetryDelayMillis(conf)

/**
* Runs `f` with multiple retries in case the hive metastore is temporarily unreachable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.lang.{Boolean => JBoolean, Integer => JInteger}
import java.lang.reflect.{Method, Modifier}
import java.net.URI
import java.util.{ArrayList => JArrayList, List => JList, Map => JMap, Set => JSet}
import java.util.concurrent.TimeUnit

import scala.collection.JavaConversions._

Expand Down Expand Up @@ -64,6 +65,8 @@ private[client] sealed abstract class Shim {

def getDriverResults(driver: Driver): Seq[String]

def getMetastoreClientConnectRetryDelayMillis(conf: HiveConf): Long

def loadPartition(
hive: Hive,
loadPath: Path,
Expand Down Expand Up @@ -192,6 +195,10 @@ private[client] class Shim_v0_12 extends Shim {
res.toSeq
}

override def getMetastoreClientConnectRetryDelayMillis(conf: HiveConf): Long = {
conf.getIntVar(HiveConf.ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY) * 1000
}

override def loadPartition(
hive: Hive,
loadPath: Path,
Expand Down Expand Up @@ -321,6 +328,12 @@ private[client] class Shim_v0_14 extends Shim_v0_13 {
JBoolean.TYPE,
JBoolean.TYPE,
JBoolean.TYPE)
private lazy val getTimeVarMethod =
findMethod(
classOf[HiveConf],
"getTimeVar",
classOf[HiveConf.ConfVars],
classOf[TimeUnit])

override def loadPartition(
hive: Hive,
Expand Down Expand Up @@ -359,4 +372,10 @@ private[client] class Shim_v0_14 extends Shim_v0_13 {
numDP: JInteger, holdDDLTime: JBoolean, listBucketingEnabled: JBoolean, JBoolean.FALSE)
}

override def getMetastoreClientConnectRetryDelayMillis(conf: HiveConf): Long = {
getTimeVarMethod.invoke(
conf,
HiveConf.ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY,
TimeUnit.MILLISECONDS).asInstanceOf[Long]
}
}

0 comments on commit 0e3a74e

Please sign in to comment.