This is an automated email from the ASF dual-hosted git repository.
chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git
The following commit(s) were added to refs/heads/master by this push:
new 130981974 [KYUUBI #6542] KyuubiBatchService should wait for HTTP
server started before picking jobs
130981974 is described below
commit 130981974930c018d3e24853c8ff53638b8206d0
Author: Cheng Pan <[email protected]>
AuthorDate: Thu Jul 18 11:39:58 2024 +0800
[KYUUBI #6542] KyuubiBatchService should wait for HTTP server started
before picking jobs
# :mag: Description
This is similar to https://github.com/apache/kyuubi/pull/5310.
We need to wait for Jetty Server started before picking jobs, otherwise, it
may get the wrong local HTTP server port -1.
This only affects Batch V2
## Types of changes :bookmark:
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
## Test Plan ๐งช
Tested in internal workloads.
---
# Checklist ๐
- [x] This patch was not authored or co-authored using [Generative
Tooling](https://www.apache.org/legal/generative-tooling.html)
**Be nice. Be informative.**
Closes #6542 from pan3793/batch-wait-started.
Closes #6542
1f62debfe [Cheng Pan] fix
ee1d05d07 [Cheng Pan] KyuubiBatchService should wait for HTTP server
started before picking jobs
Authored-by: Cheng Pan <[email protected]>
Signed-off-by: Cheng Pan <[email protected]>
---
.../org/apache/kyuubi/server/KyuubiBatchService.scala | 3 ++-
.../kyuubi/server/KyuubiRestFrontendService.scala | 18 +++++++++++-------
.../org/apache/kyuubi/server/ui/JettyServer.scala | 4 ++--
3 files changed, 15 insertions(+), 10 deletions(-)
diff --git
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiBatchService.scala
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiBatchService.scala
index e2736267f..c099f2cb9 100644
---
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiBatchService.scala
+++
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiBatchService.scala
@@ -34,7 +34,7 @@ class KyuubiBatchService(
private lazy val restFrontend = server.frontendServices
.filter(_.isInstanceOf[KyuubiRestFrontendService])
- .head
+ .head.asInstanceOf[KyuubiRestFrontendService]
private def kyuubiInstance: String = restFrontend.connectionUrl
@@ -66,6 +66,7 @@ class KyuubiBatchService(
override def start(): Unit = {
assert(running.compareAndSet(false, true))
val submitTask: Runnable = () => {
+ restFrontend.waitForServerStarted()
while (running.get) {
metadataManager.pickBatchForSubmitting(kyuubiInstance) match {
case None => Thread.sleep(1000)
diff --git
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
index 811f3d053..35ee0afff 100644
---
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
+++
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala
@@ -193,19 +193,23 @@ class KyuubiRestFrontendService(override val serverable:
Serverable)
}
}
+ def waitForServerStarted(): Unit = {
+ // block until the HTTP server is started, otherwise, we may get
+ // the wrong HTTP server port -1
+ while (!server.isStarted) {
+ info(s"Waiting for $getName's HTTP server getting started")
+ Thread.sleep(1000)
+ }
+ }
+
override def start(): Unit = synchronized {
if (!isStarted.get) {
try {
server.start()
+ startInternal()
+ waitForServerStarted()
isStarted.set(true)
startBatchChecker()
- startInternal()
- // block until the HTTP server is started, otherwise, we may get
- // the wrong HTTP server port -1
- while (server.getState != "STARTED") {
- info(s"Waiting for $getName's HTTP server getting started")
- Thread.sleep(1000)
- }
recoverBatchSessions()
} catch {
case e: Exception => throw new KyuubiException(s"Cannot start
$getName", e)
diff --git
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala
index f0b752061..f88d46241 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala
@@ -24,7 +24,7 @@ import org.eclipse.jetty.util.thread.{QueuedThreadPool,
ScheduledExecutorSchedul
import org.apache.kyuubi.util.JavaUtils
-private[kyuubi] case class JettyServer(
+private[kyuubi] class JettyServer(
server: Server,
connector: ServerConnector,
rootHandler: ContextHandlerCollection) {
@@ -68,7 +68,7 @@ private[kyuubi] case class JettyServer(
addHandler(JettyUtils.createRedirectHandler(src, dest))
}
- def getState: String = server.getState
+ def isStarted: Boolean = server.isStarted
}
object JettyServer {