You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by GitBox <gi...@apache.org> on 2022/07/15 02:00:33 UTC
[GitHub] [dolphinscheduler] wjf222 opened a new pull request, #10981: [Feature][Registry] Support etcd as registry
wjf222 opened a new pull request, #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981
<!--Thanks very much for contributing to Apache DolphinScheduler. Please review https://dolphinscheduler.apache.org/en-us/community/development/pull-request.html before opening a pull request.-->
## Purpose of the pull request
Close #8975
## Brief change log
Add CRUD
Add Subscribe
Add Lock
Add ConnectStateListener
## Verify this pull request
This change added tests and can be verified as follows:
Add persistTest to test for CRUD
Add lockTest for lock
TODO add connectStateListener
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1192344009
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [37.3% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1232376705
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [6 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [44.8% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] kezhenxu94 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r921754931
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/pom.xml:
##########
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
Review Comment:
License header
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/README.md:
##########
@@ -0,0 +1,28 @@
+# Introduction
+
+This module is the etcd registry plugin module, this plugin will use etcd as the registry center.
+
+# How to use
+
+If you want to set the registry center as mysql,You need to set the registry properties in master/worker/api's appplication.yml
Review Comment:
```suggestion
If you want to set the registry center as mysql, you need to set the registry properties in master/worker/api's appplication.yml
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,133 @@
+package org.apache.dolphinscheduler.plugin.registry.etcd;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import io.etcd.jetcd.Client;
+import io.grpc.ConnectivityState;
+import io.grpc.ManagedChannel;
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Get the connection status by listening to the Client's Channel
+ */
+public class EtcdConnectionStateListener implements AutoCloseable{
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // Client's Channel
+ private AtomicReference<ManagedChannel> channel;
+ // monitored client
+ private Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
+ private long initialDelay = 500L;
+ private long delay = 500L;
+ public EtcdConnectionStateListener(Client client) {
+ this.client = client;
+ channel = new AtomicReference<>();
+ this.scheduledExecutorService = Executors.newScheduledThreadPool(
+ 1,
+ new ThreadFactoryBuilder().setNameFormat("EtcdConnectionStateListenerThread").setDaemon(true).build());
+ }
+
+ public void addConnectionListener(ConnectionListener connectionListener) {
+ connectionListeners.add(connectionListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connectionListeners.clear();
+ scheduledExecutorService.shutdownNow();
+ }
+
+ /**
+ * try to get jetcd client ManagedChannel
+ * @param client the etcd client
+ * @return current connection channel
+ */
+ private ManagedChannel newChannel(Client client) {
+ try {
+ Field connectField =client.getClass().getDeclaredField("connectManager");
+ if(!connectField.isAccessible()){
+ connectField.setAccessible(true);
+ }
+ Object connection = connectField.get(client);
+ Method channel = connection.getClass().getDeclaredMethod("getChannel");
+ if (!channel.isAccessible()) {
+ channel.setAccessible(true);
+ }
+ return (ManagedChannel) channel.invoke(connection);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to get the etcd client channel", e);
+ }
Review Comment:
I don't think this is a good way to implement the connectivity state listener, why do you choose to use reflection instead of some native method of jetcd client?
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,301 @@
+package org.apache.dolphinscheduler.plugin.registry.etcd;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import io.etcd.jetcd.*;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+import org.apache.dolphinscheduler.registry.api.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Collectors;
+
+import static org.apache.dolphinscheduler.common.Constants.FOLDER_SEPARATOR;
+
+
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS=30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if(!Strings.isNullOrEmpty(registryProperties.getUser())&&(!Strings.isNullOrEmpty(registryProperties.getPassword()))){
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if(!Strings.isNullOrEmpty(registryProperties.getLoadBalancerPolicy())){
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if(!Strings.isNullOrEmpty(registryProperties.getAuthority())){
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e){
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @param key
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (Exception e) {
+ throw new RegistryException("etcd get data error", e);
+ }
+ }
+
+ /**
+ *
+ * @param key
+ * @param value
+ * @param deleteOnDisconnect Does the put data disappear when the client disconnects
+ */
+ @Override
+ public void put(String key, String value, boolean deleteOnDisconnect) {
+ try{
+ if(deleteOnDisconnect) {
+ // keep the key by lease, if disconnected, the lease will ,the key will delete
Review Comment:
This sentence is not complete...
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistryProperties.java:
##########
@@ -0,0 +1,31 @@
+package org.apache.dolphinscheduler.plugin.registry.etcd;
+
+import lombok.Data;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.time.Duration;
+
+@Data
+@Configuration
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+@ConfigurationProperties(prefix = "registry")
+public class EtcdRegistryProperties {
+ private String endpoints;
+ private String namespace="dolphinscheduler";
+ private Duration connectionTimeout = Duration.ofSeconds(9);
+
+ // auth
+ private String user;
+ private String password;
+ private String authority;
+
+ // RetryPolicy
+ private Long retryDelay=60L;
+ private Long retryMaxDelay=300L;
Review Comment:
> The time unit for these two parameters is set by the ChronUnitRetry in jetcd. The type of these two parameters is long, but the type of retryMaxDuration is Duration.
>
> You can see the reference of these three parameters in EtcdRegistry.java line 51 to 54.
Hi, you don't have to just copy the type from JETCD client, using `Duration` as type in our own configurations is for users' convenient, they can just set something like `1s`, `500ms`, without knowing what's the time unit of the config. Also, users don't care what types we pass into `EtcdRegistry.java`, let's provide simplicity to users
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r921884048
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,133 @@
+package org.apache.dolphinscheduler.plugin.registry.etcd;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import io.etcd.jetcd.Client;
+import io.grpc.ConnectivityState;
+import io.grpc.ManagedChannel;
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Get the connection status by listening to the Client's Channel
+ */
+public class EtcdConnectionStateListener implements AutoCloseable{
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // Client's Channel
+ private AtomicReference<ManagedChannel> channel;
+ // monitored client
+ private Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
+ private long initialDelay = 500L;
+ private long delay = 500L;
+ public EtcdConnectionStateListener(Client client) {
+ this.client = client;
+ channel = new AtomicReference<>();
+ this.scheduledExecutorService = Executors.newScheduledThreadPool(
+ 1,
+ new ThreadFactoryBuilder().setNameFormat("EtcdConnectionStateListenerThread").setDaemon(true).build());
+ }
+
+ public void addConnectionListener(ConnectionListener connectionListener) {
+ connectionListeners.add(connectionListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connectionListeners.clear();
+ scheduledExecutorService.shutdownNow();
+ }
+
+ /**
+ * try to get jetcd client ManagedChannel
+ * @param client the etcd client
+ * @return current connection channel
+ */
+ private ManagedChannel newChannel(Client client) {
+ try {
+ Field connectField =client.getClass().getDeclaredField("connectManager");
+ if(!connectField.isAccessible()){
+ connectField.setAccessible(true);
+ }
+ Object connection = connectField.get(client);
+ Method channel = connection.getClass().getDeclaredMethod("getChannel");
+ if (!channel.isAccessible()) {
+ channel.setAccessible(true);
+ }
+ return (ManagedChannel) channel.invoke(connection);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to get the etcd client channel", e);
+ }
Review Comment:
Ok, I will try to use keepalive in lease client to listen for connection status.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1200097147
I have followed the suggestions of the previous review and modified it
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] kezhenxu94 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r926358599
##########
pom.xml:
##########
@@ -878,6 +878,31 @@
<version>${aws.sdk.version}</version>
</dependency>
+ <dependency>
Review Comment:
consider importing `grpc-bom` instead
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r933956997
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd CLuster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (!Strings.isNullOrEmpty(registryProperties.getUser()) && (!Strings.isNullOrEmpty(registryProperties.getPassword()))) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @param key
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException | ExecutionException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get data error", e);
+ }
+ }
+
+ /**
+ *
+ * @param key
+ * @param value
+ * @param deleteOnDisconnect Does the put data disappear when the client disconnects
+ */
+ @Override
+ public void put(String key, String value, boolean deleteOnDisconnect) {
+ try {
+ if (deleteOnDisconnect) {
+ // keep the key by lease, if disconnected, the lease will expire and the key will delete
+ long leaseId = client.getLeaseClient().grant(TIME_TO_LIVE_SECONDS).get().getID();
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ PutOption putOption = PutOption.newBuilder().withLeaseId(leaseId).build();
+ client.getKVClient().put(byteSequence(key), byteSequence(value),putOption).get();
+ } else {
+ client.getKVClient().put(byteSequence(key), byteSequence(value)).get();
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ }
+ }
+
+ /**
+ * delete all keys that contain the prefix
+ * @param key the prrefix
+ */
+ @Override
+ public void delete(String key) {
Review Comment:
I also think deleteByPrefix can better reflect the meaning of the function
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1186479738
Thanks for your review, I'll keep submitting after the unit test bug is resolved
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r921930820
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,133 @@
+package org.apache.dolphinscheduler.plugin.registry.etcd;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import io.etcd.jetcd.Client;
+import io.grpc.ConnectivityState;
+import io.grpc.ManagedChannel;
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Get the connection status by listening to the Client's Channel
+ */
+public class EtcdConnectionStateListener implements AutoCloseable{
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // Client's Channel
+ private AtomicReference<ManagedChannel> channel;
+ // monitored client
+ private Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
+ private long initialDelay = 500L;
+ private long delay = 500L;
+ public EtcdConnectionStateListener(Client client) {
+ this.client = client;
+ channel = new AtomicReference<>();
+ this.scheduledExecutorService = Executors.newScheduledThreadPool(
+ 1,
+ new ThreadFactoryBuilder().setNameFormat("EtcdConnectionStateListenerThread").setDaemon(true).build());
+ }
+
+ public void addConnectionListener(ConnectionListener connectionListener) {
+ connectionListeners.add(connectionListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connectionListeners.clear();
+ scheduledExecutorService.shutdownNow();
+ }
+
+ /**
+ * try to get jetcd client ManagedChannel
+ * @param client the etcd client
+ * @return current connection channel
+ */
+ private ManagedChannel newChannel(Client client) {
+ try {
+ Field connectField =client.getClass().getDeclaredField("connectManager");
+ if(!connectField.isAccessible()){
+ connectField.setAccessible(true);
+ }
+ Object connection = connectField.get(client);
+ Method channel = connection.getClass().getDeclaredMethod("getChannel");
+ if (!channel.isAccessible()) {
+ channel.setAccessible(true);
+ }
+ return (ManagedChannel) channel.invoke(connection);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to get the etcd client channel", e);
+ }
Review Comment:
> I don't think this is a good way to implement the connectivity state listener, why do you choose to use reflection instead of some native method of jetcd client?
I made the problem complicated. I only need to periodically try to connect to Etcd, and the connection status can be judged by the connection result.
I have removed the reflection related code. Now, i use the client to apply for a lease to determine whether the connection is successful in [Using the lease to listen connection state](https://github.com/apache/dolphinscheduler/pull/10981/commits/d3ecd2a6eed4af52395d2547ef7486cf435d03a1)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r921747271
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistryProperties.java:
##########
@@ -0,0 +1,31 @@
+package org.apache.dolphinscheduler.plugin.registry.etcd;
+
+import lombok.Data;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.time.Duration;
+
+@Data
+@Configuration
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+@ConfigurationProperties(prefix = "registry")
+public class EtcdRegistryProperties {
+ private String endpoints;
+ private String namespace="dolphinscheduler";
+ private Duration connectionTimeout = Duration.ofSeconds(9);
+
+ // auth
+ private String user;
+ private String password;
+ private String authority;
+
+ // RetryPolicy
+ private Long retryDelay=60L;
+ private Long retryMaxDelay=300L;
+ private Duration retryMaxDuration=Duration.ofMillis(1500);;
Review Comment:
How to undo this operation, I clicked wrongly
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1201994783
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [35.2% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r933956221
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd CLuster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (!Strings.isNullOrEmpty(registryProperties.getUser()) && (!Strings.isNullOrEmpty(registryProperties.getPassword()))) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @param key
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException | ExecutionException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get data error", e);
+ }
+ }
+
+ /**
+ *
+ * @param key
+ * @param value
+ * @param deleteOnDisconnect Does the put data disappear when the client disconnects
+ */
+ @Override
+ public void put(String key, String value, boolean deleteOnDisconnect) {
+ try {
+ if (deleteOnDisconnect) {
+ // keep the key by lease, if disconnected, the lease will expire and the key will delete
+ long leaseId = client.getLeaseClient().grant(TIME_TO_LIVE_SECONDS).get().getID();
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ PutOption putOption = PutOption.newBuilder().withLeaseId(leaseId).build();
+ client.getKVClient().put(byteSequence(key), byteSequence(value),putOption).get();
+ } else {
+ client.getKVClient().put(byteSequence(key), byteSequence(value)).get();
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ }
+ }
+
+ /**
+ * delete all keys that contain the prefix
+ * @param key the prrefix
+ */
+ @Override
+ public void delete(String key) {
Review Comment:
> It's better to use the more precise method name, such as `deleteByPrefix(String keyPrefix)`
This is a function from the Registry interface. It may be a better choice to initiate a new PR to modify the function name.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1231583825
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [6 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [44.8% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1232404407
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [6 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [44.8% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] codecov-commenter commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1191017741
# [Codecov](https://codecov.io/gh/apache/dolphinscheduler/pull/10981?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 [#10981](https://codecov.io/gh/apache/dolphinscheduler/pull/10981?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (64a512b) into [dev](https://codecov.io/gh/apache/dolphinscheduler/commit/25ded1e81b59a216275e6bbe26e0eb3e6f400f78?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (25ded1e) will **increase** coverage by `0.03%`.
> The diff coverage is `51.76%`.
```diff
@@ Coverage Diff @@
## dev #10981 +/- ##
============================================
+ Coverage 40.30% 40.33% +0.03%
- Complexity 4854 4880 +26
============================================
Files 943 946 +3
Lines 37055 37223 +168
Branches 4073 4084 +11
============================================
+ Hits 14935 15014 +79
- Misses 20612 20690 +78
- Partials 1508 1519 +11
```
| [Impacted Files](https://codecov.io/gh/apache/dolphinscheduler/pull/10981?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [...gin/registry/etcd/EtcdConnectionStateListener.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10981/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-ZG9scGhpbnNjaGVkdWxlci1yZWdpc3RyeS9kb2xwaGluc2NoZWR1bGVyLXJlZ2lzdHJ5LXBsdWdpbnMvZG9scGhpbnNjaGVkdWxlci1yZWdpc3RyeS1ldGNkL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kb2xwaGluc2NoZWR1bGVyL3BsdWdpbi9yZWdpc3RyeS9ldGNkL0V0Y2RDb25uZWN0aW9uU3RhdGVMaXN0ZW5lci5qYXZh) | `21.05% <21.05%> (ø)` | |
| [...inscheduler/plugin/registry/etcd/EtcdRegistry.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10981/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-ZG9scGhpbnNjaGVkdWxlci1yZWdpc3RyeS9kb2xwaGluc2NoZWR1bGVyLXJlZ2lzdHJ5LXBsdWdpbnMvZG9scGhpbnNjaGVkdWxlci1yZWdpc3RyeS1ldGNkL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kb2xwaGluc2NoZWR1bGVyL3BsdWdpbi9yZWdpc3RyeS9ldGNkL0V0Y2RSZWdpc3RyeS5qYXZh) | `58.67% <58.67%> (ø)` | |
| [...r/plugin/registry/etcd/EtcdRegistryProperties.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10981/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-ZG9scGhpbnNjaGVkdWxlci1yZWdpc3RyeS9kb2xwaGluc2NoZWR1bGVyLXJlZ2lzdHJ5LXBsdWdpbnMvZG9scGhpbnNjaGVkdWxlci1yZWdpc3RyeS1ldGNkL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9kb2xwaGluc2NoZWR1bGVyL3BsdWdpbi9yZWdpc3RyeS9ldGNkL0V0Y2RSZWdpc3RyeVByb3BlcnRpZXMuamF2YQ==) | `81.81% <81.81%> (ø)` | |
| [...erver/master/processor/queue/TaskEventService.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10981/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-ZG9scGhpbnNjaGVkdWxlci1tYXN0ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvc2VydmVyL21hc3Rlci9wcm9jZXNzb3IvcXVldWUvVGFza0V2ZW50U2VydmljZS5qYXZh) | `69.64% <0.00%> (-10.72%)` | :arrow_down: |
| [...er/master/dispatch/host/assign/RandomSelector.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10981/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-ZG9scGhpbnNjaGVkdWxlci1tYXN0ZXIvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvc2VydmVyL21hc3Rlci9kaXNwYXRjaC9ob3N0L2Fzc2lnbi9SYW5kb21TZWxlY3Rvci5qYXZh) | `77.77% <0.00%> (-5.56%)` | :arrow_down: |
| [...r/plugin/task/sqoop/parameter/SqoopParameters.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10981/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-ZG9scGhpbnNjaGVkdWxlci10YXNrLXBsdWdpbi9kb2xwaGluc2NoZWR1bGVyLXRhc2stc3Fvb3Avc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvcGx1Z2luL3Rhc2svc3Fvb3AvcGFyYW1ldGVyL1Nxb29wUGFyYW1ldGVycy5qYXZh) | `53.33% <0.00%> (-1.34%)` | :arrow_down: |
| [...pache/dolphinscheduler/common/utils/DateUtils.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10981/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-ZG9scGhpbnNjaGVkdWxlci1jb21tb24vc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvY29tbW9uL3V0aWxzL0RhdGVVdGlscy5qYXZh) | `74.83% <0.00%> (-0.17%)` | :arrow_down: |
| [.../dolphinscheduler/plugin/task/datax/DataxTask.java](https://codecov.io/gh/apache/dolphinscheduler/pull/10981/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-ZG9scGhpbnNjaGVkdWxlci10YXNrLXBsdWdpbi9kb2xwaGluc2NoZWR1bGVyLXRhc2stZGF0YXgvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2RvbHBoaW5zY2hlZHVsZXIvcGx1Z2luL3Rhc2svZGF0YXgvRGF0YXhUYXNrLmphdmE=) | `0.00% <0.00%> (ø)` | |
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1226987940
@caishunfeng Please pass the review, I have fixed the conflict. Thank you.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] ruanwenjun commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1231398706
@wjf222 Please resolve the dependency check failure.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1231595098
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [6 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [44.8% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1214290390
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [45.1% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] kezhenxu94 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r939604042
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import io.etcd.jetcd.Client;
+
+public class EtcdConnectionStateListener implements AutoCloseable {
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // monitored client
+ private final Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
Review Comment:
```suggestion
private volatile ConnectionState connectionState;
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import com.google.common.base.Splitter;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd cluster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
Review Comment:
```suggestion
private static final long TIME_TO_LIVE_SECONDS = 30L;
```
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] kezhenxu94 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1185117075
Many files are missing license headers
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1207215116
@kezhenxu94 @caishunfeng @ruanwenjun If there are no other comments, I hope to be able to agree to this PR
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r943310151
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import com.google.common.base.Splitter;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd cluster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (StringUtils.hasLength(registryProperties.getUser()) && StringUtils.hasLength(registryProperties.getPassword())) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (StringUtils.hasLength(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (StringUtils.hasLength(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get data error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get data error", e);
+ }
+ }
+
+ /**
+ *
+ * @param deleteOnDisconnect Does the put data disappear when the client disconnects
+ */
+ @Override
+ public void put(String key, String value, boolean deleteOnDisconnect) {
+ try {
+ if (deleteOnDisconnect) {
+ // keep the key by lease, if disconnected, the lease will expire and the key will delete
+ long leaseId = client.getLeaseClient().grant(TIME_TO_LIVE_SECONDS).get().getID();
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ PutOption putOption = PutOption.newBuilder().withLeaseId(leaseId).build();
+ client.getKVClient().put(byteSequence(key), byteSequence(value),putOption).get();
+ } else {
+ client.getKVClient().put(byteSequence(key), byteSequence(value)).get();
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ }
+ }
+
+ /**
+ * delete all keys that contain the prefix {@Code key}
+ */
+ @Override
+ public void delete(String key) {
+ try {
+ DeleteOption deleteOption = DeleteOption.newBuilder().isPrefix(true).build();
+ client.getKVClient().delete(byteSequence(key), deleteOption).get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to delete registry key: " + key, e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("Failed to delete registry key: " + key, e);
+ }
+ }
+
+ /**
+ * Get all child objects, split by "/"
+ */
+ @Override
+ public Collection<String> children(String key) {
+ // Make sure the string end with '/'
+ // eg:change key = /nodes to /nodes/
+ String prefix = key.endsWith(FOLDER_SEPARATOR) ? key : key + FOLDER_SEPARATOR;
+ GetOption getOption = GetOption.newBuilder().isPrefix(true).withSortField(GetOption.SortTarget.KEY).withSortOrder(GetOption.SortOrder.ASCEND).build();
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(prefix),getOption).get().getKvs();
+ return keyValues.stream().map(e -> getSubNodeKeyName(prefix, e.getKey().toString(StandardCharsets.UTF_8))).distinct().collect(Collectors.toList());
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get children error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get children error", e);
+ }
+ }
+
+ /**
+ * If "/" exists in the child object, get the string prefixed with "/"
+ */
+ private String getSubNodeKeyName(final String prefix, final String fullPath) {
+ String pathWithoutPrefix = fullPath.substring(prefix.length());
+ return pathWithoutPrefix.contains(FOLDER_SEPARATOR) ? pathWithoutPrefix.substring(0, pathWithoutPrefix.indexOf(FOLDER_SEPARATOR)) : pathWithoutPrefix;
+ }
+
+ @Override
+ public boolean exists(String key) {
+ GetOption getOption = GetOption.newBuilder().withCountOnly(true).build();
+ try {
+ if (client.getKVClient().get(byteSequence(key),getOption).get().getCount() >= 1) {
+ return true;
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd check key is existed error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd check key is existed error", e);
+ }
+ return false;
+ }
+
+ /**
+ * get the lock with a lease
+ */
+ @Override
+ public boolean acquireLock(String key) {
+ Lock lockClient = client.getLockClient();
+ Lease leaseClient = client.getLeaseClient();
+ // get the lock with a lease
+ try {
+ long leaseId = leaseClient.grant(TIME_TO_LIVE_SECONDS).get().getID();
+ // keep the lease
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ lockClient.lock(byteSequence(key),leaseId).get();
+
+ // save the leaseId for release Lock
+ if (null == threadLocalLockMap.get()) {
+ threadLocalLockMap.set(new HashMap<>());
+ }
+ threadLocalLockMap.get().put(key,leaseId);
+ return true;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get lock error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get lock error", e);
+ }
+ }
+
+ /**
+ * release the lock by revoking the leaseId
+ */
+ @Override
+ public boolean releaseLock(String key) {
+ try {
+ Long leaseId = threadLocalLockMap.get().get(key);
+ client.getLeaseClient().revoke(leaseId);
+ threadLocalLockMap.get().remove(key);
Review Comment:
If this is null, the remove function will throw an exception
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1211876464
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [45.9% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] caishunfeng commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
caishunfeng commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r933920182
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd CLuster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (!Strings.isNullOrEmpty(registryProperties.getUser()) && (!Strings.isNullOrEmpty(registryProperties.getPassword()))) {
Review Comment:
I only marked one place
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd CLuster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (!Strings.isNullOrEmpty(registryProperties.getUser()) && (!Strings.isNullOrEmpty(registryProperties.getPassword()))) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @param key
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException | ExecutionException e) {
Review Comment:
I only marked one place
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1217460870
> Generally looks good to me, please fix conflict
@kezhenxu94 Thanks, I have fixed the conflict
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1185248632
> Many files are missing license headers
I fixed this in the [Add license header](https://github.com/apache/dolphinscheduler/pull/10981/commits/65d0b9d78401478d0f15830b1f949e725771a20a)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] ruanwenjun commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r926524325
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import io.etcd.jetcd.Client;
+import io.grpc.ManagedChannel;
+
+/**
+ * Get the connection status by listening to the Client's Channel
+ */
+public class EtcdConnectionStateListener implements AutoCloseable {
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // Client's Channel
+ private AtomicReference<ManagedChannel> channel;
+ // monitored client
+ private Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
+ private long initialDelay = 500L;
+ private long delay = 500L;
+ public EtcdConnectionStateListener(Client client) {
+ this.client = client;
+ channel = new AtomicReference<>();
+ this.scheduledExecutorService = Executors.newScheduledThreadPool(
+ 1,
+ new ThreadFactoryBuilder().setNameFormat("EtcdConnectionStateListenerThread").setDaemon(true).build());
+ }
+
+ public void addConnectionListener(ConnectionListener connectionListener) {
+ connectionListeners.add(connectionListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connectionListeners.clear();
+ scheduledExecutorService.shutdownNow();
+ }
+
+ /**
+ * Apply for a lease through the client, if there is no exception, the connection is normal
+ * @return the current connection state
+ * @throws if there is a exception, return is DISCONNECTED
+ */
+ private ConnectionState isConnected() {
+ try {
+ // Use Get() to ensure Future completes
+ client.getLeaseClient().grant(1).get().getID();
+ return ConnectionState.CONNECTED;
+ } catch (Exception e) {
+ return ConnectionState.DISCONNECTED;
+ }
+ }
+
+ /**
+ * Periodically execute thread to get connection status
+ */
+ public void start() {
+ this.scheduledExecutorService.scheduleWithFixedDelay(() -> {
+ ConnectionState currentConnectionState = isConnected();
+ if (currentConnectionState == connectionState) {
+ return;
+ }
+ if (connectionState == ConnectionState.CONNECTED) {
+ if (currentConnectionState == ConnectionState.DISCONNECTED) {
+ connectionState = ConnectionState.DISCONNECTED;
+ triggerListener(ConnectionState.DISCONNECTED);
+ }
+ } else if (connectionState == ConnectionState.DISCONNECTED) {
+ if (currentConnectionState == ConnectionState.CONNECTED) {
+ connectionState = ConnectionState.CONNECTED;
+ triggerListener(ConnectionState.RECONNECTED);
+ }
+ } else if (connectionState == null) {
+ connectionState = currentConnectionState;
+ triggerListener(connectionState);
+ }
Review Comment:
Yes, in fact, for all state changes, we need to notify the listener.
I wrote these logic in MysqlRegistry, since we need to generate `ConnectionState.RECONNECTED` state :), but the state we story in memory is just `RECONNECTED` and `RECONNECTED`.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1236063169
@kezhenxu94 @caishunfeng @ruanwenjun I have passed the test.Please apprve the review.Thank you.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1236618466
@kezhenxu94 @caishunfeng @ruanwenjun I have passed the test.Please apprve the review.Thank you.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] caishunfeng commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
caishunfeng commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1223841615
@wjf222 Please fix the conflicts.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1207213607
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [46.2% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] ruanwenjun commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
ruanwenjun commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r939603219
##########
dolphinscheduler-bom/pom.xml:
##########
@@ -247,6 +250,25 @@
<version>${curator-test.version}</version>
</dependency>
+ <!-- Etcd -->
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-core</artifactId>
+ <version>${jetcd.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-test</artifactId>
+ <version>${jetcd.test.version}</version>
Review Comment:
if this is only used in UT, please change the scope to test.
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/README.md:
##########
@@ -0,0 +1,27 @@
+# Introduction
+
+This module is the etcd registry plugin module, this plugin will use etcd as the registry center.
+
+# How to use
+
+If you want to set the registry center as mysql,you need to set the registry properties in master/worker/api's appplication.yml
Review Comment:
```suggestion
If you want to set the registry center as zookeeper, you need to set the registry properties in master/worker/api's appplication.yml
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/README.md:
##########
@@ -0,0 +1,27 @@
+# Introduction
+
+This module is the etcd registry plugin module, this plugin will use etcd as the registry center.
Review Comment:
```suggestion
This module is the zookeeper registry plugin module, this plugin will use zookeeper as the registry center.
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/test/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistryTest.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.etcd.jetcd.test.EtcdClusterExtension;
+
+public class EtcdRegistryTest {
+ private static final Logger logger = LoggerFactory.getLogger(EtcdRegistryTest.class);
+
+ @RegisterExtension
+ public static final EtcdClusterExtension server = EtcdClusterExtension.builder()
+ .withNodes(1)
+ .withImage("ibmcom/etcd:3.2.24")
+ .build();
+ public static EtcdRegistry registry;
+
+ @BeforeClass
+ public static void before() throws Exception {
+ EtcdRegistryProperties properties = new EtcdRegistryProperties();
+ server.restart();
+ properties.setEndpoints(String.valueOf(server.clientEndpoints().get(0)));
+ registry = new EtcdRegistry(properties);
+ registry.put("/sub", "sub", false);
+ }
+
+ @Test
+ public void persistTest() {
+ registry.put("/nodes/m1", "", false);
+ registry.put("/nodes/m2", "", false);
+ Assert.assertEquals(Arrays.asList("m1", "m2"), registry.children("/nodes"));
+ Assert.assertTrue(registry.exists("/nodes/m1"));
+ registry.delete("/nodes/m2");
+ Assert.assertFalse(registry.exists("/nodes/m2"));
+ registry.delete("/nodes");
+ Assert.assertFalse(registry.exists("/nodes/m1"));
+ }
+
+ @Test
+ public void lockTest() {
+ CountDownLatch preCountDownLatch = new CountDownLatch(1);
+ CountDownLatch allCountDownLatch = new CountDownLatch(2);
+ List<String> testData = new ArrayList<>();
+ new Thread(() -> {
+ registry.acquireLock("/lock");
+ preCountDownLatch.countDown();
+ logger.info(Thread.currentThread().getName() + " :I got the lock, but I don't want to work. I want to rest for a while");
+ try {
+ Thread.sleep(1000);
+ logger.info(Thread.currentThread().getName() + " :I'm going to start working");
+ testData.add("thread1");
+
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ } finally {
+ logger.info(Thread.currentThread().getName() + " :I have finished my work, now I release the lock");
+ registry.releaseLock("/lock");
+ allCountDownLatch.countDown();
+ }
+ }).start();
+ try {
+ preCountDownLatch.await();
Review Comment:
Please add timeout.
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import com.google.common.base.Splitter;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd cluster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (StringUtils.hasLength(registryProperties.getUser()) && StringUtils.hasLength(registryProperties.getPassword())) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (StringUtils.hasLength(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (StringUtils.hasLength(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get data error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get data error", e);
+ }
+ }
+
+ /**
+ *
+ * @param deleteOnDisconnect Does the put data disappear when the client disconnects
+ */
+ @Override
+ public void put(String key, String value, boolean deleteOnDisconnect) {
+ try {
+ if (deleteOnDisconnect) {
+ // keep the key by lease, if disconnected, the lease will expire and the key will delete
+ long leaseId = client.getLeaseClient().grant(TIME_TO_LIVE_SECONDS).get().getID();
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ PutOption putOption = PutOption.newBuilder().withLeaseId(leaseId).build();
+ client.getKVClient().put(byteSequence(key), byteSequence(value),putOption).get();
+ } else {
+ client.getKVClient().put(byteSequence(key), byteSequence(value)).get();
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ }
+ }
+
+ /**
+ * delete all keys that contain the prefix {@Code key}
+ */
+ @Override
+ public void delete(String key) {
+ try {
+ DeleteOption deleteOption = DeleteOption.newBuilder().isPrefix(true).build();
+ client.getKVClient().delete(byteSequence(key), deleteOption).get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to delete registry key: " + key, e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("Failed to delete registry key: " + key, e);
+ }
+ }
+
+ /**
+ * Get all child objects, split by "/"
+ */
+ @Override
+ public Collection<String> children(String key) {
+ // Make sure the string end with '/'
+ // eg:change key = /nodes to /nodes/
+ String prefix = key.endsWith(FOLDER_SEPARATOR) ? key : key + FOLDER_SEPARATOR;
+ GetOption getOption = GetOption.newBuilder().isPrefix(true).withSortField(GetOption.SortTarget.KEY).withSortOrder(GetOption.SortOrder.ASCEND).build();
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(prefix),getOption).get().getKvs();
+ return keyValues.stream().map(e -> getSubNodeKeyName(prefix, e.getKey().toString(StandardCharsets.UTF_8))).distinct().collect(Collectors.toList());
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get children error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get children error", e);
+ }
+ }
+
+ /**
+ * If "/" exists in the child object, get the string prefixed with "/"
+ */
+ private String getSubNodeKeyName(final String prefix, final String fullPath) {
+ String pathWithoutPrefix = fullPath.substring(prefix.length());
+ return pathWithoutPrefix.contains(FOLDER_SEPARATOR) ? pathWithoutPrefix.substring(0, pathWithoutPrefix.indexOf(FOLDER_SEPARATOR)) : pathWithoutPrefix;
+ }
+
+ @Override
+ public boolean exists(String key) {
+ GetOption getOption = GetOption.newBuilder().withCountOnly(true).build();
+ try {
+ if (client.getKVClient().get(byteSequence(key),getOption).get().getCount() >= 1) {
+ return true;
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd check key is existed error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd check key is existed error", e);
Review Comment:
```suggestion
throw new RegistryException("etcd check key is existed error, key: " + key, e);
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import com.google.common.base.Splitter;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd cluster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (StringUtils.hasLength(registryProperties.getUser()) && StringUtils.hasLength(registryProperties.getPassword())) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (StringUtils.hasLength(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (StringUtils.hasLength(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get data error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get data error", e);
+ }
+ }
+
+ /**
+ *
+ * @param deleteOnDisconnect Does the put data disappear when the client disconnects
+ */
+ @Override
+ public void put(String key, String value, boolean deleteOnDisconnect) {
+ try {
+ if (deleteOnDisconnect) {
+ // keep the key by lease, if disconnected, the lease will expire and the key will delete
+ long leaseId = client.getLeaseClient().grant(TIME_TO_LIVE_SECONDS).get().getID();
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ PutOption putOption = PutOption.newBuilder().withLeaseId(leaseId).build();
+ client.getKVClient().put(byteSequence(key), byteSequence(value),putOption).get();
+ } else {
+ client.getKVClient().put(byteSequence(key), byteSequence(value)).get();
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ }
+ }
+
+ /**
+ * delete all keys that contain the prefix {@Code key}
+ */
+ @Override
+ public void delete(String key) {
+ try {
+ DeleteOption deleteOption = DeleteOption.newBuilder().isPrefix(true).build();
+ client.getKVClient().delete(byteSequence(key), deleteOption).get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to delete registry key: " + key, e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("Failed to delete registry key: " + key, e);
+ }
+ }
+
+ /**
+ * Get all child objects, split by "/"
+ */
+ @Override
+ public Collection<String> children(String key) {
+ // Make sure the string end with '/'
+ // eg:change key = /nodes to /nodes/
+ String prefix = key.endsWith(FOLDER_SEPARATOR) ? key : key + FOLDER_SEPARATOR;
+ GetOption getOption = GetOption.newBuilder().isPrefix(true).withSortField(GetOption.SortTarget.KEY).withSortOrder(GetOption.SortOrder.ASCEND).build();
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(prefix),getOption).get().getKvs();
+ return keyValues.stream().map(e -> getSubNodeKeyName(prefix, e.getKey().toString(StandardCharsets.UTF_8))).distinct().collect(Collectors.toList());
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get children error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get children error", e);
+ }
+ }
+
+ /**
+ * If "/" exists in the child object, get the string prefixed with "/"
+ */
+ private String getSubNodeKeyName(final String prefix, final String fullPath) {
+ String pathWithoutPrefix = fullPath.substring(prefix.length());
+ return pathWithoutPrefix.contains(FOLDER_SEPARATOR) ? pathWithoutPrefix.substring(0, pathWithoutPrefix.indexOf(FOLDER_SEPARATOR)) : pathWithoutPrefix;
+ }
+
+ @Override
+ public boolean exists(String key) {
+ GetOption getOption = GetOption.newBuilder().withCountOnly(true).build();
+ try {
+ if (client.getKVClient().get(byteSequence(key),getOption).get().getCount() >= 1) {
+ return true;
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd check key is existed error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd check key is existed error", e);
+ }
+ return false;
+ }
+
+ /**
+ * get the lock with a lease
+ */
+ @Override
+ public boolean acquireLock(String key) {
+ Lock lockClient = client.getLockClient();
+ Lease leaseClient = client.getLeaseClient();
+ // get the lock with a lease
+ try {
+ long leaseId = leaseClient.grant(TIME_TO_LIVE_SECONDS).get().getID();
+ // keep the lease
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ lockClient.lock(byteSequence(key),leaseId).get();
+
+ // save the leaseId for release Lock
+ if (null == threadLocalLockMap.get()) {
+ threadLocalLockMap.set(new HashMap<>());
+ }
+ threadLocalLockMap.get().put(key,leaseId);
+ return true;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get lock error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get lock error", e);
+ }
+ }
+
+ /**
+ * release the lock by revoking the leaseId
+ */
+ @Override
+ public boolean releaseLock(String key) {
+ try {
+ Long leaseId = threadLocalLockMap.get().get(key);
+ client.getLeaseClient().revoke(leaseId);
+ threadLocalLockMap.get().remove(key);
Review Comment:
Do we need to check if the `threadLocalLockMap.get()` will null?
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import com.google.common.base.Splitter;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd cluster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (StringUtils.hasLength(registryProperties.getUser()) && StringUtils.hasLength(registryProperties.getPassword())) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (StringUtils.hasLength(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (StringUtils.hasLength(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get data error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get data error", e);
+ }
+ }
+
+ /**
+ *
+ * @param deleteOnDisconnect Does the put data disappear when the client disconnects
+ */
+ @Override
+ public void put(String key, String value, boolean deleteOnDisconnect) {
+ try {
+ if (deleteOnDisconnect) {
+ // keep the key by lease, if disconnected, the lease will expire and the key will delete
+ long leaseId = client.getLeaseClient().grant(TIME_TO_LIVE_SECONDS).get().getID();
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ PutOption putOption = PutOption.newBuilder().withLeaseId(leaseId).build();
+ client.getKVClient().put(byteSequence(key), byteSequence(value),putOption).get();
+ } else {
+ client.getKVClient().put(byteSequence(key), byteSequence(value)).get();
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ }
+ }
+
+ /**
+ * delete all keys that contain the prefix {@Code key}
+ */
+ @Override
+ public void delete(String key) {
+ try {
+ DeleteOption deleteOption = DeleteOption.newBuilder().isPrefix(true).build();
+ client.getKVClient().delete(byteSequence(key), deleteOption).get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to delete registry key: " + key, e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("Failed to delete registry key: " + key, e);
+ }
+ }
+
+ /**
+ * Get all child objects, split by "/"
+ */
+ @Override
+ public Collection<String> children(String key) {
+ // Make sure the string end with '/'
+ // eg:change key = /nodes to /nodes/
+ String prefix = key.endsWith(FOLDER_SEPARATOR) ? key : key + FOLDER_SEPARATOR;
+ GetOption getOption = GetOption.newBuilder().isPrefix(true).withSortField(GetOption.SortTarget.KEY).withSortOrder(GetOption.SortOrder.ASCEND).build();
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(prefix),getOption).get().getKvs();
+ return keyValues.stream().map(e -> getSubNodeKeyName(prefix, e.getKey().toString(StandardCharsets.UTF_8))).distinct().collect(Collectors.toList());
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get children error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get children error", e);
+ }
+ }
+
+ /**
+ * If "/" exists in the child object, get the string prefixed with "/"
+ */
+ private String getSubNodeKeyName(final String prefix, final String fullPath) {
+ String pathWithoutPrefix = fullPath.substring(prefix.length());
+ return pathWithoutPrefix.contains(FOLDER_SEPARATOR) ? pathWithoutPrefix.substring(0, pathWithoutPrefix.indexOf(FOLDER_SEPARATOR)) : pathWithoutPrefix;
+ }
+
+ @Override
+ public boolean exists(String key) {
+ GetOption getOption = GetOption.newBuilder().withCountOnly(true).build();
+ try {
+ if (client.getKVClient().get(byteSequence(key),getOption).get().getCount() >= 1) {
+ return true;
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd check key is existed error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd check key is existed error", e);
+ }
+ return false;
+ }
+
+ /**
+ * get the lock with a lease
+ */
+ @Override
+ public boolean acquireLock(String key) {
+ Lock lockClient = client.getLockClient();
+ Lease leaseClient = client.getLeaseClient();
+ // get the lock with a lease
+ try {
+ long leaseId = leaseClient.grant(TIME_TO_LIVE_SECONDS).get().getID();
+ // keep the lease
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ lockClient.lock(byteSequence(key),leaseId).get();
+
+ // save the leaseId for release Lock
+ if (null == threadLocalLockMap.get()) {
+ threadLocalLockMap.set(new HashMap<>());
+ }
+ threadLocalLockMap.get().put(key,leaseId);
+ return true;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get lock error", e);
+ } catch (ExecutionException e) {
+ throw new RegistryException("etcd get lock error", e);
Review Comment:
```suggestion
throw new RegistryException("etcd get lock error, lockKey: " + key, e);
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import com.google.common.base.Splitter;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd cluster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
Review Comment:
```suggestion
```
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1191206267
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [37.3% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1214291916
@kezhenxu94 @caishunfeng @ruanwenjun Please help continue to review. Thank you very much
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r933956733
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd CLuster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (!Strings.isNullOrEmpty(registryProperties.getUser()) && (!Strings.isNullOrEmpty(registryProperties.getPassword()))) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @param key
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException | ExecutionException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get data error", e);
+ }
+ }
+
+ /**
+ *
+ * @param key
+ * @param value
+ * @param deleteOnDisconnect Does the put data disappear when the client disconnects
+ */
+ @Override
+ public void put(String key, String value, boolean deleteOnDisconnect) {
+ try {
+ if (deleteOnDisconnect) {
+ // keep the key by lease, if disconnected, the lease will expire and the key will delete
+ long leaseId = client.getLeaseClient().grant(TIME_TO_LIVE_SECONDS).get().getID();
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ PutOption putOption = PutOption.newBuilder().withLeaseId(leaseId).build();
+ client.getKVClient().put(byteSequence(key), byteSequence(value),putOption).get();
+ } else {
+ client.getKVClient().put(byteSequence(key), byteSequence(value)).get();
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ }
+ }
+
+ /**
+ * delete all keys that contain the prefix
+ * @param key the prrefix
+ */
+ @Override
+ public void delete(String key) {
Review Comment:
This is a function from the Registry interface, maybe we can start an Issue to see other people's opinions
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] MichaelDeSteven commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
MichaelDeSteven commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r934455681
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,338 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+
+import com.google.common.base.Splitter;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd CLuster to
Review Comment:
```suggestion
* This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd cluster to
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import io.etcd.jetcd.Client;
+
+public class EtcdConnectionStateListener implements AutoCloseable {
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // monitored client
+ private final Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
+
+ public EtcdConnectionStateListener(Client client) {
+ this.client = client;
+ this.scheduledExecutorService = Executors.newScheduledThreadPool(
+ 1,
+ new ThreadFactoryBuilder().setNameFormat("EtcdConnectionStateListenerThread").setDaemon(true).build());
+ }
+
+ public void addConnectionListener(ConnectionListener connectionListener) {
+ connectionListeners.add(connectionListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connectionListeners.clear();
+ scheduledExecutorService.shutdownNow();
+ }
+
+ /**
+ * Apply for a lease through the client, if there is no exception, the connection is normal
+ * @return the current connection state
+ * @throws if there is an exception, return is DISCONNECTED
+ */
+ private ConnectionState currentConnectivityState() {
+ try {
+ client.getLeaseClient().grant(1).get().getID();
+ return ConnectionState.CONNECTED;
+ } catch (ExecutionException e) {
+ return ConnectionState.DISCONNECTED;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return ConnectionState.DISCONNECTED;
+ }
+ }
+
+ /**
+ * Periodically execute thread to get connection status
+ */
+ public void start() {
+ long initialDelay = 500L;
Review Comment:
why don‘t we design to make it configurable
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1211876335
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [45.9% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r935087863
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import io.etcd.jetcd.Client;
+
+public class EtcdConnectionStateListener implements AutoCloseable {
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // monitored client
+ private final Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
+
+ public EtcdConnectionStateListener(Client client) {
+ this.client = client;
+ this.scheduledExecutorService = Executors.newScheduledThreadPool(
+ 1,
+ new ThreadFactoryBuilder().setNameFormat("EtcdConnectionStateListenerThread").setDaemon(true).build());
+ }
+
+ public void addConnectionListener(ConnectionListener connectionListener) {
+ connectionListeners.add(connectionListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connectionListeners.clear();
+ scheduledExecutorService.shutdownNow();
+ }
+
+ /**
+ * Apply for a lease through the client, if there is no exception, the connection is normal
+ * @return the current connection state
+ * @throws if there is an exception, return is DISCONNECTED
+ */
+ private ConnectionState currentConnectivityState() {
+ try {
+ client.getLeaseClient().grant(1).get().getID();
+ return ConnectionState.CONNECTED;
+ } catch (ExecutionException e) {
+ return ConnectionState.DISCONNECTED;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return ConnectionState.DISCONNECTED;
+ }
+ }
+
+ /**
+ * Periodically execute thread to get connection status
+ */
+ public void start() {
+ long initialDelay = 500L;
Review Comment:
This parameter is only used inside this function and has nothing to do with etcD clusters.So I didn't make it configurable
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1185519807
> Hi @wjf222 please add the doc of the registry together.
I add the doc in [[Document] Add readme and comments](https://github.com/apache/dolphinscheduler/pull/10981/commits/48dc9982af58b5015110469c3857312de858d0c4).Do you need to add other documents 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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1200426590
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [35.2% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1200425878
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [35.2% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1232401823
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [6 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [44.8% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1232407961
> @wjf222 Please resolve the dependency check failure.
@ruanwenjun I have fixed the conflict. Thank you.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] ruanwenjun merged pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
ruanwenjun merged PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] caishunfeng commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
caishunfeng commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1185216415
Hi @wjf222 please add the doc of the registry together.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1191020036
SonarCloud Quality Gate failed. [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [7 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [38.4% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1230212108
@kezhenxu94 @caishunfeng @ruanwenjun Due to previous conflicts, modifications have been made, and I hope to pass this review again. Thank you very much.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r921877160
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistryProperties.java:
##########
@@ -0,0 +1,31 @@
+package org.apache.dolphinscheduler.plugin.registry.etcd;
+
+import lombok.Data;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.time.Duration;
+
+@Data
+@Configuration
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+@ConfigurationProperties(prefix = "registry")
+public class EtcdRegistryProperties {
+ private String endpoints;
+ private String namespace="dolphinscheduler";
+ private Duration connectionTimeout = Duration.ofSeconds(9);
+
+ // auth
+ private String user;
+ private String password;
+ private String authority;
+
+ // RetryPolicy
+ private Long retryDelay=60L;
+ private Long retryMaxDelay=300L;
Review Comment:
> > The time unit for these two parameters is set by the ChronUnitRetry in jetcd. The type of these two parameters is long, but the type of retryMaxDuration is Duration.
> > You can see the reference of these three parameters in EtcdRegistry.java line 51 to 54.
>
> Hi, you don't have to just copy the type from JETCD client, using `Duration` as type in our own configurations is for users' convenient, they can just set something like `1s`, `500ms`, without knowing what's the time unit of the config. Also, users don't care what types we pass into `EtcdRegistry.java`, let's provide simplicity to users
You are right,I fix this in [Modify the type of delay](https://github.com/apache/dolphinscheduler/pull/10981/commits/ba5f7687f8842427e4fea67b56f7f1125e48b9d4)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1200095989
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [37.3% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1200095369
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [37.3% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1200096634
@kezhenxu94 @caishunfeng @ruanwenjun Hello, my PR has now passed the test, please help to review it, thank you very much
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] caishunfeng commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
caishunfeng commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r933918952
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd CLuster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (!Strings.isNullOrEmpty(registryProperties.getUser()) && (!Strings.isNullOrEmpty(registryProperties.getPassword()))) {
Review Comment:
```suggestion
if (StringUtils.isNotEmpty(registryProperties.getUser()) && (StringUtils.isNotEmpty(registryProperties.getPassword()))) {
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/test/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistryTest.java:
##########
@@ -0,0 +1,141 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.etcd.jetcd.test.EtcdClusterExtension;
+
+public class EtcdRegistryTest {
Review Comment:
:+1:
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd CLuster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (!Strings.isNullOrEmpty(registryProperties.getUser()) && (!Strings.isNullOrEmpty(registryProperties.getPassword()))) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @param key
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException | ExecutionException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get data error", e);
+ }
+ }
+
+ /**
+ *
+ * @param key
+ * @param value
+ * @param deleteOnDisconnect Does the put data disappear when the client disconnects
+ */
+ @Override
+ public void put(String key, String value, boolean deleteOnDisconnect) {
+ try {
+ if (deleteOnDisconnect) {
+ // keep the key by lease, if disconnected, the lease will expire and the key will delete
+ long leaseId = client.getLeaseClient().grant(TIME_TO_LIVE_SECONDS).get().getID();
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ PutOption putOption = PutOption.newBuilder().withLeaseId(leaseId).build();
+ client.getKVClient().put(byteSequence(key), byteSequence(value),putOption).get();
+ } else {
+ client.getKVClient().put(byteSequence(key), byteSequence(value)).get();
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ }
+ }
+
+ /**
+ * delete all keys that contain the prefix
+ * @param key the prrefix
Review Comment:
```suggestion
* @param the key prefix
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd CLuster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (!Strings.isNullOrEmpty(registryProperties.getUser()) && (!Strings.isNullOrEmpty(registryProperties.getPassword()))) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @param key
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException | ExecutionException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("etcd get data error", e);
+ }
+ }
+
+ /**
+ *
+ * @param key
+ * @param value
+ * @param deleteOnDisconnect Does the put data disappear when the client disconnects
+ */
+ @Override
+ public void put(String key, String value, boolean deleteOnDisconnect) {
+ try {
+ if (deleteOnDisconnect) {
+ // keep the key by lease, if disconnected, the lease will expire and the key will delete
+ long leaseId = client.getLeaseClient().grant(TIME_TO_LIVE_SECONDS).get().getID();
+ client.getLeaseClient().keepAlive(leaseId, Observers.observer(response -> {
+ }));
+ PutOption putOption = PutOption.newBuilder().withLeaseId(leaseId).build();
+ client.getKVClient().put(byteSequence(key), byteSequence(value),putOption).get();
+ } else {
+ client.getKVClient().put(byteSequence(key), byteSequence(value)).get();
+ }
+ } catch (InterruptedException | ExecutionException e) {
+ Thread.currentThread().interrupt();
+ throw new RegistryException("Failed to put registry key: " + key, e);
+ }
+ }
+
+ /**
+ * delete all keys that contain the prefix
+ * @param key the prrefix
+ */
+ @Override
+ public void delete(String key) {
Review Comment:
It's better to use the more precise method name, such as `deleteByPrefix(String keyPrefix)`
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistry.java:
##########
@@ -0,0 +1,344 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.Event;
+import org.apache.dolphinscheduler.registry.api.Registry;
+import org.apache.dolphinscheduler.registry.api.RegistryException;
+import org.apache.dolphinscheduler.registry.api.SubscribeListener;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+
+import javax.annotation.PostConstruct;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+
+import io.etcd.jetcd.ByteSequence;
+import io.etcd.jetcd.Client;
+import io.etcd.jetcd.ClientBuilder;
+import io.etcd.jetcd.KeyValue;
+import io.etcd.jetcd.Lease;
+import io.etcd.jetcd.Lock;
+import io.etcd.jetcd.Util;
+import io.etcd.jetcd.Watch;
+import io.etcd.jetcd.options.DeleteOption;
+import io.etcd.jetcd.options.GetOption;
+import io.etcd.jetcd.options.PutOption;
+import io.etcd.jetcd.options.WatchOption;
+import io.etcd.jetcd.support.Observers;
+import io.etcd.jetcd.watch.WatchEvent;
+
+/**
+ * This is one of the implementation of {@link Registry}, with this implementation, you need to rely on Etcd CLuster to
+ * store the DolphinScheduler master/worker's metadata and do the server registry/unRegistry.
+ */
+@Component
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+public class EtcdRegistry implements Registry {
+ private static Logger LOGGER = LoggerFactory.getLogger(EtcdRegistry.class);
+ private final Client client;
+ private EtcdConnectionStateListener etcdConnectionStateListener;
+ public static final String FOLDER_SEPARATOR = "/";
+ // save the lock info for thread
+ // key:lockKey Value:leaseId
+ private static final ThreadLocal<Map<String, Long>> threadLocalLockMap = new ThreadLocal<>();
+
+ private final Map<String, Watch.Watcher> watcherMap = new ConcurrentHashMap<>();
+
+ private static Long TIME_TO_LIVE_SECONDS = 30L;
+ public EtcdRegistry(EtcdRegistryProperties registryProperties) {
+ LOGGER.info("Starting Etcd Registry...");
+ ClientBuilder clientBuilder = Client.builder()
+ .endpoints(Util.toURIs(Splitter.on(",").trimResults().splitToList(registryProperties.getEndpoints())))
+ .namespace(byteSequence(registryProperties.getNamespace()))
+ .connectTimeout(registryProperties.getConnectionTimeout())
+ .retryChronoUnit(ChronoUnit.MILLIS)
+ .retryDelay(registryProperties.getRetryDelay().toMillis())
+ .retryMaxDelay(registryProperties.getRetryMaxDelay().toMillis())
+ .retryMaxDuration(registryProperties.getRetryMaxDuration());
+ if (!Strings.isNullOrEmpty(registryProperties.getUser()) && (!Strings.isNullOrEmpty(registryProperties.getPassword()))) {
+ clientBuilder.user(byteSequence(registryProperties.getUser()));
+ clientBuilder.password(byteSequence(registryProperties.getPassword()));
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getLoadBalancerPolicy())) {
+ clientBuilder.loadBalancerPolicy(registryProperties.getLoadBalancerPolicy());
+ }
+ if (!Strings.isNullOrEmpty(registryProperties.getAuthority())) {
+ clientBuilder.authority(registryProperties.getAuthority());
+ }
+ client = clientBuilder.build();
+ LOGGER.info("Started Etcd Registry...");
+ etcdConnectionStateListener = new EtcdConnectionStateListener(client);
+ }
+
+ /**
+ * Start the etcd Connection stateListeer
+ */
+ @PostConstruct
+ public void start() {
+ LOGGER.info("Starting Etcd ConnectionListener...");
+ etcdConnectionStateListener.start();
+ LOGGER.info("Started Etcd ConnectionListener...");
+ }
+
+ /**
+ *
+ * @param path The prefix of the key being listened to
+ * @param listener
+ * @return if subcribe Returns true if no exception was thrown
+ */
+ @Override
+ public boolean subscribe(String path, SubscribeListener listener) {
+ try {
+ ByteSequence watchKey = byteSequence(path);
+ WatchOption watchOption = WatchOption.newBuilder().isPrefix(true).build();
+ watcherMap.computeIfAbsent(path, $ -> client.getWatchClient().watch(watchKey, watchOption,watchResponse -> {
+ for (WatchEvent event : watchResponse.getEvents()) {
+ listener.notify(new EventAdaptor(event, path));
+ }
+ }));
+ } catch (Exception e) {
+ throw new RegistryException("Failed to subscribe listener for key: " + path, e);
+ }
+ return true;
+ }
+
+ /**
+ * @throws throws an exception if the unsubscribe path does not exist
+ * @param path The prefix of the key being listened to
+ */
+ @Override
+ public void unsubscribe(String path) {
+ try {
+ watcherMap.get(path).close();
+ watcherMap.remove(path);
+ } catch (Exception e) {
+ throw new RegistryException("Failed to unsubscribe listener for key: " + path, e);
+ }
+ }
+
+ @Override
+ public void addConnectionStateListener(ConnectionListener listener) {
+ etcdConnectionStateListener.addConnectionListener(listener);
+ }
+
+ /**
+ *
+ * @param key
+ * @return Returns the value corresponding to the key
+ * @throws throws an exception if the key does not exist
+ */
+ @Override
+ public String get(String key) {
+ try {
+ List<KeyValue> keyValues = client.getKVClient().get(byteSequence(key)).get().getKvs();
+ return keyValues.iterator().next().getValue().toString(StandardCharsets.UTF_8);
+ } catch (InterruptedException | ExecutionException e) {
Review Comment:
If throw ExecutionException, should we call `Thread.currentThread().interrupt()`? It's better to handle separately, WDYT?
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1217406152
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [6 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [44.8% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1217407358
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [6 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [44.8% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] kezhenxu94 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r921744266
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/pom.xml:
##########
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>dolphinscheduler-registry-plugins</artifactId>
+ <groupId>org.apache.dolphinscheduler</groupId>
+ <version>dev-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dolphinscheduler-registry-etcd</artifactId>
+
+ <properties>
+ <maven.compiler.source>8</maven.compiler.source>
+ <maven.compiler.target>8</maven.compiler.target>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dolphinscheduler</groupId>
+ <artifactId>dolphinscheduler-registry-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dolphinscheduler</groupId>
+ <artifactId>dolphinscheduler-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>io.etcd</groupId>
+ <artifactId>jetcd-test</artifactId>
+ </dependency>
Review Comment:
This should be `test` scope
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/pom.xml:
##########
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>dolphinscheduler-registry-plugins</artifactId>
+ <groupId>org.apache.dolphinscheduler</groupId>
+ <version>dev-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dolphinscheduler-registry-etcd</artifactId>
+
+ <properties>
+ <maven.compiler.source>8</maven.compiler.source>
+ <maven.compiler.target>8</maven.compiler.target>
+ </properties>
Review Comment:
Don't set this here
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistryProperties.java:
##########
@@ -0,0 +1,31 @@
+package org.apache.dolphinscheduler.plugin.registry.etcd;
+
+import lombok.Data;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.time.Duration;
+
+@Data
+@Configuration
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+@ConfigurationProperties(prefix = "registry")
+public class EtcdRegistryProperties {
+ private String endpoints;
+ private String namespace="dolphinscheduler";
+ private Duration connectionTimeout = Duration.ofSeconds(9);
+
+ // auth
+ private String user;
+ private String password;
+ private String authority;
+
+ // RetryPolicy
+ private Long retryDelay=60L;
+ private Long retryMaxDelay=300L;
+ private Duration retryMaxDuration=Duration.ofMillis(1500);;
Review Comment:
```suggestion
private Duration retryMaxDuration=Duration.ofMillis(1500);
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistryProperties.java:
##########
@@ -0,0 +1,31 @@
+package org.apache.dolphinscheduler.plugin.registry.etcd;
+
+import lombok.Data;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.time.Duration;
+
+@Data
+@Configuration
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+@ConfigurationProperties(prefix = "registry")
+public class EtcdRegistryProperties {
+ private String endpoints;
+ private String namespace="dolphinscheduler";
+ private Duration connectionTimeout = Duration.ofSeconds(9);
+
+ // auth
+ private String user;
+ private String password;
+ private String authority;
+
+ // RetryPolicy
+ private Long retryDelay=60L;
+ private Long retryMaxDelay=300L;
Review Comment:
Consider also using `Duration` type, and format the codes please.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r921751990
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdRegistryProperties.java:
##########
@@ -0,0 +1,31 @@
+package org.apache.dolphinscheduler.plugin.registry.etcd;
+
+import lombok.Data;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+import java.time.Duration;
+
+@Data
+@Configuration
+@ConditionalOnProperty(prefix = "registry", name = "type", havingValue = "etcd")
+@ConfigurationProperties(prefix = "registry")
+public class EtcdRegistryProperties {
+ private String endpoints;
+ private String namespace="dolphinscheduler";
+ private Duration connectionTimeout = Duration.ofSeconds(9);
+
+ // auth
+ private String user;
+ private String password;
+ private String authority;
+
+ // RetryPolicy
+ private Long retryDelay=60L;
+ private Long retryMaxDelay=300L;
Review Comment:
The time unit for these two parameters is set by the ChronUnitRetry in jetcd. The type of these two parameters is long, but the type of retryMaxDuration is Duration.
You can see the reference of these three parameters in EtcdRegistry.java line 51 to 54.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1201994366
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [35.2% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r935087863
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import io.etcd.jetcd.Client;
+
+public class EtcdConnectionStateListener implements AutoCloseable {
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // monitored client
+ private final Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
+
+ public EtcdConnectionStateListener(Client client) {
+ this.client = client;
+ this.scheduledExecutorService = Executors.newScheduledThreadPool(
+ 1,
+ new ThreadFactoryBuilder().setNameFormat("EtcdConnectionStateListenerThread").setDaemon(true).build());
+ }
+
+ public void addConnectionListener(ConnectionListener connectionListener) {
+ connectionListeners.add(connectionListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connectionListeners.clear();
+ scheduledExecutorService.shutdownNow();
+ }
+
+ /**
+ * Apply for a lease through the client, if there is no exception, the connection is normal
+ * @return the current connection state
+ * @throws if there is an exception, return is DISCONNECTED
+ */
+ private ConnectionState currentConnectivityState() {
+ try {
+ client.getLeaseClient().grant(1).get().getID();
+ return ConnectionState.CONNECTED;
+ } catch (ExecutionException e) {
+ return ConnectionState.DISCONNECTED;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ return ConnectionState.DISCONNECTED;
+ }
+ }
+
+ /**
+ * Periodically execute thread to get connection status
+ */
+ public void start() {
+ long initialDelay = 500L;
Review Comment:
This parameter is only used inside this function and has nothing to do with etcd clusters.So I didn't make it configurable
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1191022078
SonarCloud Quality Gate failed. [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [7 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [38.4% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] kezhenxu94 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r922597330
##########
dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/Event.java:
##########
@@ -20,9 +20,13 @@
package org.apache.dolphinscheduler.registry.api;
public class Event {
+ // The prefix which is watched
private String key;
+ // The full path where the event was generated
private String path;
+ // The value corresponding to the path
private String data;
+ // The event type {ADD, REMOVE ,UPDATE}
Review Comment:
```suggestion
// The event type {ADD, REMOVE, UPDATE}
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/README.md:
##########
@@ -0,0 +1,28 @@
+# Introduction
+
+This module is the etcd registry plugin module, this plugin will use etcd as the registry center.
+
+# How to use
+
+If you want to set the registry center as mysql,you need to set the registry properties in master/worker/api's appplication.yml
Review Comment:
```suggestion
If you want to set the registry center as etcd, you need to set the registry properties in master/worker/api's appplication.yml
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/Registry.java:
##########
@@ -20,27 +20,72 @@
package org.apache.dolphinscheduler.registry.api;
import java.io.Closeable;
-import java.time.Duration;
import java.util.Collection;
+/**
+ * Registry
+ *
+ * <p>
+ * The implementation may throw RegistryException during function call
+ */
public interface Registry extends Closeable {
+ /**
+ * Watch the change of this path and subpath.
+ * The type of change contains [ADD,DELETE,UPDATE]
+ * @return if there is not a Exception, the result is true.
Review Comment:
```suggestion
* @return {@code true} if succeeded.
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/Registry.java:
##########
@@ -20,27 +20,72 @@
package org.apache.dolphinscheduler.registry.api;
import java.io.Closeable;
-import java.time.Duration;
import java.util.Collection;
+/**
+ * Registry
+ *
+ * <p>
+ * The implementation may throw RegistryException during function call
+ */
public interface Registry extends Closeable {
+ /**
+ * Watch the change of this path and subpath.
+ * The type of change contains [ADD,DELETE,UPDATE]
+ * @return if there is not a Exception, the result is true.
+ */
boolean subscribe(String path, SubscribeListener listener);
+ /**
+ * remove the SubscribeListener which subscribe this path
Review Comment:
```suggestion
* Remove the path from the subscribe list.
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/Registry.java:
##########
@@ -20,27 +20,72 @@
package org.apache.dolphinscheduler.registry.api;
import java.io.Closeable;
-import java.time.Duration;
import java.util.Collection;
+/**
+ * Registry
+ *
+ * <p>
+ * The implementation may throw RegistryException during function call
+ */
public interface Registry extends Closeable {
+ /**
+ * Watch the change of this path and subpath.
+ * The type of change contains [ADD,DELETE,UPDATE]
+ * @return if there is not a Exception, the result is true.
+ */
boolean subscribe(String path, SubscribeListener listener);
+ /**
+ * remove the SubscribeListener which subscribe this path
+ */
void unsubscribe(String path);
+ /**
+ * addd a connection listener to collection
Review Comment:
```suggestion
* Add a connection listener to collection.
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/ConnectionState.java:
##########
@@ -19,6 +19,9 @@
package org.apache.dolphinscheduler.registry.api;
+/**
+ * Connection State Between client and registry center(Etcd,MySql,Zookeeper)
Review Comment:
```suggestion
* Connection state between client and registry center(Etcd, MySql, Zookeeper)
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/Registry.java:
##########
@@ -20,27 +20,72 @@
package org.apache.dolphinscheduler.registry.api;
import java.io.Closeable;
-import java.time.Duration;
import java.util.Collection;
+/**
+ * Registry
+ *
+ * <p>
+ * The implementation may throw RegistryException during function call
+ */
public interface Registry extends Closeable {
+ /**
+ * Watch the change of this path and subpath.
+ * The type of change contains [ADD,DELETE,UPDATE]
+ * @return if there is not a Exception, the result is true.
+ */
boolean subscribe(String path, SubscribeListener listener);
+ /**
+ * remove the SubscribeListener which subscribe this path
+ */
void unsubscribe(String path);
+ /**
+ * addd a connection listener to collection
+ */
void addConnectionStateListener(ConnectionListener listener);
+ /**
+ * @return the value
+ */
String get(String key);
+ /**
+ *
+ * @param key
+ * @param value
+ * @param deleteOnDisconnect if true, when the connection state is disconnected, the key will be deleted
+ */
void put(String key, String value, boolean deleteOnDisconnect);
+ /**
+ * This function will delete the keys whose prefix is {@param key}
+ * @param key the prefix of deleted key
+ * @throws if the key not exists, there is a registryException
+ */
void delete(String key);
+ /**
+ * This function will get the subdirectory of {@param key}
+ * E.g: registry contains the following keys:[/test/test1/test2,]
+ * if the key: /test
+ * Return: test1
+ */
Collection<String> children(String key);
+ /**
+ * @return if key exists,return true
Review Comment:
```suggestion
* @return {@code true} if key exists.
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import io.etcd.jetcd.Client;
+import io.grpc.ManagedChannel;
+
+/**
+ * Get the connection status by listening to the Client's Channel
+ */
+public class EtcdConnectionStateListener implements AutoCloseable {
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // Client's Channel
+ private AtomicReference<ManagedChannel> channel;
+ // monitored client
+ private Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
+ private long initialDelay = 500L;
+ private long delay = 500L;
+ public EtcdConnectionStateListener(Client client) {
+ this.client = client;
+ channel = new AtomicReference<>();
+ this.scheduledExecutorService = Executors.newScheduledThreadPool(
+ 1,
+ new ThreadFactoryBuilder().setNameFormat("EtcdConnectionStateListenerThread").setDaemon(true).build());
+ }
+
+ public void addConnectionListener(ConnectionListener connectionListener) {
+ connectionListeners.add(connectionListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connectionListeners.clear();
+ scheduledExecutorService.shutdownNow();
+ }
+
+ /**
+ * Apply for a lease through the client, if there is no exception, the connection is normal
+ * @return the current connection state
+ * @throws if there is a exception, return is DISCONNECTED
+ */
+ private ConnectionState isConnected() {
Review Comment:
```suggestion
private ConnectionState currentConnectivityState() {
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/Registry.java:
##########
@@ -20,27 +20,72 @@
package org.apache.dolphinscheduler.registry.api;
import java.io.Closeable;
-import java.time.Duration;
import java.util.Collection;
+/**
+ * Registry
+ *
+ * <p>
+ * The implementation may throw RegistryException during function call
Review Comment:
This is verbose as the function signatures already indicate that.
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import io.etcd.jetcd.Client;
+import io.grpc.ManagedChannel;
+
+/**
+ * Get the connection status by listening to the Client's Channel
+ */
+public class EtcdConnectionStateListener implements AutoCloseable {
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // Client's Channel
+ private AtomicReference<ManagedChannel> channel;
+ // monitored client
+ private Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
+ private long initialDelay = 500L;
+ private long delay = 500L;
+ public EtcdConnectionStateListener(Client client) {
+ this.client = client;
+ channel = new AtomicReference<>();
+ this.scheduledExecutorService = Executors.newScheduledThreadPool(
+ 1,
+ new ThreadFactoryBuilder().setNameFormat("EtcdConnectionStateListenerThread").setDaemon(true).build());
+ }
+
+ public void addConnectionListener(ConnectionListener connectionListener) {
+ connectionListeners.add(connectionListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connectionListeners.clear();
+ scheduledExecutorService.shutdownNow();
+ }
+
+ /**
+ * Apply for a lease through the client, if there is no exception, the connection is normal
+ * @return the current connection state
+ * @throws if there is a exception, return is DISCONNECTED
+ */
+ private ConnectionState isConnected() {
+ try {
+ // Use Get() to ensure Future completes
Review Comment:
Remove this. Don't explain codes if they are already very clear.
##########
dolphinscheduler-registry/dolphinscheduler-registry-api/src/main/java/org/apache/dolphinscheduler/registry/api/ConnectionListener.java:
##########
@@ -19,6 +19,10 @@
package org.apache.dolphinscheduler.registry.api;
+/**
+ * when the connect state between client and registry center changed,
+ * the onupdate function is triggered
Review Comment:
```suggestion
* the {@code onUpdate} function is triggered
```
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import io.etcd.jetcd.Client;
+import io.grpc.ManagedChannel;
+
+/**
+ * Get the connection status by listening to the Client's Channel
Review Comment:
Reword this there is no channel anymore
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import io.etcd.jetcd.Client;
+import io.grpc.ManagedChannel;
+
+/**
+ * Get the connection status by listening to the Client's Channel
+ */
+public class EtcdConnectionStateListener implements AutoCloseable {
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // Client's Channel
+ private AtomicReference<ManagedChannel> channel;
+ // monitored client
+ private Client client;
+ // The state of the last monitor
+ private ConnectionState connectionState;
+ private long initialDelay = 500L;
+ private long delay = 500L;
+ public EtcdConnectionStateListener(Client client) {
+ this.client = client;
+ channel = new AtomicReference<>();
+ this.scheduledExecutorService = Executors.newScheduledThreadPool(
+ 1,
+ new ThreadFactoryBuilder().setNameFormat("EtcdConnectionStateListenerThread").setDaemon(true).build());
+ }
+
+ public void addConnectionListener(ConnectionListener connectionListener) {
+ connectionListeners.add(connectionListener);
+ }
+
+ @Override
+ public void close() throws Exception {
+ connectionListeners.clear();
+ scheduledExecutorService.shutdownNow();
+ }
+
+ /**
+ * Apply for a lease through the client, if there is no exception, the connection is normal
+ * @return the current connection state
+ * @throws if there is a exception, return is DISCONNECTED
+ */
+ private ConnectionState isConnected() {
+ try {
+ // Use Get() to ensure Future completes
+ client.getLeaseClient().grant(1).get().getID();
+ return ConnectionState.CONNECTED;
+ } catch (Exception e) {
+ return ConnectionState.DISCONNECTED;
+ }
+ }
+
+ /**
+ * Periodically execute thread to get connection status
+ */
+ public void start() {
+ this.scheduledExecutorService.scheduleWithFixedDelay(() -> {
+ ConnectionState currentConnectionState = isConnected();
+ if (currentConnectionState == connectionState) {
+ return;
+ }
+ if (connectionState == ConnectionState.CONNECTED) {
+ if (currentConnectionState == ConnectionState.DISCONNECTED) {
+ connectionState = ConnectionState.DISCONNECTED;
+ triggerListener(ConnectionState.DISCONNECTED);
+ }
+ } else if (connectionState == ConnectionState.DISCONNECTED) {
+ if (currentConnectionState == ConnectionState.CONNECTED) {
+ connectionState = ConnectionState.CONNECTED;
+ triggerListener(ConnectionState.RECONNECTED);
+ }
+ } else if (connectionState == null) {
+ connectionState = currentConnectionState;
+ triggerListener(connectionState);
+ }
Review Comment:
Why can't we just simplify this to
```suggestion
if (connectionState != ConnectionState.SUSPENDED) {
connectionState = currentConnectionState;
triggerListener(connectionState);
```
@ruanwenjun I think the api should also notify even if the previous state is suspended and if the listener isn't interested in this they can just ignored.
##########
dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-etcd/src/main/java/org/apache/dolphinscheduler/plugin/registry/etcd/EtcdConnectionStateListener.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.dolphinscheduler.plugin.registry.etcd;
+
+import org.apache.dolphinscheduler.registry.api.ConnectionListener;
+import org.apache.dolphinscheduler.registry.api.ConnectionState;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+import io.etcd.jetcd.Client;
+import io.grpc.ManagedChannel;
+
+/**
+ * Get the connection status by listening to the Client's Channel
+ */
+public class EtcdConnectionStateListener implements AutoCloseable {
+ private final List<ConnectionListener> connectionListeners = Collections.synchronizedList(new ArrayList<>());
+ // A thread pool that periodically obtains connection status
+ private final ScheduledExecutorService scheduledExecutorService;
+ // Client's Channel
+ private AtomicReference<ManagedChannel> channel;
Review Comment:
This is no needed right?
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] kezhenxu94 commented on a diff in pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
kezhenxu94 commented on code in PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#discussion_r926358599
##########
pom.xml:
##########
@@ -878,6 +878,31 @@
<version>${aws.sdk.version}</version>
</dependency>
+ <dependency>
Review Comment:
consider importing `grpc-bom` instead
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1191213930
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [7 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [37.3% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1224028202
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [6 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [44.8% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] sonarcloud[bot] commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
sonarcloud[bot] commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1224031061
Kudos, SonarCloud Quality Gate passed! [](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=10981)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=BUG)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=VULNERABILITY)
[](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=SECURITY_HOTSPOT)
[](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL) [6 Code Smells](https://sonarcloud.io/project/issues?id=apache-dolphinscheduler&pullRequest=10981&resolved=false&types=CODE_SMELL)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list) [44.8% Coverage](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_coverage&view=list)
[](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list) [2.0% Duplication](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=10981&metric=new_duplicated_lines_density&view=list)
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1224107449
> Thanks, I have fixed the conflict
@caishunfeng I have fixed the conflict. Test bugs are due to new 3rd party packages introduced in other commits
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [dolphinscheduler] wjf222 commented on pull request #10981: [Feature][Registry] Support etcd as registry
Posted by GitBox <gi...@apache.org>.
wjf222 commented on PR #10981:
URL: https://github.com/apache/dolphinscheduler/pull/10981#issuecomment-1211912698
@ruanwenjun I have edited it according to the comments.
--
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: commits-unsubscribe@dolphinscheduler.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org