Skip to content

Commit fe79dee

Browse files
bgramsyaooqinn
authored andcommitted
[KYUUBI #3272] Synchronize graceful shutdown with main stop sequence
### _Why are the changes needed?_ Fixes #3272 Kyuubi server stop sequence doesn't respect graceful shutdown triggered in the discovery clients' `DeRegisterWatcher` loops. This leads to frontend service components being stopped before sessions close, resetting connections and leading to client disruption. PR synchronizes these threads to ensure that service components wait for client sessions to close before continuing the stop sequence. * Existing service discovery deregistration functionality is maintained to ensure that new connections are established with healthy instances once the stop sequence has begun. * Existing Hadoop shutdown hooks ensure that the watcher can be timed out, and are configurable via `hadoop.service.shutdown.timeout`. The Kyuubi server will always shut down within 30 seconds when using default config. ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #3291 from bgrams/fix/graceful-shutdown. Closes #3272 ffec2a2 [Brandon Grams] Synchronize graceful session shutdown Authored-by: Brandon Grams <brandongr@zillowgroup.com> Signed-off-by: Kent Yao <yao@apache.org> (cherry picked from commit bc16852) Signed-off-by: Kent Yao <yao@apache.org>
1 parent 7c15771 commit fe79dee

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class KyuubiServiceDiscovery(
3232
if (!isServerLost.get()) {
3333
discoveryClient.deregisterService()
3434
discoveryClient.closeClient()
35+
gracefulShutdownLatch.await() // wait for graceful shutdown triggered by watcher
3536
} else {
3637
warn(s"The Zookeeper ensemble is LOST")
3738
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.kyuubi.ha.client
1919

20+
import java.util.concurrent.CountDownLatch
2021
import java.util.concurrent.atomic.AtomicBoolean
2122

2223
import org.apache.kyuubi.Logging
@@ -34,6 +35,7 @@ abstract class ServiceDiscovery(
3435
name: String,
3536
val fe: FrontendService) extends AbstractService(name) {
3637

38+
protected val gracefulShutdownLatch = new CountDownLatch(1)
3739
protected val isServerLost = new AtomicBoolean(false)
3840

3941
/**
@@ -68,6 +70,7 @@ abstract class ServiceDiscovery(
6870
Thread.sleep(1000 * 60)
6971
}
7072
isServerLost.set(isLost)
73+
gracefulShutdownLatch.countDown()
7174
fe.serverable.stop()
7275
}
7376
}

0 commit comments

Comments
 (0)