You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2022/05/27 09:47:36 UTC
[GitHub] [incubator-kyuubi] hddong opened a new pull request, #2767: [KYUUBI #2644][WIP] Add etcd discovery client for HA
hddong opened a new pull request, #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767
<!--
Thanks for sending a pull request!
Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/contributions.html
2. If the PR is related to an issue in https://github.com/apache/incubator-kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
-->
### _Why are the changes needed?_
<!--
Please clarify why the changes are needed. For instance,
1. If you add a feature, you can talk about the use case of it.
2. If you fix a bug, you can clarify why it is a bug.
-->
Add etcd discovery client for HA
### _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
- [ ] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
pan3793 commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895215765
##########
kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/DiscoveryClient.scala:
##########
@@ -43,7 +43,7 @@ trait DiscoveryClient extends Logging {
/**
* Get the stored data under path.
*/
- def getData(path: String): Array[Byte]
+ def getData(path: String): String
Review Comment:
We'd better avoid changing the API as much as possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] codecov-commenter commented on pull request #2767: [KYUUBI #2644][WIP] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#issuecomment-1141600126
# [Codecov](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#2767](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (53a7a82) into [master](https://codecov.io/gh/apache/incubator-kyuubi/commit/8578bcd46112a790fa7a977a40cd198dbfeb0eee?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (8578bcd) will **increase** coverage by `0.14%`.
> The diff coverage is `74.83%`.
```diff
@@ Coverage Diff @@
## master #2767 +/- ##
============================================
+ Coverage 62.15% 62.29% +0.14%
+ Complexity 424 198 -226
============================================
Files 464 466 +2
Lines 20827 20978 +151
Branches 2814 2827 +13
============================================
+ Hits 12945 13069 +124
- Misses 6619 6635 +16
- Partials 1263 1274 +11
```
| [Impacted Files](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [.../org/apache/kyuubi/ha/client/DiscoveryClient.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLWhhL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUva3l1dWJpL2hhL2NsaWVudC9EaXNjb3ZlcnlDbGllbnQuc2NhbGE=) | `59.09% <ø> (ø)` | |
| [...he/kyuubi/ha/client/etcd/EtcdDiscoveryClient.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLWhhL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUva3l1dWJpL2hhL2NsaWVudC9ldGNkL0V0Y2REaXNjb3ZlcnlDbGllbnQuc2NhbGE=) | `73.91% <73.91%> (ø)` | |
| [...a/org/apache/kyuubi/ha/client/etcd/EtcdUtils.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLWhhL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUva3l1dWJpL2hhL2NsaWVudC9ldGNkL0V0Y2RVdGlscy5zY2FsYQ==) | `80.00% <80.00%> (ø)` | |
| [...la/org/apache/kyuubi/ha/HighAvailabilityConf.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLWhhL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUva3l1dWJpL2hhL0hpZ2hBdmFpbGFiaWxpdHlDb25mLnNjYWxh) | `98.23% <83.33%> (-0.84%)` | :arrow_down: |
| [...ha/client/zookeeper/ZookeeperDiscoveryClient.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLWhhL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUva3l1dWJpL2hhL2NsaWVudC96b29rZWVwZXIvWm9va2VlcGVyRGlzY292ZXJ5Q2xpZW50LnNjYWxh) | `69.87% <100.00%> (ø)` | |
| [...on/ZooKeeperEngineSecuritySecretProviderImpl.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLWhhL3NyYy9tYWluL3NjYWxhL29yZy9hcGFjaGUva3l1dWJpL3NlcnZpY2UvYXV0aGVudGljYXRpb24vWm9vS2VlcGVyRW5naW5lU2VjdXJpdHlTZWNyZXRQcm92aWRlckltcGwuc2NhbGE=) | `100.00% <100.00%> (ø)` | |
| [...rg/apache/kyuubi/engine/trino/TrinoSqlEngine.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZXh0ZXJuYWxzL2t5dXViaS10cmluby1lbmdpbmUvc3JjL21haW4vc2NhbGEvb3JnL2FwYWNoZS9reXV1YmkvZW5naW5lL3RyaW5vL1RyaW5vU3FsRW5naW5lLnNjYWxh) | `52.63% <0.00%> (-7.02%)` | :arrow_down: |
| [.../org/apache/kyuubi/operation/KyuubiOperation.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLXNlcnZlci9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9vcGVyYXRpb24vS3l1dWJpT3BlcmF0aW9uLnNjYWxh) | `68.00% <0.00%> (-1.34%)` | :arrow_down: |
| [...n/scala/org/apache/kyuubi/engine/ProcBuilder.scala](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLXNlcnZlci9zcmMvbWFpbi9zY2FsYS9vcmcvYXBhY2hlL2t5dXViaS9lbmdpbmUvUHJvY0J1aWxkZXIuc2NhbGE=) | `84.27% <0.00%> (-0.63%)` | :arrow_down: |
| [...main/java/org/apache/kyuubi/client/RestClient.java](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-a3l1dWJpLXJlc3QtY2xpZW50L3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9reXV1YmkvY2xpZW50L1Jlc3RDbGllbnQuamF2YQ==) | `81.03% <0.00%> (+1.72%)` | :arrow_up: |
| ... and [3 more](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
------
[Continue to review full report at Codecov](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [8578bcd...53a7a82](https://codecov.io/gh/apache/incubator-kyuubi/pull/2767?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r902408046
##########
dev/dependencyList:
##########
@@ -87,9 +101,15 @@ metrics-json/4.2.8//metrics-json-4.2.8.jar
metrics-jvm/4.2.8//metrics-jvm-4.2.8.jar
netty-all/4.1.73.Final//netty-all-4.1.73.Final.jar
netty-buffer/4.1.73.Final//netty-buffer-4.1.73.Final.jar
+netty-codec-dns/4.1.74.Final//netty-codec-dns-4.1.74.Final.jar
Review Comment:
> gRPC uses a shaded netty, why do we need those netty stuff?
These netty jars are a dependency of jetcd, had try to use netty-shaded, but got `ClassNoDefException`. Classes in `netty-shaded` have prefix `io.grpc`, jetcd can not recognized. Any suggestions?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] yaooqinn commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
yaooqinn commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895402555
##########
pom.xml:
##########
@@ -110,6 +110,7 @@
<commons-lang.version>2.6</commons-lang.version>
<commons-lang3.version>3.10</commons-lang3.version>
<curator.version>2.12.0</curator.version>
+ <etcd.version>0.7.0</etcd.version>
Review Comment:
0.7.1?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] yaooqinn closed pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
yaooqinn closed pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
URL: https://github.com/apache/incubator-kyuubi/pull/2767
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] zwangsheng commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
zwangsheng commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r913618186
##########
kyuubi-ha/src/test/scala/org/apache/kyuubi/ha/client/etcd/EtcdDiscoveryClientSuite.scala:
##########
@@ -0,0 +1,74 @@
+/*
+ * 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.etcd
+
+import java.nio.charset.StandardCharsets
+
+import scala.collection.JavaConverters._
+
+import io.etcd.jetcd.launcher.Etcd
+import io.etcd.jetcd.launcher.EtcdCluster
+
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.ha.HighAvailabilityConf.HA_CLIENT_CLASS
+import org.apache.kyuubi.ha.client.DiscoveryClientProvider.withDiscoveryClient
+import org.apache.kyuubi.ha.client.DiscoveryClientTests
+import org.apache.kyuubi.service.NoopTBinaryFrontendServer
+
+class EtcdDiscoveryClientSuite extends DiscoveryClientTests {
+ private var etcdCluster: EtcdCluster = _
+ var engineServer: NoopTBinaryFrontendServer = _
+
+ private lazy val _connectString = etcdCluster.clientEndpoints().asScala.mkString(",")
+
+ override def getConnectString(): String = _connectString
+
+ val conf: KyuubiConf = {
+ KyuubiConf()
+ .set(HA_CLIENT_CLASS, classOf[EtcdDiscoveryClient].getName)
Review Comment:
How about we describe the option `EtcdDiscoveryClient ` in the `HA_CLIENT_CLASS` docs, after all, ETCD is not mentioned in the docs at present.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r910818987
##########
dev/dependencyList:
##########
@@ -87,9 +101,15 @@ metrics-json/4.2.8//metrics-json-4.2.8.jar
metrics-jvm/4.2.8//metrics-jvm-4.2.8.jar
netty-all/4.1.73.Final//netty-all-4.1.73.Final.jar
netty-buffer/4.1.73.Final//netty-buffer-4.1.73.Final.jar
+netty-codec-dns/4.1.74.Final//netty-codec-dns-4.1.74.Final.jar
Review Comment:
> [etcd-io/jetcd#1068](https://github.com/etcd-io/jetcd/pull/1068) seems going to provide an all-in-one client jar then we can get rid of those dependencies.
Yep, we can provide an additional pr to change to shaded jar after it was merged and released
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r902401244
##########
dev/dependencyList:
##########
@@ -59,6 +68,7 @@ jakarta.validation-api/2.0.2//jakarta.validation-api-2.0.2.jar
jakarta.ws.rs-api/2.1.6//jakarta.ws.rs-api-2.1.6.jar
jakarta.xml.bind-api/2.3.2//jakarta.xml.bind-api-2.3.2.jar
javassist/3.25.0-GA//javassist-3.25.0-GA.jar
+javax.annotation-api/1.3.2//javax.annotation-api-1.3.2.jar
Review Comment:
Removed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r902415773
##########
externals/kyuubi-spark-sql-engine/src/main/resources/META-INF/services/io.grpc.LoadBalancerProvider:
##########
@@ -0,0 +1,3 @@
+io.grpc.internal.PickFirstLoadBalancerProvider
+io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider
+io.grpc.grpclb.GrpclbLoadBalancerProvider
Review Comment:
> What doesn't relocate them?
Had do this, and got
```scala
Caused by: java.lang.IllegalArgumentException: cannot find a NameResolver for ip:///100.71.36.42:2389
at org.apache.kyuubi.shade.io.grpc.internal.ManagedChannelImpl.getNameResolver(ManagedChannelImpl.java:776)
at org.apache.kyuubi.shade.io.grpc.internal.ManagedChannelImpl.getNameResolver(ManagedChannelImpl.java:785)
at org.apache.kyuubi.shade.io.grpc.internal.ManagedChannelImpl.<init>(ManagedChannelImpl.java:665)
at org.apache.kyuubi.shade.io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:630)
at org.apache.kyuubi.shade.io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:297)
at org.apache.kyuubi.shade.io.vertx.grpc.VertxChannelBuilder.build(VertxChannelBuilder.java:302)
at io.etcd.jetcd.impl.ClientConnectionManager.getChannel(ClientConnectionManager.java:89)
```
Although we provide `IPResolverProvider` in `nameresolverprovider`, `NameResolver` can not load `IPResolverProvider`, we can relocate them after a solution is found.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] zwangsheng commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
zwangsheng commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r885268447
##########
kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/etcd/EtcdDiscoveryClient.scala:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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.etcd
+
+import java.util.concurrent.TimeUnit
+
+import scala.collection.JavaConverters._
+import scala.concurrent.TimeoutException
+
+import EtcdUtils._
+import com.google.common.annotations.VisibleForTesting
+import io.etcd.jetcd.Client
+import io.etcd.jetcd.KV
+import io.etcd.jetcd.Lease
+import io.etcd.jetcd.Lock
+import io.etcd.jetcd.Watch
+import io.etcd.jetcd.lease.LeaseKeepAliveResponse
+import io.etcd.jetcd.options.DeleteOption
+import io.etcd.jetcd.options.GetOption
+import io.etcd.jetcd.options.PutOption
+import io.etcd.jetcd.watch.WatchEvent
+import io.etcd.jetcd.watch.WatchResponse
+import io.grpc.stub.StreamObserver
+
+import org.apache.kyuubi.KYUUBI_VERSION
+import org.apache.kyuubi.KyuubiException
+import org.apache.kyuubi.KyuubiSQLException
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.config.KyuubiConf.ENGINE_INIT_TIMEOUT
+import org.apache.kyuubi.ha.HighAvailabilityConf
+import org.apache.kyuubi.ha.HighAvailabilityConf.HA_ZK_ENGINE_REF_ID
+import org.apache.kyuubi.ha.client.DiscoveryClient
+import org.apache.kyuubi.ha.client.DiscoveryPaths
+import org.apache.kyuubi.ha.client.ServiceDiscovery
+import org.apache.kyuubi.ha.client.ServiceNodeInfo
+import org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClient._
+
+class EtcdDiscoveryClient(conf: KyuubiConf) extends DiscoveryClient {
+
+ case class ServiceNode(path: String, lease: Long)
+
+ var client: Client = _
+ var kvClient: KV = _
+ var lockClient: Lock = _
+ var leaseClient: Lease = _
+ var serviceNode: ServiceNode = _
+
+ var leaseTTL: Long = _
+
+ def createClient(): Unit = {
+ val endpoints = conf.get(HighAvailabilityConf.HA_ADDRESSES)
+ client = Client.builder.endpoints(endpoints).build
+ kvClient = client.getKVClient()
+ lockClient = client.getLockClient()
+ leaseClient = client.getLeaseClient()
+
+ leaseTTL = conf.get(HighAvailabilityConf.HA_ETCD_LEASE_TIMEOUT) / 1000
+ }
+
+ def closeClient(): Unit = {
+ if (client != null) {
+ client.close()
+ }
+ }
+
+ def create(path: String, mode: String, createParent: Boolean = true): String = {
+ // createParent can not effect here
+ mode match {
+ case "PERSISTENT" => kvClient.put(path, path).get()
+ case m => throw new KyuubiException(s"Create mode $m is not support in etcd!")
+ }
+ path
+ }
+
+ def getData(path: String): String = {
+ val response = kvClient.get(path).get()
+ if (response.getKvs.isEmpty) {
+ throw new KyuubiException(s"Key[$path] not exists in ETCD, please check it.")
+ } else {
+ response.getKvs.get(0).getValue
+ }
+ }
+
+ def getChildren(path: String): List[String] = {
+ val kvs = kvClient.get(
+ path,
+ GetOption.newBuilder().isPrefix(true).build()).get().getKvs
+ if (kvs.isEmpty) {
+ List.empty
+ } else {
+ kvs.asScala.map(kv => byteSequenceToString(kv.getKey).stripPrefix(path).stripPrefix("/"))
+ .filter(key => key.nonEmpty && !key.startsWith("lock")).toList
+ }
+ }
+
+ def pathExists(path: String): Boolean = {
+ !pathNonExists(path)
+ }
+
+ def pathNonExists(path: String): Boolean = {
+ kvClient.get(path).get().getKvs.isEmpty
+ }
+
+ def delete(path: String, deleteChildren: Boolean = false): Unit = {
+ kvClient.delete(
+ path,
+ DeleteOption.newBuilder().isPrefix(deleteChildren).build()).get()
+ }
+
+ def monitorState(serviceDiscovery: ServiceDiscovery): Unit = {
+ // not need with etcd
+ }
+
+ def tryWithLock[T](
+ lockPath: String,
+ timeout: Long)(f: => T): T = {
+ // the default unit is millis, covert to seconds.
+ // add more 3 second for leaseTime to make client fast fail
+ val leaseTime = timeout / 1000 + 3
+ // if the lease expires, the lock is automatically released.
+ val leaseId = leaseClient.grant(leaseTime).get().getID()
+ try {
+ try {
+ // Acquire a lease. If no leases are available, this method blocks until either the
+ // maximum number of leases is increased or another client/process closes a lease
+
+ // will throw TimeoutException when we are get lock timeout
+ lockClient.lock(lockPath, leaseId).get(timeout, TimeUnit.MILLISECONDS)
+ } catch {
+ case _: TimeoutException =>
+ throw KyuubiSQLException(s"Timeout to lock on path [$lockPath] after " +
+ s"$timeout ms. There would be some problem that other session may " +
+ s"create engine timeout.")
+ case e: Exception =>
+ throw new KyuubiException(s"Lock failed on path [$lockPath]", e)
+ }
+ f
+ } finally {
+ try {
+ lockClient.unlock(lockPath).get()
+ leaseClient.revoke(leaseId).get()
+ } catch {
+ case e: Exception => throw new KyuubiException(e.getMessage, e.getCause)
+ }
+ }
+ }
+
+ def getServerHost(namespace: String): Option[(String, Int)] = {
+ // TODO: use last one because to avoid touching some maybe-crashed engines
+ // We need a big improvement here.
+ getServiceNodesInfo(namespace, Some(1), silent = true) match {
+ case Seq(sn) => Some((sn.host, sn.port))
+ case _ => None
+ }
+ }
+
+ def getEngineByRefId(
+ namespace: String,
+ engineRefId: String): Option[(String, Int)] = {
+ getServiceNodesInfo(namespace, silent = true)
+ .find(_.engineRefId.exists(_.equals(engineRefId)))
+ .map(data => (data.host, data.port))
+ }
+
+ def getServiceNodesInfo(
+ namespace: String,
+ sizeOpt: Option[Int] = None,
+ silent: Boolean = false): Seq[ServiceNodeInfo] = {
+ try {
+ val hosts = getChildren(DiscoveryPaths.makePath(null, namespace))
+ val size = sizeOpt.getOrElse(hosts.size)
+ hosts.takeRight(size).map { p =>
+ val path = DiscoveryPaths.makePath(namespace, p)
+ val instance = getData(path)
+ val (host, port) = DiscoveryClient.parseInstanceHostPort(instance)
+ val version = p.split(";").find(_.startsWith("version=")).map(_.stripPrefix("version="))
+ val engineRefId = p.split(";").find(_.startsWith("refId=")).map(_.stripPrefix("refId="))
+ info(s"Get service instance:$instance and version:$version under $namespace")
+ ServiceNodeInfo(namespace, p, host, port, version, engineRefId)
+ }
+ } catch {
+ case _: Exception if silent => Nil
+ case e: Exception =>
+ error(s"Failed to get service node info", e)
+ Nil
+ }
+ }
+
+ def registerService(
+ conf: KyuubiConf,
+ namespace: String,
+ serviceDiscovery: ServiceDiscovery,
+ version: Option[String] = None,
+ external: Boolean = false): Unit = {
+ val instance = serviceDiscovery.fe.connectionUrl
+ val watcher = new DeRegisterWatcher(instance, serviceDiscovery)
+
+ val serviceNode = createPersistentNode(conf, namespace, instance, version, external)
+
+ client.getWatchClient.watch(serviceNode.path, watcher)
+
+ if (pathNonExists(serviceNode.path)) {
+ // No node exists, throw exception
+ throw new KyuubiException(s"Unable to create keyValue for this Kyuubi " +
+ s"instance[${instance}] on ETCD.")
+ }
+ }
+
+ def deregisterService(): Unit = {
+ // close the EPHEMERAL_SEQUENTIAL node in etcd
+ if (serviceNode != null) {
+ if (serviceNode.lease != LEASE_NULL_VALUE) {
+ client.getLeaseClient.revoke(serviceNode.lease)
+ delete(serviceNode.path)
+ }
+ serviceNode = null
+ }
+ }
+
+ def postDeregisterService(namespace: String): Boolean = {
+ if (namespace != null) {
+ delete(DiscoveryPaths.makePath(null, namespace), true)
+ true
+ } else {
+ false
+ }
+ }
+
+ def createAndGetServiceNode(
+ conf: KyuubiConf,
+ namespace: String,
+ instance: String,
+ version: Option[String] = None,
+ external: Boolean = false): String = {
+ createPersistentNode(conf, namespace, instance, version, external).path
+ }
+
+ @VisibleForTesting
+ def startSecretNode(
+ createMode: String,
+ basePath: String,
+ initData: String,
+ useProtection: Boolean = false): Unit = {
+ client.getKVClient.put(basePath, initData).get()
+ }
+
+ private def createPersistentNode(
+ conf: KyuubiConf,
+ namespace: String,
+ instance: String,
+ version: Option[String] = None,
+ external: Boolean = false): ServiceNode = {
+ val ns = DiscoveryPaths.makePath(null, namespace)
+ create(ns, "PERSISTENT")
+
+ val session = conf.get(HA_ZK_ENGINE_REF_ID)
Review Comment:
Maybe we should rename this configuration as it is used in both ETCD and ZK
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r902416305
##########
externals/kyuubi-spark-sql-engine/src/main/resources/META-INF/services/io.grpc.NameResolverProvider:
##########
@@ -0,0 +1,4 @@
+io.etcd.jetcd.resolver.DnsSrvResolverProvider
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
pan3793 commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895215133
##########
dev/dependencyList:
##########
@@ -87,9 +101,15 @@ metrics-json/4.2.8//metrics-json-4.2.8.jar
metrics-jvm/4.2.8//metrics-jvm-4.2.8.jar
netty-all/4.1.73.Final//netty-all-4.1.73.Final.jar
netty-buffer/4.1.73.Final//netty-buffer-4.1.73.Final.jar
+netty-codec-dns/4.1.74.Final//netty-codec-dns-4.1.74.Final.jar
Review Comment:
gRPC uses a shaded netty, why do we need those?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on pull request #2767: [KYUUBI #2644][WIP] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#issuecomment-1141696722
cc @yaooqinn @pan3793
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r887435042
##########
kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/etcd/EtcdDiscoveryClient.scala:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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.etcd
+
+import java.util.concurrent.TimeUnit
+
+import scala.collection.JavaConverters._
+import scala.concurrent.TimeoutException
+
+import EtcdUtils._
+import com.google.common.annotations.VisibleForTesting
+import io.etcd.jetcd.Client
+import io.etcd.jetcd.KV
+import io.etcd.jetcd.Lease
+import io.etcd.jetcd.Lock
+import io.etcd.jetcd.Watch
+import io.etcd.jetcd.lease.LeaseKeepAliveResponse
+import io.etcd.jetcd.options.DeleteOption
+import io.etcd.jetcd.options.GetOption
+import io.etcd.jetcd.options.PutOption
+import io.etcd.jetcd.watch.WatchEvent
+import io.etcd.jetcd.watch.WatchResponse
+import io.grpc.stub.StreamObserver
+
+import org.apache.kyuubi.KYUUBI_VERSION
+import org.apache.kyuubi.KyuubiException
+import org.apache.kyuubi.KyuubiSQLException
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.config.KyuubiConf.ENGINE_INIT_TIMEOUT
+import org.apache.kyuubi.ha.HighAvailabilityConf
+import org.apache.kyuubi.ha.HighAvailabilityConf.HA_ZK_ENGINE_REF_ID
+import org.apache.kyuubi.ha.client.DiscoveryClient
+import org.apache.kyuubi.ha.client.DiscoveryPaths
+import org.apache.kyuubi.ha.client.ServiceDiscovery
+import org.apache.kyuubi.ha.client.ServiceNodeInfo
+import org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClient._
+
+class EtcdDiscoveryClient(conf: KyuubiConf) extends DiscoveryClient {
+
+ case class ServiceNode(path: String, lease: Long)
+
+ var client: Client = _
+ var kvClient: KV = _
+ var lockClient: Lock = _
+ var leaseClient: Lease = _
+ var serviceNode: ServiceNode = _
+
+ var leaseTTL: Long = _
+
+ def createClient(): Unit = {
+ val endpoints = conf.get(HighAvailabilityConf.HA_ADDRESSES)
+ client = Client.builder.endpoints(endpoints).build
+ kvClient = client.getKVClient()
+ lockClient = client.getLockClient()
+ leaseClient = client.getLeaseClient()
+
+ leaseTTL = conf.get(HighAvailabilityConf.HA_ETCD_LEASE_TIMEOUT) / 1000
+ }
+
+ def closeClient(): Unit = {
+ if (client != null) {
+ client.close()
+ }
+ }
+
+ def create(path: String, mode: String, createParent: Boolean = true): String = {
+ // createParent can not effect here
+ mode match {
+ case "PERSISTENT" => kvClient.put(path, path).get()
+ case m => throw new KyuubiException(s"Create mode $m is not support in etcd!")
+ }
+ path
+ }
+
+ def getData(path: String): String = {
+ val response = kvClient.get(path).get()
+ if (response.getKvs.isEmpty) {
+ throw new KyuubiException(s"Key[$path] not exists in ETCD, please check it.")
+ } else {
+ response.getKvs.get(0).getValue
+ }
+ }
+
+ def getChildren(path: String): List[String] = {
+ val kvs = kvClient.get(
+ path,
+ GetOption.newBuilder().isPrefix(true).build()).get().getKvs
+ if (kvs.isEmpty) {
+ List.empty
+ } else {
+ kvs.asScala.map(kv => byteSequenceToString(kv.getKey).stripPrefix(path).stripPrefix("/"))
+ .filter(key => key.nonEmpty && !key.startsWith("lock")).toList
+ }
+ }
+
+ def pathExists(path: String): Boolean = {
+ !pathNonExists(path)
+ }
+
+ def pathNonExists(path: String): Boolean = {
+ kvClient.get(path).get().getKvs.isEmpty
+ }
+
+ def delete(path: String, deleteChildren: Boolean = false): Unit = {
+ kvClient.delete(
+ path,
+ DeleteOption.newBuilder().isPrefix(deleteChildren).build()).get()
+ }
+
+ def monitorState(serviceDiscovery: ServiceDiscovery): Unit = {
+ // not need with etcd
+ }
+
+ def tryWithLock[T](
+ lockPath: String,
+ timeout: Long)(f: => T): T = {
+ // the default unit is millis, covert to seconds.
+ // add more 3 second for leaseTime to make client fast fail
+ val leaseTime = timeout / 1000 + 3
+ // if the lease expires, the lock is automatically released.
+ val leaseId = leaseClient.grant(leaseTime).get().getID()
+ try {
+ try {
+ // Acquire a lease. If no leases are available, this method blocks until either the
+ // maximum number of leases is increased or another client/process closes a lease
+
+ // will throw TimeoutException when we are get lock timeout
+ lockClient.lock(lockPath, leaseId).get(timeout, TimeUnit.MILLISECONDS)
+ } catch {
+ case _: TimeoutException =>
+ throw KyuubiSQLException(s"Timeout to lock on path [$lockPath] after " +
+ s"$timeout ms. There would be some problem that other session may " +
+ s"create engine timeout.")
+ case e: Exception =>
+ throw new KyuubiException(s"Lock failed on path [$lockPath]", e)
+ }
+ f
+ } finally {
+ try {
+ lockClient.unlock(lockPath).get()
+ leaseClient.revoke(leaseId).get()
+ } catch {
+ case e: Exception => throw new KyuubiException(e.getMessage, e.getCause)
+ }
+ }
+ }
+
+ def getServerHost(namespace: String): Option[(String, Int)] = {
+ // TODO: use last one because to avoid touching some maybe-crashed engines
+ // We need a big improvement here.
+ getServiceNodesInfo(namespace, Some(1), silent = true) match {
+ case Seq(sn) => Some((sn.host, sn.port))
+ case _ => None
+ }
+ }
+
+ def getEngineByRefId(
+ namespace: String,
+ engineRefId: String): Option[(String, Int)] = {
+ getServiceNodesInfo(namespace, silent = true)
+ .find(_.engineRefId.exists(_.equals(engineRefId)))
+ .map(data => (data.host, data.port))
+ }
+
+ def getServiceNodesInfo(
+ namespace: String,
+ sizeOpt: Option[Int] = None,
+ silent: Boolean = false): Seq[ServiceNodeInfo] = {
+ try {
+ val hosts = getChildren(DiscoveryPaths.makePath(null, namespace))
+ val size = sizeOpt.getOrElse(hosts.size)
+ hosts.takeRight(size).map { p =>
+ val path = DiscoveryPaths.makePath(namespace, p)
+ val instance = getData(path)
+ val (host, port) = DiscoveryClient.parseInstanceHostPort(instance)
+ val version = p.split(";").find(_.startsWith("version=")).map(_.stripPrefix("version="))
+ val engineRefId = p.split(";").find(_.startsWith("refId=")).map(_.stripPrefix("refId="))
+ info(s"Get service instance:$instance and version:$version under $namespace")
+ ServiceNodeInfo(namespace, p, host, port, version, engineRefId)
+ }
+ } catch {
+ case _: Exception if silent => Nil
+ case e: Exception =>
+ error(s"Failed to get service node info", e)
+ Nil
+ }
+ }
+
+ def registerService(
+ conf: KyuubiConf,
+ namespace: String,
+ serviceDiscovery: ServiceDiscovery,
+ version: Option[String] = None,
+ external: Boolean = false): Unit = {
+ val instance = serviceDiscovery.fe.connectionUrl
+ val watcher = new DeRegisterWatcher(instance, serviceDiscovery)
+
+ val serviceNode = createPersistentNode(conf, namespace, instance, version, external)
+
+ client.getWatchClient.watch(serviceNode.path, watcher)
+
+ if (pathNonExists(serviceNode.path)) {
+ // No node exists, throw exception
+ throw new KyuubiException(s"Unable to create keyValue for this Kyuubi " +
+ s"instance[${instance}] on ETCD.")
+ }
+ }
+
+ def deregisterService(): Unit = {
+ // close the EPHEMERAL_SEQUENTIAL node in etcd
+ if (serviceNode != null) {
+ if (serviceNode.lease != LEASE_NULL_VALUE) {
+ client.getLeaseClient.revoke(serviceNode.lease)
+ delete(serviceNode.path)
+ }
+ serviceNode = null
+ }
+ }
+
+ def postDeregisterService(namespace: String): Boolean = {
+ if (namespace != null) {
+ delete(DiscoveryPaths.makePath(null, namespace), true)
+ true
+ } else {
+ false
+ }
+ }
+
+ def createAndGetServiceNode(
+ conf: KyuubiConf,
+ namespace: String,
+ instance: String,
+ version: Option[String] = None,
+ external: Boolean = false): String = {
+ createPersistentNode(conf, namespace, instance, version, external).path
+ }
+
+ @VisibleForTesting
+ def startSecretNode(
+ createMode: String,
+ basePath: String,
+ initData: String,
+ useProtection: Boolean = false): Unit = {
+ client.getKVClient.put(basePath, initData).get()
+ }
+
+ private def createPersistentNode(
+ conf: KyuubiConf,
+ namespace: String,
+ instance: String,
+ version: Option[String] = None,
+ external: Boolean = false): ServiceNode = {
+ val ns = DiscoveryPaths.makePath(null, namespace)
+ create(ns, "PERSISTENT")
+
+ val session = conf.get(HA_ZK_ENGINE_REF_ID)
Review Comment:
Sorry for feedback late, done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
pan3793 commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895215369
##########
externals/kyuubi-spark-sql-engine/src/main/resources/META-INF/services/io.grpc.LoadBalancerProvider:
##########
@@ -0,0 +1,3 @@
+io.grpc.internal.PickFirstLoadBalancerProvider
+io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider
+io.grpc.grpclb.GrpclbLoadBalancerProvider
Review Comment:
What doesn't relocate them?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] yaooqinn commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
yaooqinn commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895398663
##########
externals/kyuubi-spark-sql-engine/src/main/resources/META-INF/services/io.grpc.LoadBalancerProvider:
##########
@@ -0,0 +1,3 @@
+io.grpc.internal.PickFirstLoadBalancerProvider
Review Comment:
license can be added here
##########
externals/kyuubi-spark-sql-engine/src/main/resources/META-INF/services/io.grpc.NameResolverProvider:
##########
@@ -0,0 +1,4 @@
+io.etcd.jetcd.resolver.DnsSrvResolverProvider
Review Comment:
ditto
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r902415978
##########
kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/etcd/EtcdDiscoveryClient.scala:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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.etcd
+
+import java.util.concurrent.TimeUnit
+
+import scala.collection.JavaConverters._
+import scala.concurrent.TimeoutException
+
+import EtcdUtils._
+import com.google.common.annotations.VisibleForTesting
+import io.etcd.jetcd.Client
+import io.etcd.jetcd.KV
+import io.etcd.jetcd.Lease
+import io.etcd.jetcd.Lock
+import io.etcd.jetcd.Watch
+import io.etcd.jetcd.lease.LeaseKeepAliveResponse
+import io.etcd.jetcd.options.DeleteOption
+import io.etcd.jetcd.options.GetOption
+import io.etcd.jetcd.options.PutOption
+import io.etcd.jetcd.watch.WatchEvent
+import io.etcd.jetcd.watch.WatchResponse
+import io.grpc.stub.StreamObserver
+
+import org.apache.kyuubi.KYUUBI_VERSION
+import org.apache.kyuubi.KyuubiException
+import org.apache.kyuubi.KyuubiSQLException
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.config.KyuubiConf.ENGINE_INIT_TIMEOUT
+import org.apache.kyuubi.ha.HighAvailabilityConf
+import org.apache.kyuubi.ha.HighAvailabilityConf.HA_ENGINE_REF_ID
+import org.apache.kyuubi.ha.client.DiscoveryClient
+import org.apache.kyuubi.ha.client.DiscoveryPaths
+import org.apache.kyuubi.ha.client.ServiceDiscovery
+import org.apache.kyuubi.ha.client.ServiceNodeInfo
+import org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClient._
+
+class EtcdDiscoveryClient(conf: KyuubiConf) extends DiscoveryClient {
+
+ case class ServiceNode(path: String, lease: Long)
+
+ var client: Client = _
+ var kvClient: KV = _
+ var lockClient: Lock = _
+ var leaseClient: Lease = _
+ var serviceNode: ServiceNode = _
+
+ var leaseTTL: Long = _
+
+ def createClient(): Unit = {
+ val endpoints = conf.get(HighAvailabilityConf.HA_ADDRESSES)
+ client = Client.builder.endpoints(endpoints).build
+ kvClient = client.getKVClient()
+ lockClient = client.getLockClient()
+ leaseClient = client.getLeaseClient()
+
+ leaseTTL = conf.get(HighAvailabilityConf.HA_ETCD_LEASE_TIMEOUT) / 1000
+ }
+
+ def closeClient(): Unit = {
+ if (client != null) {
+ client.close()
+ }
+ }
+
+ def create(path: String, mode: String, createParent: Boolean = true): String = {
+ // createParent can not effect here
+ mode match {
+ case "PERSISTENT" => kvClient.put(path, path).get()
+ case m => throw new KyuubiException(s"Create mode $m is not support in etcd!")
+ }
+ path
+ }
+
+ def getData(path: String): String = {
+ val response = kvClient.get(path).get()
+ if (response.getKvs.isEmpty) {
+ throw new KyuubiException(s"Key[$path] not exists in ETCD, please check it.")
+ } else {
+ response.getKvs.get(0).getValue
+ }
+ }
+
+ def getChildren(path: String): List[String] = {
+ val kvs = kvClient.get(
+ path,
+ GetOption.newBuilder().isPrefix(true).build()).get().getKvs
+ if (kvs.isEmpty) {
+ List.empty
+ } else {
+ kvs.asScala.map(kv => byteSequenceToString(kv.getKey).stripPrefix(path).stripPrefix("/"))
+ .filter(key => key.nonEmpty && !key.startsWith("lock")).toList
+ }
+ }
+
+ def pathExists(path: String): Boolean = {
+ !pathNonExists(path)
+ }
+
+ def pathNonExists(path: String): Boolean = {
+ kvClient.get(path).get().getKvs.isEmpty
+ }
+
+ def delete(path: String, deleteChildren: Boolean = false): Unit = {
+ kvClient.delete(
+ path,
+ DeleteOption.newBuilder().isPrefix(deleteChildren).build()).get()
+ }
+
+ def monitorState(serviceDiscovery: ServiceDiscovery): Unit = {
+ // not need with etcd
+ }
+
+ def tryWithLock[T](
+ lockPath: String,
+ timeout: Long)(f: => T): T = {
+ // the default unit is millis, covert to seconds.
+ // add more 3 second for leaseTime to make client fast fail
+ val leaseTime = timeout / 1000 + 3
+ // if the lease expires, the lock is automatically released.
+ val leaseId = leaseClient.grant(leaseTime).get().getID()
+ try {
+ try {
+ // Acquire a lease. If no leases are available, this method blocks until either the
+ // maximum number of leases is increased or another client/process closes a lease
+
+ // will throw TimeoutException when we are get lock timeout
+ lockClient.lock(lockPath, leaseId).get(timeout, TimeUnit.MILLISECONDS)
+ } catch {
+ case _: TimeoutException =>
+ throw KyuubiSQLException(s"Timeout to lock on path [$lockPath] after " +
+ s"$timeout ms. There would be some problem that other session may " +
+ s"create engine timeout.")
+ case e: Exception =>
+ throw new KyuubiException(s"Lock failed on path [$lockPath]", e)
+ }
+ f
+ } finally {
+ try {
+ lockClient.unlock(lockPath).get()
+ leaseClient.revoke(leaseId).get()
+ } catch {
+ case e: Exception => throw new KyuubiException(e.getMessage, e.getCause)
+ }
+ }
+ }
+
+ def getServerHost(namespace: String): Option[(String, Int)] = {
+ // TODO: use last one because to avoid touching some maybe-crashed engines
+ // We need a big improvement here.
+ getServiceNodesInfo(namespace, Some(1), silent = true) match {
+ case Seq(sn) => Some((sn.host, sn.port))
+ case _ => None
+ }
+ }
+
+ def getEngineByRefId(
+ namespace: String,
+ engineRefId: String): Option[(String, Int)] = {
+ getServiceNodesInfo(namespace, silent = true)
+ .find(_.engineRefId.exists(_.equals(engineRefId)))
+ .map(data => (data.host, data.port))
+ }
+
+ def getServiceNodesInfo(
+ namespace: String,
+ sizeOpt: Option[Int] = None,
+ silent: Boolean = false): Seq[ServiceNodeInfo] = {
+ try {
+ val hosts = getChildren(DiscoveryPaths.makePath(null, namespace))
+ val size = sizeOpt.getOrElse(hosts.size)
+ hosts.takeRight(size).map { p =>
+ val path = DiscoveryPaths.makePath(namespace, p)
+ val instance = getData(path)
+ val (host, port) = DiscoveryClient.parseInstanceHostPort(instance)
+ val version = p.split(";").find(_.startsWith("version=")).map(_.stripPrefix("version="))
+ val engineRefId = p.split(";").find(_.startsWith("refId=")).map(_.stripPrefix("refId="))
+ info(s"Get service instance:$instance and version:$version under $namespace")
+ ServiceNodeInfo(namespace, p, host, port, version, engineRefId)
+ }
+ } catch {
+ case _: Exception if silent => Nil
+ case e: Exception =>
+ error(s"Failed to get service node info", e)
+ Nil
+ }
+ }
+
+ def registerService(
+ conf: KyuubiConf,
+ namespace: String,
+ serviceDiscovery: ServiceDiscovery,
+ version: Option[String] = None,
+ external: Boolean = false): Unit = {
+ val instance = serviceDiscovery.fe.connectionUrl
+ val watcher = new DeRegisterWatcher(instance, serviceDiscovery)
+
+ val serviceNode = createPersistentNode(conf, namespace, instance, version, external)
+
+ client.getWatchClient.watch(serviceNode.path, watcher)
+
+ if (pathNonExists(serviceNode.path)) {
+ // No node exists, throw exception
+ throw new KyuubiException(s"Unable to create keyValue for this Kyuubi " +
+ s"instance[${instance}] on ETCD.")
+ }
+ }
+
+ def deregisterService(): Unit = {
+ // close the EPHEMERAL_SEQUENTIAL node in etcd
+ if (serviceNode != null) {
+ if (serviceNode.lease != LEASE_NULL_VALUE) {
+ client.getLeaseClient.revoke(serviceNode.lease)
+ delete(serviceNode.path)
+ }
+ serviceNode = null
+ }
+ }
+
+ def postDeregisterService(namespace: String): Boolean = {
+ if (namespace != null) {
+ delete(DiscoveryPaths.makePath(null, namespace), true)
+ true
+ } else {
+ false
+ }
+ }
+
+ def createAndGetServiceNode(
+ conf: KyuubiConf,
+ namespace: String,
+ instance: String,
+ version: Option[String] = None,
+ external: Boolean = false): String = {
+ createPersistentNode(conf, namespace, instance, version, external).path
+ }
+
+ @VisibleForTesting
+ def startSecretNode(
+ createMode: String,
+ basePath: String,
+ initData: String,
+ useProtection: Boolean = false): Unit = {
+ client.getKVClient.put(basePath, initData).get()
+ }
+
+ private def createPersistentNode(
+ conf: KyuubiConf,
+ namespace: String,
+ instance: String,
+ version: Option[String] = None,
+ external: Boolean = false): ServiceNode = {
+ val ns = DiscoveryPaths.makePath(null, namespace)
+ create(ns, "PERSISTENT")
+
+ val session = conf.get(HA_ENGINE_REF_ID)
+ .map(refId => s"refId=$refId;").getOrElse("")
+ val pathPrefix = DiscoveryPaths.makePath(
+ namespace,
+ s"serviceUri=$instance;version=${version.getOrElse(KYUUBI_VERSION)};${session}sequence=")
+ val znodeData = instance
Review Comment:
done
##########
externals/kyuubi-spark-sql-engine/src/main/resources/META-INF/services/io.grpc.LoadBalancerProvider:
##########
@@ -0,0 +1,3 @@
+io.grpc.internal.PickFirstLoadBalancerProvider
Review Comment:
> license can be added here
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r902416532
##########
kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/etcd/EtcdUtils.scala:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.etcd
+
+import java.nio.charset.StandardCharsets.UTF_8
+
+import scala.language.implicitConversions
+
+import io.etcd.jetcd.ByteSequence
+
+object EtcdUtils {
Review Comment:
Done
##########
pom.xml:
##########
@@ -118,6 +119,7 @@
<flink.archive.mirror>${apache.archive.dist}/flink/flink-${flink.version}</flink.archive.mirror>
<flink.archive.download.skip>false</flink.archive.download.skip>
<google.jsr305.version>3.0.2</google.jsr305.version>
+ <grpc.verion>1.45.0</grpc.verion>
Review Comment:
Done
##########
pom.xml:
##########
@@ -110,6 +110,7 @@
<commons-lang.version>2.6</commons-lang.version>
<commons-lang3.version>3.10</commons-lang3.version>
<curator.version>2.12.0</curator.version>
+ <etcd.version>0.7.0</etcd.version>
Review Comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] yaooqinn commented on pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
yaooqinn commented on PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#issuecomment-1181261606
thanks, merged to master
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] yaooqinn commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
yaooqinn commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895405507
##########
kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/etcd/EtcdUtils.scala:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.etcd
+
+import java.nio.charset.StandardCharsets.UTF_8
+
+import scala.language.implicitConversions
+
+import io.etcd.jetcd.ByteSequence
+
+object EtcdUtils {
Review Comment:
seems not very necessary to have implicit here, can we remove this class?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
pan3793 commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895215857
##########
kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/etcd/EtcdDiscoveryClient.scala:
##########
@@ -0,0 +1,332 @@
+/*
+ * 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.etcd
+
+import java.util.concurrent.TimeUnit
+
+import scala.collection.JavaConverters._
+import scala.concurrent.TimeoutException
+
+import EtcdUtils._
+import com.google.common.annotations.VisibleForTesting
+import io.etcd.jetcd.Client
+import io.etcd.jetcd.KV
+import io.etcd.jetcd.Lease
+import io.etcd.jetcd.Lock
+import io.etcd.jetcd.Watch
+import io.etcd.jetcd.lease.LeaseKeepAliveResponse
+import io.etcd.jetcd.options.DeleteOption
+import io.etcd.jetcd.options.GetOption
+import io.etcd.jetcd.options.PutOption
+import io.etcd.jetcd.watch.WatchEvent
+import io.etcd.jetcd.watch.WatchResponse
+import io.grpc.stub.StreamObserver
+
+import org.apache.kyuubi.KYUUBI_VERSION
+import org.apache.kyuubi.KyuubiException
+import org.apache.kyuubi.KyuubiSQLException
+import org.apache.kyuubi.config.KyuubiConf
+import org.apache.kyuubi.config.KyuubiConf.ENGINE_INIT_TIMEOUT
+import org.apache.kyuubi.ha.HighAvailabilityConf
+import org.apache.kyuubi.ha.HighAvailabilityConf.HA_ENGINE_REF_ID
+import org.apache.kyuubi.ha.client.DiscoveryClient
+import org.apache.kyuubi.ha.client.DiscoveryPaths
+import org.apache.kyuubi.ha.client.ServiceDiscovery
+import org.apache.kyuubi.ha.client.ServiceNodeInfo
+import org.apache.kyuubi.ha.client.etcd.EtcdDiscoveryClient._
+
+class EtcdDiscoveryClient(conf: KyuubiConf) extends DiscoveryClient {
+
+ case class ServiceNode(path: String, lease: Long)
+
+ var client: Client = _
+ var kvClient: KV = _
+ var lockClient: Lock = _
+ var leaseClient: Lease = _
+ var serviceNode: ServiceNode = _
+
+ var leaseTTL: Long = _
+
+ def createClient(): Unit = {
+ val endpoints = conf.get(HighAvailabilityConf.HA_ADDRESSES)
+ client = Client.builder.endpoints(endpoints).build
+ kvClient = client.getKVClient()
+ lockClient = client.getLockClient()
+ leaseClient = client.getLeaseClient()
+
+ leaseTTL = conf.get(HighAvailabilityConf.HA_ETCD_LEASE_TIMEOUT) / 1000
+ }
+
+ def closeClient(): Unit = {
+ if (client != null) {
+ client.close()
+ }
+ }
+
+ def create(path: String, mode: String, createParent: Boolean = true): String = {
+ // createParent can not effect here
+ mode match {
+ case "PERSISTENT" => kvClient.put(path, path).get()
+ case m => throw new KyuubiException(s"Create mode $m is not support in etcd!")
+ }
+ path
+ }
+
+ def getData(path: String): String = {
+ val response = kvClient.get(path).get()
+ if (response.getKvs.isEmpty) {
+ throw new KyuubiException(s"Key[$path] not exists in ETCD, please check it.")
+ } else {
+ response.getKvs.get(0).getValue
+ }
+ }
+
+ def getChildren(path: String): List[String] = {
+ val kvs = kvClient.get(
+ path,
+ GetOption.newBuilder().isPrefix(true).build()).get().getKvs
+ if (kvs.isEmpty) {
+ List.empty
+ } else {
+ kvs.asScala.map(kv => byteSequenceToString(kv.getKey).stripPrefix(path).stripPrefix("/"))
+ .filter(key => key.nonEmpty && !key.startsWith("lock")).toList
+ }
+ }
+
+ def pathExists(path: String): Boolean = {
+ !pathNonExists(path)
+ }
+
+ def pathNonExists(path: String): Boolean = {
+ kvClient.get(path).get().getKvs.isEmpty
+ }
+
+ def delete(path: String, deleteChildren: Boolean = false): Unit = {
+ kvClient.delete(
+ path,
+ DeleteOption.newBuilder().isPrefix(deleteChildren).build()).get()
+ }
+
+ def monitorState(serviceDiscovery: ServiceDiscovery): Unit = {
+ // not need with etcd
+ }
+
+ def tryWithLock[T](
+ lockPath: String,
+ timeout: Long)(f: => T): T = {
+ // the default unit is millis, covert to seconds.
+ // add more 3 second for leaseTime to make client fast fail
+ val leaseTime = timeout / 1000 + 3
+ // if the lease expires, the lock is automatically released.
+ val leaseId = leaseClient.grant(leaseTime).get().getID()
+ try {
+ try {
+ // Acquire a lease. If no leases are available, this method blocks until either the
+ // maximum number of leases is increased or another client/process closes a lease
+
+ // will throw TimeoutException when we are get lock timeout
+ lockClient.lock(lockPath, leaseId).get(timeout, TimeUnit.MILLISECONDS)
+ } catch {
+ case _: TimeoutException =>
+ throw KyuubiSQLException(s"Timeout to lock on path [$lockPath] after " +
+ s"$timeout ms. There would be some problem that other session may " +
+ s"create engine timeout.")
+ case e: Exception =>
+ throw new KyuubiException(s"Lock failed on path [$lockPath]", e)
+ }
+ f
+ } finally {
+ try {
+ lockClient.unlock(lockPath).get()
+ leaseClient.revoke(leaseId).get()
+ } catch {
+ case e: Exception => throw new KyuubiException(e.getMessage, e.getCause)
+ }
+ }
+ }
+
+ def getServerHost(namespace: String): Option[(String, Int)] = {
+ // TODO: use last one because to avoid touching some maybe-crashed engines
+ // We need a big improvement here.
+ getServiceNodesInfo(namespace, Some(1), silent = true) match {
+ case Seq(sn) => Some((sn.host, sn.port))
+ case _ => None
+ }
+ }
+
+ def getEngineByRefId(
+ namespace: String,
+ engineRefId: String): Option[(String, Int)] = {
+ getServiceNodesInfo(namespace, silent = true)
+ .find(_.engineRefId.exists(_.equals(engineRefId)))
+ .map(data => (data.host, data.port))
+ }
+
+ def getServiceNodesInfo(
+ namespace: String,
+ sizeOpt: Option[Int] = None,
+ silent: Boolean = false): Seq[ServiceNodeInfo] = {
+ try {
+ val hosts = getChildren(DiscoveryPaths.makePath(null, namespace))
+ val size = sizeOpt.getOrElse(hosts.size)
+ hosts.takeRight(size).map { p =>
+ val path = DiscoveryPaths.makePath(namespace, p)
+ val instance = getData(path)
+ val (host, port) = DiscoveryClient.parseInstanceHostPort(instance)
+ val version = p.split(";").find(_.startsWith("version=")).map(_.stripPrefix("version="))
+ val engineRefId = p.split(";").find(_.startsWith("refId=")).map(_.stripPrefix("refId="))
+ info(s"Get service instance:$instance and version:$version under $namespace")
+ ServiceNodeInfo(namespace, p, host, port, version, engineRefId)
+ }
+ } catch {
+ case _: Exception if silent => Nil
+ case e: Exception =>
+ error(s"Failed to get service node info", e)
+ Nil
+ }
+ }
+
+ def registerService(
+ conf: KyuubiConf,
+ namespace: String,
+ serviceDiscovery: ServiceDiscovery,
+ version: Option[String] = None,
+ external: Boolean = false): Unit = {
+ val instance = serviceDiscovery.fe.connectionUrl
+ val watcher = new DeRegisterWatcher(instance, serviceDiscovery)
+
+ val serviceNode = createPersistentNode(conf, namespace, instance, version, external)
+
+ client.getWatchClient.watch(serviceNode.path, watcher)
+
+ if (pathNonExists(serviceNode.path)) {
+ // No node exists, throw exception
+ throw new KyuubiException(s"Unable to create keyValue for this Kyuubi " +
+ s"instance[${instance}] on ETCD.")
+ }
+ }
+
+ def deregisterService(): Unit = {
+ // close the EPHEMERAL_SEQUENTIAL node in etcd
+ if (serviceNode != null) {
+ if (serviceNode.lease != LEASE_NULL_VALUE) {
+ client.getLeaseClient.revoke(serviceNode.lease)
+ delete(serviceNode.path)
+ }
+ serviceNode = null
+ }
+ }
+
+ def postDeregisterService(namespace: String): Boolean = {
+ if (namespace != null) {
+ delete(DiscoveryPaths.makePath(null, namespace), true)
+ true
+ } else {
+ false
+ }
+ }
+
+ def createAndGetServiceNode(
+ conf: KyuubiConf,
+ namespace: String,
+ instance: String,
+ version: Option[String] = None,
+ external: Boolean = false): String = {
+ createPersistentNode(conf, namespace, instance, version, external).path
+ }
+
+ @VisibleForTesting
+ def startSecretNode(
+ createMode: String,
+ basePath: String,
+ initData: String,
+ useProtection: Boolean = false): Unit = {
+ client.getKVClient.put(basePath, initData).get()
+ }
+
+ private def createPersistentNode(
+ conf: KyuubiConf,
+ namespace: String,
+ instance: String,
+ version: Option[String] = None,
+ external: Boolean = false): ServiceNode = {
+ val ns = DiscoveryPaths.makePath(null, namespace)
+ create(ns, "PERSISTENT")
+
+ val session = conf.get(HA_ENGINE_REF_ID)
+ .map(refId => s"refId=$refId;").getOrElse("")
+ val pathPrefix = DiscoveryPaths.makePath(
+ namespace,
+ s"serviceUri=$instance;version=${version.getOrElse(KYUUBI_VERSION)};${session}sequence=")
+ val znodeData = instance
Review Comment:
znode?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#issuecomment-1150577960
@yaooqinn @pan3793 : Please have a review when free.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] yaooqinn commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
yaooqinn commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r916443033
##########
.rat-excludes:
##########
@@ -44,6 +44,8 @@ build/scala-*/**
**/semantic.min.css
**/icon.png
**/icon.min.css
+**/io.grpc.LoadBalancerProvider
+**/io.grpc.NameResolverProvider
Review Comment:
nit: remove them from rat-ex
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
pan3793 commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895215056
##########
dev/dependencyList:
##########
@@ -59,6 +68,7 @@ jakarta.validation-api/2.0.2//jakarta.validation-api-2.0.2.jar
jakarta.ws.rs-api/2.1.6//jakarta.ws.rs-api-2.1.6.jar
jakarta.xml.bind-api/2.3.2//jakarta.xml.bind-api-2.3.2.jar
javassist/3.25.0-GA//javassist-3.25.0-GA.jar
+javax.annotation-api/1.3.2//javax.annotation-api-1.3.2.jar
Review Comment:
We don't need this, `jakarta.annotation-api` is a drop-in replacement
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
pan3793 commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895215133
##########
dev/dependencyList:
##########
@@ -87,9 +101,15 @@ metrics-json/4.2.8//metrics-json-4.2.8.jar
metrics-jvm/4.2.8//metrics-jvm-4.2.8.jar
netty-all/4.1.73.Final//netty-all-4.1.73.Final.jar
netty-buffer/4.1.73.Final//netty-buffer-4.1.73.Final.jar
+netty-codec-dns/4.1.74.Final//netty-codec-dns-4.1.74.Final.jar
Review Comment:
gRPC uses a shaded netty, why do we need those netty stuff?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] yaooqinn commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
yaooqinn commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895402777
##########
pom.xml:
##########
@@ -118,6 +119,7 @@
<flink.archive.mirror>${apache.archive.dist}/flink/flink-${flink.version}</flink.archive.mirror>
<flink.archive.download.skip>false</flink.archive.download.skip>
<google.jsr305.version>3.0.2</google.jsr305.version>
+ <grpc.verion>1.45.0</grpc.verion>
Review Comment:
1.47.0?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] yaooqinn commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
yaooqinn commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r895405507
##########
kyuubi-ha/src/main/scala/org/apache/kyuubi/ha/client/etcd/EtcdUtils.scala:
##########
@@ -0,0 +1,38 @@
+/*
+ * 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.etcd
+
+import java.nio.charset.StandardCharsets.UTF_8
+
+import scala.language.implicitConversions
+
+import io.etcd.jetcd.ByteSequence
+
+object EtcdUtils {
Review Comment:
seems not very necessary to have implicit here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] pan3793 commented on a diff in pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
pan3793 commented on code in PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#discussion_r902449382
##########
dev/dependencyList:
##########
@@ -87,9 +101,15 @@ metrics-json/4.2.8//metrics-json-4.2.8.jar
metrics-jvm/4.2.8//metrics-jvm-4.2.8.jar
netty-all/4.1.73.Final//netty-all-4.1.73.Final.jar
netty-buffer/4.1.73.Final//netty-buffer-4.1.73.Final.jar
+netty-codec-dns/4.1.74.Final//netty-codec-dns-4.1.74.Final.jar
Review Comment:
https://github.com/etcd-io/jetcd/pull/1068 seems going to provide an all-in-one client jar then we can get rid of those dependencies.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org
[GitHub] [incubator-kyuubi] hddong commented on pull request #2767: [KYUUBI #2644] Add etcd discovery client for HA
Posted by GitBox <gi...@apache.org>.
hddong commented on PR #2767:
URL: https://github.com/apache/incubator-kyuubi/pull/2767#issuecomment-1171865551
@yaooqinn @pan3793 @zwangsheng : Took some time to fix the tests, can review this again.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org