WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit bae0f03

Browse files
committed
[KYUUBI #6542] KyuubiBatchService should wait for HTTP server started before picking jobs
# 🔍 Description This is similar to #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 🔖 - [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 1f62deb [Cheng Pan] fix ee1d05d [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]> (cherry picked from commit 1309819) Signed-off-by: Cheng Pan <[email protected]>
1 parent 14b7e32 commit bae0f03

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiBatchService.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class KyuubiBatchService(
3434

3535
private lazy val restFrontend = server.frontendServices
3636
.filter(_.isInstanceOf[KyuubiRestFrontendService])
37-
.head
37+
.head.asInstanceOf[KyuubiRestFrontendService]
3838

3939
private def kyuubiInstance: String = restFrontend.connectionUrl
4040

@@ -66,6 +66,7 @@ class KyuubiBatchService(
6666
override def start(): Unit = {
6767
assert(running.compareAndSet(false, true))
6868
val submitTask: Runnable = () => {
69+
restFrontend.waitForServerStarted()
6970
while (running.get) {
7071
metadataManager.pickBatchForSubmitting(kyuubiInstance) match {
7172
case None => Thread.sleep(1000)

kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiRestFrontendService.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,23 @@ class KyuubiRestFrontendService(override val serverable: Serverable)
192192
}
193193
}
194194

195+
def waitForServerStarted(): Unit = {
196+
// block until the HTTP server is started, otherwise, we may get
197+
// the wrong HTTP server port -1
198+
while (!server.isStarted) {
199+
info(s"Waiting for $getName's HTTP server getting started")
200+
Thread.sleep(1000)
201+
}
202+
}
203+
195204
override def start(): Unit = synchronized {
196205
if (!isStarted.get) {
197206
try {
198207
server.start()
208+
startInternal()
209+
waitForServerStarted()
199210
isStarted.set(true)
200211
startBatchChecker()
201-
startInternal()
202-
// block until the HTTP server is started, otherwise, we may get
203-
// the wrong HTTP server port -1
204-
while (server.getState != "STARTED") {
205-
info(s"Waiting for $getName's HTTP server getting started")
206-
Thread.sleep(1000)
207-
}
208212
recoverBatchSessions()
209213
} catch {
210214
case e: Exception => throw new KyuubiException(s"Cannot start $getName", e)

kyuubi-server/src/main/scala/org/apache/kyuubi/server/ui/JettyServer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import org.eclipse.jetty.util.thread.{QueuedThreadPool, ScheduledExecutorSchedul
2424

2525
import org.apache.kyuubi.Utils.isWindows
2626

27-
private[kyuubi] case class JettyServer(
27+
private[kyuubi] class JettyServer(
2828
server: Server,
2929
connector: ServerConnector,
3030
rootHandler: ContextHandlerCollection) {
@@ -68,7 +68,7 @@ private[kyuubi] case class JettyServer(
6868
addHandler(JettyUtils.createRedirectHandler(src, dest))
6969
}
7070

71-
def getState: String = server.getState
71+
def isStarted: Boolean = server.isStarted
7272
}
7373

7474
object JettyServer {

0 commit comments

Comments
 (0)