Skip to content

Commit 8c468a6

Browse files
committed
[SPARK-5751] [SQL] Sets SPARK_HOME as SPARK_PID_DIR when running Thrift server test suites
This is a follow-up of apache#4720. By default, `spark-daemon.sh` writes PID files under `/tmp`, which makes it impossible to start multiple server instances simultaneously. This PR sets `SPARK_PID_DIR` to Spark home directory to workaround this problem. Many thanks to chenghao-intel for pointing out this issue! <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/apache/spark/4758) <!-- Reviewable:end --> Author: Cheng Lian <[email protected]> Closes apache#4758 from liancheng/thriftserver-pid-dir and squashes the following commits: 252fa0f [Cheng Lian] Uses temporary directory as Thrift server PID directory 1b3d1e3 [Cheng Lian] Sets SPARK_HOME as SPARK_PID_DIR when running Thrift server test suites
1 parent 5f7f3b9 commit 8c468a6

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import org.scalatest.{BeforeAndAfterAll, FunSuite}
3939
import org.apache.spark.Logging
4040
import org.apache.spark.sql.catalyst.util
4141
import org.apache.spark.sql.hive.HiveShim
42+
import org.apache.spark.util.Utils
4243

4344
object TestData {
4445
def getTestDataFilePath(name: String) = {
@@ -273,6 +274,7 @@ abstract class HiveThriftServer2Test extends FunSuite with BeforeAndAfterAll wit
273274
private var metastorePath: File = _
274275
private def metastoreJdbcUri = s"jdbc:derby:;databaseName=$metastorePath;create=true"
275276

277+
private val pidDir: File = Utils.createTempDir("thriftserver-pid")
276278
private var logPath: File = _
277279
private var logTailingProcess: Process = _
278280
private var diagnosisBuffer: ArrayBuffer[String] = ArrayBuffer.empty[String]
@@ -315,7 +317,14 @@ abstract class HiveThriftServer2Test extends FunSuite with BeforeAndAfterAll wit
315317

316318
logInfo(s"Trying to start HiveThriftServer2: port=$port, mode=$mode, attempt=$attempt")
317319

318-
logPath = Process(command, None, "SPARK_TESTING" -> "0").lines.collectFirst {
320+
val env = Seq(
321+
// Disables SPARK_TESTING to exclude log4j.properties in test directories.
322+
"SPARK_TESTING" -> "0",
323+
// Points SPARK_PID_DIR to SPARK_HOME, otherwise only 1 Thrift server instance can be started
324+
// at a time, which is not Jenkins friendly.
325+
"SPARK_PID_DIR" -> pidDir.getCanonicalPath)
326+
327+
logPath = Process(command, None, env: _*).lines.collectFirst {
319328
case line if line.contains(LOG_FILE_MARK) => new File(line.drop(LOG_FILE_MARK.length))
320329
}.getOrElse {
321330
throw new RuntimeException("Failed to find HiveThriftServer2 log file.")
@@ -346,7 +355,7 @@ abstract class HiveThriftServer2Test extends FunSuite with BeforeAndAfterAll wit
346355

347356
private def stopThriftServer(): Unit = {
348357
// The `spark-daemon.sh' script uses kill, which is not synchronous, have to wait for a while.
349-
Process(stopScript, None).run().exitValue()
358+
Process(stopScript, None, "SPARK_PID_DIR" -> pidDir.getCanonicalPath).run().exitValue()
350359
Thread.sleep(3.seconds.toMillis)
351360

352361
warehousePath.delete()

0 commit comments

Comments
 (0)