Skip to content

Commit 59310c3

Browse files
committed
Port HIVE-10415
1 parent 75da050 commit 59310c3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

sql/hive-thriftserver/src/main/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package org.apache.spark.sql.hive.thriftserver
2020
import java.util.Locale
2121
import java.util.concurrent.atomic.AtomicBoolean
2222

23+
import org.apache.hadoop.hive.common.ServerUtils
2324
import org.apache.hadoop.hive.conf.HiveConf
2425
import org.apache.hadoop.hive.conf.HiveConf.ConfVars
2526
import org.apache.hive.service.cli.thrift.{ThriftBinaryCLIService, ThriftHttpCLIService}
@@ -101,6 +102,8 @@ object HiveThriftServer2 extends Logging {
101102
SparkSQLEnv.sqlContext.sessionState.newHadoopConf())
102103

103104
try {
105+
// Cleanup the scratch dir before starting
106+
ServerUtils.cleanUpScratchDir(executionHive.conf)
104107
val server = new HiveThriftServer2(SparkSQLEnv.sqlContext)
105108
server.init(executionHive.conf)
106109
server.start()

sql/hive-thriftserver/src/test/scala/org/apache/spark/sql/hive/thriftserver/HiveThriftServer2Suites.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,39 @@ class SingleSessionSuite extends HiveThriftJdbcTest {
924924
}
925925
}
926926

927+
class HiveThriftCleanUpScratchDirSuite extends HiveThriftJdbcTest{
928+
var tempScratchDir: File = _
929+
930+
override protected def beforeAll(): Unit = {
931+
tempScratchDir = Utils.createTempDir()
932+
tempScratchDir.setWritable(true, false)
933+
assert(tempScratchDir.list().isEmpty)
934+
new File(tempScratchDir.getAbsolutePath + File.separator + "SPARK-31626").createNewFile()
935+
assert(tempScratchDir.list().nonEmpty)
936+
super.beforeAll()
937+
}
938+
939+
override def mode: ServerMode.Value = ServerMode.binary
940+
941+
override protected def extraConf: Seq[String] =
942+
s" --hiveconf ${ConfVars.HIVE_START_CLEANUP_SCRATCHDIR}=true " ::
943+
s"--hiveconf ${ConfVars.SCRATCHDIR}=${tempScratchDir.getAbsolutePath}" :: Nil
944+
945+
test("Cleanup the Hive scratchdir when starting the Hive Server") {
946+
assert(!tempScratchDir.exists())
947+
withJdbcStatement() { statement =>
948+
val rs = statement.executeQuery("SELECT id FROM range(1)")
949+
assert(rs.next())
950+
assert(rs.getLong(1) === 0L)
951+
}
952+
}
953+
954+
override protected def afterAll(): Unit = {
955+
Utils.deleteRecursively(tempScratchDir)
956+
super.afterAll()
957+
}
958+
}
959+
927960
class HiveThriftHttpServerSuite extends HiveThriftJdbcTest {
928961
override def mode: ServerMode.Value = ServerMode.http
929962

0 commit comments

Comments
 (0)