From 5b9ef3c3dfafc8d3db1093ac3e025c17afb35b5b Mon Sep 17 00:00:00 2001 From: fwang12 Date: Mon, 5 Apr 2021 20:00:46 +0800 Subject: [PATCH] [KYUUBI #483] Add configEntry for zookeeper node timeout ![turboFei](https://badgen.net/badge/Hello/turboFei/green) [![Closes #484](https://badgen.net/badge/Preview/Closes%20%23484/blue)](https://github.com/yaooqinn/kyuubi/pull/484) ![45](https://badgen.net/badge/%2B/45/red) ![2](https://badgen.net/badge/-/2/green) ![2](https://badgen.net/badge/commits/2/yellow) [Powered by Pull Request Badge](https://pullrequestbadge.com/?utm_medium=github&utm_source=yaooqinn&utm_campaign=badge_info) ### _Why are the changes needed?_ Add configEntry for zookeeper node timeout instead of using constant value ### _How was this patch tested?_ - [x] 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/latest/tools/testing.html#running-tests) locally before make a pull request Closes #484 from turboFei/KYUUBI_304_znode_timeout. Closes #483 786b915 [fwang12] address comments 5c8dbc1 [fwang12] [KYUUBI #483] Add configEntry for zookeeper node timeout Authored-by: fwang12 Signed-off-by: Kent Yao --- docs/deployment/settings.md | 1 + .../kyuubi/ha/HighAvailabilityConf.scala | 9 +++++ .../kyuubi/ha/client/ServiceDiscovery.scala | 4 +-- .../ha/client/HighAvailabilityConfSuite.scala | 33 +++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/HighAvailabilityConfSuite.scala diff --git a/docs/deployment/settings.md b/docs/deployment/settings.md index 63d56364e..e0400f5d0 100644 --- a/docs/deployment/settings.md +++ b/docs/deployment/settings.md @@ -165,6 +165,7 @@ kyuubi\.ha\.zookeeper
\.connection\.max\.retry
\.wait|
EXPONENTIAL_BACKOFF
|
The retry policy for connecting to the zookeeper ensemble, all candidates are:
  • ONE_TIME
  • N_TIME
  • EXPONENTIAL_BACKOFF
  • BOUNDED_EXPONENTIAL_BACKOFF
  • UNTIL_ELAPSED
|
string
|
1.0.0
kyuubi\.ha\.zookeeper
\.connection\.timeout|
15000
|
The timeout(ms) of creating the connection to the zookeeper ensemble
|
int
|
1.0.0
kyuubi\.ha\.zookeeper
\.namespace|
kyuubi
|
The root directory for the service to deploy its instance uri. Additionally, it will creates a -[username] suffixed root directory for each application
|
string
|
1.0.0
+kyuubi\.ha\.zookeeper
\.node\.creation\.timeout|
PT2M
|
Timeout for creating zookeeper node
|
duration
|
1.2.0
kyuubi\.ha\.zookeeper
\.quorum|
|
The connection string for the zookeeper ensemble
|
string
|
1.0.0
kyuubi\.ha\.zookeeper
\.session\.timeout|
60000
|
The timeout(ms) of a connected session to be idled
|
int
|
1.0.0
diff --git a/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/HighAvailabilityConf.scala b/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/HighAvailabilityConf.scala index edf3e9bcb..94fd91678 100644 --- a/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/HighAvailabilityConf.scala +++ b/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/HighAvailabilityConf.scala @@ -17,6 +17,8 @@ package org.apache.kyuubi.ha +import java.time.Duration + import org.apache.hadoop.security.UserGroupInformation import org.apache.kyuubi.config.{ConfigBuilder, ConfigEntry, KyuubiConf} @@ -90,4 +92,11 @@ object HighAvailabilityConf { .checkValues(RetryPolicies.values.map(_.toString)) .createWithDefault(RetryPolicies.EXPONENTIAL_BACKOFF.toString) + val HA_ZK_NODE_TIMEOUT: ConfigEntry[Long] = + buildConf("ha.zookeeper.node.creation.timeout") + .doc("Timeout for creating zookeeper node") + .version("1.2.0") + .timeConf + .checkValue(_ > 0, "Must be positive") + .createWithDefault(Duration.ofSeconds(120).toMillis) } diff --git a/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/ServiceDiscovery.scala b/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/ServiceDiscovery.scala index 52e5b4496..46fc6e59b 100644 --- a/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/ServiceDiscovery.scala +++ b/kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/ServiceDiscovery.scala @@ -125,8 +125,8 @@ abstract class ServiceDiscovery private ( pathPrefix, instance.getBytes(StandardCharsets.UTF_8)) serviceNode.start() - val znodeTimeout = 120 - if (!serviceNode.waitForInitialCreate(znodeTimeout, TimeUnit.SECONDS)) { + val znodeTimeout = conf.get(HA_ZK_NODE_TIMEOUT) + if (!serviceNode.waitForInitialCreate(znodeTimeout, TimeUnit.MILLISECONDS)) { throw new KyuubiException(s"Max znode creation wait time $znodeTimeout s exhausted") } info(s"Created a ${serviceNode.getActualPath} on ZooKeeper for KyuubiServer uri: " + instance) diff --git a/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/HighAvailabilityConfSuite.scala b/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/HighAvailabilityConfSuite.scala new file mode 100644 index 000000000..f5c7be840 --- /dev/null +++ b/kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/HighAvailabilityConfSuite.scala @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kyuubi.ha.client + +import org.apache.kyuubi.KyuubiFunSuite +import org.apache.kyuubi.config.KyuubiConf +import org.apache.kyuubi.ha.HighAvailabilityConf._ + +class HighAvailabilityConfSuite extends KyuubiFunSuite { + test(HA_ZK_NODE_TIMEOUT.key) { + val conf = new KyuubiConf() + assert(conf.get(HA_ZK_NODE_TIMEOUT) == HA_ZK_NODE_TIMEOUT.defaultVal.get) + conf.set(HA_ZK_NODE_TIMEOUT.key, "60000") + assert(conf.get(HA_ZK_NODE_TIMEOUT) == 60000) + conf.set(HA_ZK_NODE_TIMEOUT.key, "PT1M") + assert(conf.get(HA_ZK_NODE_TIMEOUT) == 60000) + } +}