This is an automated email from the ASF dual-hosted git repository.
bowenliang 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 346d7a667 [KYUUBI #5145] Change embedded Zookeeper server to
method-local variable
346d7a667 is described below
commit 346d7a667339915e4f84fbdef65669a77c576898
Author: liangbowen <[email protected]>
AuthorDate: Fri Aug 11 20:07:45 2023 +0800
[KYUUBI #5145] Change embedded Zookeeper server to method-local variable
### _Why are the changes needed?_
- Change the embedded Zookeeper server to method variable
- Throw runtime exception for failures when initializing the embedded
Zookeeper
### _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.readthedocs.io/en/master/contributing/code/testing.html#running-tests)
locally before make a pull request
Closes #5145 from bowenliang123/embed-zk.
Closes #5145
2a78957e5 [liangbowen] nit
86087117c [liangbowen] update
0f523f265 [liangbowen] throw runtime exception for failures when
initializing embedded zookeeper
b33e7a497 [liangbowen] make the embedded zookeeper from member attributes
to method-local variable
Authored-by: liangbowen <[email protected]>
Signed-off-by: liangbowen <[email protected]>
---
.../scala/org/apache/kyuubi/server/KyuubiServer.scala | 17 +++++++++--------
.../apache/kyuubi/zookeeper/EmbeddedZookeeper.scala | 19 +++++++++++++------
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git
a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiServer.scala
b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiServer.scala
index 2fc0475a3..bd707a66f 100644
--- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiServer.scala
+++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiServer.scala
@@ -38,17 +38,20 @@ import org.apache.kyuubi.util.{KyuubiHadoopUtils,
SignalRegister}
import org.apache.kyuubi.zookeeper.EmbeddedZookeeper
object KyuubiServer extends Logging {
- private val zkServer = new EmbeddedZookeeper()
private[kyuubi] var kyuubiServer: KyuubiServer = _
@volatile private[kyuubi] var hadoopConf: Configuration = _
def startServer(conf: KyuubiConf): KyuubiServer = {
hadoopConf = KyuubiHadoopUtils.newHadoopConf(conf)
+ var embeddedZkServer: Option[EmbeddedZookeeper] = None
if (!ServiceDiscovery.supportServiceDiscovery(conf)) {
- zkServer.initialize(conf)
- zkServer.start()
- conf.set(HA_ADDRESSES, zkServer.getConnectString)
- conf.set(HA_ZK_AUTH_TYPE, AuthTypes.NONE.toString)
+ embeddedZkServer = Some(new EmbeddedZookeeper())
+ embeddedZkServer.foreach(zkServer => {
+ zkServer.initialize(conf)
+ zkServer.start()
+ conf.set(HA_ADDRESSES, zkServer.getConnectString)
+ conf.set(HA_ZK_AUTH_TYPE, AuthTypes.NONE.toString)
+ })
}
val server = conf.get(KyuubiConf.SERVER_NAME) match {
@@ -59,9 +62,7 @@ object KyuubiServer extends Logging {
server.initialize(conf)
} catch {
case e: Exception =>
- if (zkServer.getServiceState == ServiceState.STARTED) {
- zkServer.stop()
- }
+ embeddedZkServer.filter(_.getServiceState ==
ServiceState.STARTED).foreach(_.stop())
throw e
}
server.start()
diff --git
a/kyuubi-zookeeper/src/main/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala
b/kyuubi-zookeeper/src/main/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala
index 04457f3ce..25bd67446 100644
---
a/kyuubi-zookeeper/src/main/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala
+++
b/kyuubi-zookeeper/src/main/scala/org/apache/kyuubi/zookeeper/EmbeddedZookeeper.scala
@@ -44,14 +44,21 @@ class EmbeddedZookeeper extends
AbstractService("EmbeddedZookeeper") {
val maxSessionTimeout = conf.get(ZK_MAX_SESSION_TIMEOUT)
host =
conf.get(ZK_CLIENT_PORT_ADDRESS).getOrElse(findLocalInetAddress.getCanonicalHostName)
- zks = new ZooKeeperServer(dataDirectory, dataDirectory, tickTime)
- zks.setMinSessionTimeout(minSessionTimeout)
- zks.setMaxSessionTimeout(maxSessionTimeout)
+ try {
+ zks = new ZooKeeperServer(dataDirectory, dataDirectory, tickTime)
+ zks.setMinSessionTimeout(minSessionTimeout)
+ zks.setMaxSessionTimeout(maxSessionTimeout)
- serverFactory = new NIOServerCnxnFactory
- serverFactory.configure(new InetSocketAddress(host, clientPort),
maxClientCnxns)
+ serverFactory = new NIOServerCnxnFactory
+ serverFactory.configure(new InetSocketAddress(host, clientPort),
maxClientCnxns)
- super.initialize(conf)
+ super.initialize(conf)
+ } catch {
+ case e: Exception =>
+ throw new RuntimeException(
+ s"Failed to initialize the embedded ZooKeeper server, binding to
$host:$clientPort",
+ e)
+ }
}
override def start(): Unit = synchronized {