-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31926][SQL][TEST-HIVE1.2][test-maven] Fix concurrency issue for ThriftCLIService to getPortNumber #28797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is added because when I run the mvn tests for the hive-thriftserver module, it was reported missing |
||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| # Set everything to be logged to the file hive-thriftserver/target/unit-tests.log | ||
| log4j.rootLogger=DEBUG, CA, FA | ||
|
|
||
| #Console Appender | ||
| log4j.appender.CA=org.apache.log4j.ConsoleAppender | ||
| log4j.appender.CA.layout=org.apache.log4j.PatternLayout | ||
| log4j.appender.CA.layout.ConversionPattern=%d{HH:mm:ss.SSS} %p %c: %m%n | ||
| log4j.appender.CA.Threshold = WARN | ||
|
|
||
|
|
||
| #File Appender | ||
| log4j.appender.FA=org.apache.log4j.FileAppender | ||
| log4j.appender.FA.append=false | ||
| log4j.appender.FA.file=target/unit-tests.log | ||
| log4j.appender.FA.layout=org.apache.log4j.PatternLayout | ||
| log4j.appender.FA.layout.ConversionPattern=%d{HH:mm:ss.SSS} %t %p %c{1}: %m%n | ||
|
|
||
| # Set the logger level of File Appender to WARN | ||
| log4j.appender.FA.Threshold = DEBUG | ||
|
|
||
| # Some packages are noisy for no good reason. | ||
| log4j.additivity.org.apache.hadoop.hive.serde2.lazy.LazyStruct=false | ||
| log4j.logger.org.apache.hadoop.hive.serde2.lazy.LazyStruct=OFF | ||
|
|
||
| log4j.additivity.org.apache.hadoop.hive.metastore.RetryingHMSHandler=false | ||
| log4j.logger.org.apache.hadoop.hive.metastore.RetryingHMSHandler=OFF | ||
|
|
||
| log4j.additivity.hive.log=false | ||
| log4j.logger.hive.log=OFF | ||
|
|
||
| log4j.additivity.parquet.hadoop.ParquetRecordReader=false | ||
| log4j.logger.parquet.hadoop.ParquetRecordReader=OFF | ||
|
|
||
| log4j.additivity.org.apache.parquet.hadoop.ParquetRecordReader=false | ||
| log4j.logger.org.apache.parquet.hadoop.ParquetRecordReader=OFF | ||
|
|
||
| log4j.additivity.org.apache.parquet.hadoop.ParquetOutputCommitter=false | ||
| log4j.logger.org.apache.parquet.hadoop.ParquetOutputCommitter=OFF | ||
|
|
||
| log4j.additivity.hive.ql.metadata.Hive=false | ||
| log4j.logger.hive.ql.metadata.Hive=OFF | ||
|
|
||
| log4j.additivity.org.apache.hadoop.hive.ql.io.RCFile=false | ||
| log4j.logger.org.apache.hadoop.hive.ql.io.RCFile=ERROR | ||
|
|
||
| # Parquet related logging | ||
| log4j.logger.org.apache.parquet.CorruptStatistics=ERROR | ||
| log4j.logger.parquet.CorruptStatistics=ERROR | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import scala.concurrent.duration._ | |
| import scala.util.Try | ||
|
|
||
| import org.apache.hadoop.hive.conf.HiveConf.ConfVars | ||
| import org.apache.hadoop.hive.ql.session.SessionState | ||
| import org.apache.hive.service.cli.thrift.ThriftCLIService | ||
|
|
||
| import org.apache.spark.sql.test.SharedSparkSession | ||
|
|
@@ -33,6 +34,8 @@ trait SharedThriftServer extends SharedSparkSession { | |
| private var hiveServer2: HiveThriftServer2 = _ | ||
| private var serverPort: Int = 0 | ||
|
|
||
| def mode: ServerMode.Value | ||
|
|
||
| override def beforeAll(): Unit = { | ||
| super.beforeAll() | ||
| // Retries up to 3 times with different port numbers if the server fails to start | ||
|
|
@@ -50,14 +53,21 @@ trait SharedThriftServer extends SharedSparkSession { | |
| hiveServer2.stop() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From some Jenkins jobs, NPE is reported here. |
||
| } finally { | ||
| super.afterAll() | ||
| SessionState.detachSession() | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fix is added to |
||
| } | ||
| } | ||
|
|
||
| protected def jdbcUri: String = if (mode == ServerMode.http) { | ||
| s"jdbc:hive2://localhost:$serverPort/default;transportMode=http;httpPath=cliservice" | ||
| } else { | ||
| s"jdbc:hive2://localhost:$serverPort/" | ||
| } | ||
|
|
||
| protected def withJdbcStatement(fs: (Statement => Unit)*): Unit = { | ||
| val user = System.getProperty("user.name") | ||
| require(serverPort != 0, "Failed to bind an actual port for HiveThriftServer2") | ||
| val connections = | ||
| fs.map { _ => DriverManager.getConnection(s"jdbc:hive2://localhost:$serverPort", user, "") } | ||
| fs.map { _ => DriverManager.getConnection(jdbcUri, user, "") } | ||
| val statements = connections.map(_.createStatement()) | ||
|
|
||
| try { | ||
|
|
@@ -69,23 +79,35 @@ trait SharedThriftServer extends SharedSparkSession { | |
| } | ||
|
|
||
| private def startThriftServer(attempt: Int): Unit = { | ||
| logInfo(s"Trying to start HiveThriftServer2:, attempt=$attempt") | ||
| logInfo(s"Trying to start HiveThriftServer2: mode=$mode, attempt=$attempt") | ||
| val sqlContext = spark.newSession().sqlContext | ||
| // Set the HIVE_SERVER2_THRIFT_PORT to 0, so it could randomly pick any free port to use. | ||
| // Set the HIVE_SERVER2_THRIFT_PORT and HIVE_SERVER2_THRIFT_HTTP_PORT to 0, so it could | ||
| // randomly pick any free port to use. | ||
| // It's much more robust than set a random port generated by ourselves ahead | ||
| sqlContext.setConf(ConfVars.HIVE_SERVER2_THRIFT_PORT.varname, "0") | ||
| hiveServer2 = HiveThriftServer2.startWithContext(sqlContext) | ||
| hiveServer2.getServices.asScala.foreach { | ||
| case t: ThriftCLIService if t.getPortNumber != 0 => | ||
| serverPort = t.getPortNumber | ||
| logInfo(s"Started HiveThriftServer2: port=$serverPort, attempt=$attempt") | ||
| case _ => | ||
| } | ||
| sqlContext.setConf(ConfVars.HIVE_SERVER2_THRIFT_HTTP_PORT.varname, "0") | ||
| sqlContext.setConf(ConfVars.HIVE_SERVER2_TRANSPORT_MODE.varname, mode.toString) | ||
|
|
||
| try { | ||
| hiveServer2 = HiveThriftServer2.startWithContext(sqlContext) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before NPE occurs, this failed. |
||
| hiveServer2.getServices.asScala.foreach { | ||
| case t: ThriftCLIService => | ||
| serverPort = t.getPortNumber | ||
| logInfo(s"Started HiveThriftServer2: mode=$mode, port=$serverPort, attempt=$attempt") | ||
| case _ => | ||
| } | ||
|
|
||
| // Wait for thrift server to be ready to serve the query, via executing simple query | ||
| // till the query succeeds. See SPARK-30345 for more details. | ||
| eventually(timeout(30.seconds), interval(1.seconds)) { | ||
| withJdbcStatement { _.execute("SELECT 1") } | ||
| // Wait for thrift server to be ready to serve the query, via executing simple query | ||
| // till the query succeeds. See SPARK-30345 for more details. | ||
| eventually(timeout(30.seconds), interval(1.seconds)) { | ||
| withJdbcStatement { _.execute("SELECT 1") } | ||
| } | ||
| } catch { | ||
| case e: Exception => | ||
| logError("Error start hive server with Context ", e) | ||
| if (hiveServer2 != null) { | ||
| hiveServer2.stop() | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple test suites from thriftserver moduel here. Are the other suites OK to be executed in parallel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I verified it locally with all
SharedThriftServer-like tests in a single JVM, which needed to removeorg.apache.spark.sql.hive.thriftserver.ThriftServerQueryTestSuitehere, and passed.command:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure we can pass tests when running within a single JVM. We can send a new PR to optimize it by running tests in parallel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cloud-fan I meant the other hive-thriftserver suites in
testsWhichShouldRunInTheirOwnDedicatedJvm.From line 479 to 482. I haven't looked into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the log again and found that the 3 of
SharedThriftServer-like tests in #28797 (comment) were executed sequentially in the single JVM.https://www.scala-sbt.org/1.x/docs/Testing.html#Forking+tests
Not quite sure which rule above worked