Skip to content

Commit 460fe54

Browse files
committed
[KYUUBI #XXXX] Do not block server shutdown on batch sessions
Batch sessions are handles to jobs submitted to external clusters (YARN/K8s). The actual computation runs on the cluster and continues regardless of Kyuubi server state. Including batch sessions in the shutdown wait loop caused the server to hang indefinitely when long- running batch jobs were active. Introduces `closeOnServerStop` on the Session trait (default: true, backward-compatible). KyuubiBatchSession overrides it to false. ServiceDiscovery.stopGracefully now waits only for sessions where closeOnServerStop is true.
1 parent aa58942 commit 460fe54

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

kyuubi-common/src/main/scala/org/apache/kyuubi/session/Session.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,6 @@ trait Session {
9797
def closeExpiredOperations(): Unit
9898

9999
def isForAliveProbe: Boolean
100+
101+
def closeOnServerStop: Boolean = true
100102
}

kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/ServiceDiscovery.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ abstract class ServiceDiscovery(
6666

6767
// stop the server genteelly
6868
def stopGracefully(isLost: Boolean = false): Unit = {
69-
var activeSessionCount = fe.be.sessionManager.getActiveUserSessionCount
70-
while (activeSessionCount > 0) {
71-
info(s"$activeSessionCount connection(s) are active, delay shutdown")
69+
var blockingSessionCount =
70+
fe.be.sessionManager.allSessions().count(_.closeOnServerStop)
71+
while (blockingSessionCount > 0) {
72+
info(s"$blockingSessionCount connection(s) are active, delay shutdown")
7273
Thread.sleep(TimeUnit.SECONDS.toMillis(10))
73-
activeSessionCount = fe.be.sessionManager.getActiveUserSessionCount
74+
blockingSessionCount =
75+
fe.be.sessionManager.allSessions().count(_.closeOnServerStop)
7476
}
7577
isServerLost.set(isLost)
7678
gracefulShutdownLatch.countDown()

kyuubi-server/src/main/scala/org/apache/kyuubi/session/KyuubiBatchSession.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,6 @@ class KyuubiBatchSession(
229229
EventBus.post(sessionEvent)
230230
traceMetricsOnClose()
231231
}
232+
233+
override def closeOnServerStop: Boolean = false
232234
}

0 commit comments

Comments
 (0)