File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
sql/hive-thriftserver/src
main/scala/org/apache/spark/sql/hive/thriftserver
test/scala/org/apache/spark/sql/hive/thriftserver Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ package org.apache.spark.sql.hive.thriftserver
2020import java .util .Locale
2121import java .util .concurrent .atomic .AtomicBoolean
2222
23+ import org .apache .hadoop .hive .common .ServerUtils
2324import org .apache .hadoop .hive .conf .HiveConf
2425import org .apache .hadoop .hive .conf .HiveConf .ConfVars
2526import 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()
Original file line number Diff line number Diff 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+
927960class HiveThriftHttpServerSuite extends HiveThriftJdbcTest {
928961 override def mode : ServerMode .Value = ServerMode .http
929962
You can’t perform that action at this time.
0 commit comments