You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2018/11/21 06:40:21 UTC

[incubator-dubbo] branch dev-metadata updated (740b5aa -> 6140bc2)

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a change to branch dev-metadata
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git.


    from 740b5aa  remove unnecessary volatile restrict
     new 9f02b97  Fix configurator bug
     new 6140bc2  Fix concurrent problem of zookeeper configcenter, wait to start until cache being fully populated.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../cluster/configurator/AbstractConfigurator.java | 22 +++++++++++-----------
 .../org/apache/dubbo/config/AbstractConfig.java    |  2 --
 .../support/apollo/ApolloDynamicConfiguration.java |  2 --
 .../sources/ZooKeeperConfigurationSource.java      | 20 +++++++++-----------
 4 files changed, 20 insertions(+), 26 deletions(-)


[incubator-dubbo] 01/02: Fix configurator bug

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch dev-metadata
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git

commit 9f02b97ee00b80ffdb501d8fd48c794e88388d32
Author: ken.lj <ke...@gmail.com>
AuthorDate: Wed Nov 21 14:38:40 2018 +0800

    Fix configurator bug
---
 .../cluster/configurator/AbstractConfigurator.java | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java
index 449bafd..3b682ee 100644
--- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java
+++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/configurator/AbstractConfigurator.java
@@ -57,13 +57,12 @@ public abstract class AbstractConfigurator implements Configurator {
          */
         String apiVersion = configuratorUrl.getParameter(Constants.API_VERSION_KEY);
         if (StringUtils.isNotEmpty(apiVersion)) {
-            int configuratorPort = configuratorUrl.getPort();
-            if (configuratorPort == 0) {
-                configureIfMatch(NetUtils.getLocalHost(), url, configuratorUrl);
-            } else {
-                if (url.getPort() == configuratorPort) {
-                    configureIfMatch(configuratorUrl.getHost(), url, configuratorUrl);
-                }
+            String currentSide = url.getParameter(Constants.SIDE_KEY);
+            String configuratorSide = configuratorUrl.getParameter(Constants.SIDE_KEY);
+            if (currentSide.equals(configuratorSide) && Constants.CONSUMER.equals(configuratorSide) && 0 == configuratorUrl.getPort()) {
+                url = configureIfMatch(NetUtils.getLocalHost(), url);
+            } else if (currentSide.equals(configuratorSide) && Constants.PROVIDER.equals(configuratorSide) && url.getPort() == configuratorUrl.getPort()) {
+                url = configureIfMatch(url.getHost(), url);
             }
         }
         /**
@@ -80,21 +79,21 @@ public abstract class AbstractConfigurator implements Configurator {
         // If override url has port, means it is a provider address. We want to control a specific provider with this override url, it may take effect on the specific provider instance or on consumers holding this provider instance.
         if (configuratorUrl.getPort() != 0) {
             if (url.getPort() == configuratorUrl.getPort()) {
-                return configureIfMatch(url.getHost(), url, configuratorUrl);
+                return configureIfMatch(url.getHost(), url);
             }
         } else {// override url don't have a port, means the ip override url specify is a consumer address or 0.0.0.0
             // 1.If it is a consumer ip address, the intention is to control a specific consumer instance, it must takes effect at the consumer side, any provider received this override url should ignore;
             // 2.If the ip is 0.0.0.0, this override url can be used on consumer, and also can be used on provider
             if (url.getParameter(Constants.SIDE_KEY, Constants.PROVIDER).equals(Constants.CONSUMER)) {
-                return configureIfMatch(NetUtils.getLocalHost(), url, configuratorUrl);// NetUtils.getLocalHost is the ip address consumer registered to registry.
+                return configureIfMatch(NetUtils.getLocalHost(), url);// NetUtils.getLocalHost is the ip address consumer registered to registry.
             } else if (url.getParameter(Constants.SIDE_KEY, Constants.CONSUMER).equals(Constants.PROVIDER)) {
-                return configureIfMatch(Constants.ANYHOST_VALUE, url, configuratorUrl);// take effect on all providers, so address must be 0.0.0.0, otherwise it won't flow to this if branch
+                return configureIfMatch(Constants.ANYHOST_VALUE, url);// take effect on all providers, so address must be 0.0.0.0, otherwise it won't flow to this if branch
             }
         }
         return url;
     }
 
-    private URL configureIfMatch(String host, URL url, URL configuratorUrl) {
+    private URL configureIfMatch(String host, URL url) {
         if (Constants.ANYHOST_VALUE.equals(configuratorUrl.getHost()) || host.equals(configuratorUrl.getHost())) {
             // TODO, to support wildcards
             String providers = configuratorUrl.getParameter(Constants.OVERRIDE_PROVIDERS_KEY);
@@ -113,6 +112,7 @@ public abstract class AbstractConfigurator implements Configurator {
                     conditionKeys.add(Constants.VERSION_KEY);
                     conditionKeys.add(Constants.APPLICATION_KEY);
                     conditionKeys.add(Constants.SIDE_KEY);
+                    conditionKeys.add(Constants.API_VERSION_KEY);
                     for (Map.Entry<String, String> entry : configuratorUrl.getParameters().entrySet()) {
                         String key = entry.getKey();
                         String value = entry.getValue();


[incubator-dubbo] 02/02: Fix concurrent problem of zookeeper configcenter, wait to start until cache being fully populated.

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch dev-metadata
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git

commit 6140bc2a653cc3066d15ceeff5a3f06962fb32ad
Author: ken.lj <ke...@gmail.com>
AuthorDate: Wed Nov 21 14:40:03 2018 +0800

    Fix concurrent problem of zookeeper configcenter, wait to start until cache being fully populated.
---
 .../java/org/apache/dubbo/config/AbstractConfig.java |  2 --
 .../support/apollo/ApolloDynamicConfiguration.java   |  2 --
 .../sources/ZooKeeperConfigurationSource.java        | 20 +++++++++-----------
 3 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java
index f60b378..a894d76 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java
@@ -505,8 +505,6 @@ public abstract class AbstractConfig implements Serializable {
                     }
                 }
             } catch (Exception e) {
-                System.out.println(this.getClass().getName());
-                System.out.println(method.getName());
                 throw new IllegalStateException(e.getMessage(), e);
             }
         }
diff --git a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java
index f5f2cc0..f3f392d 100644
--- a/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java
+++ b/dubbo-configcenter/dubbo-configcenter-apollo/src/main/java/org/apache/dubbo/configcenter/support/apollo/ApolloDynamicConfiguration.java
@@ -56,8 +56,6 @@ public class ApolloDynamicConfiguration extends AbstractDynamicConfiguration<Con
         /**
          * Instead of using Dubbo's configuration, I would suggest use the original configuration method Apollo provides.
          */
-//        String configEnv = env.getCompositeConf().getString(ENV_KEY);
-//        String configCluster = env.getCompositeConf().getString(CLUSTER_KEY);
         String configEnv = url.getParameter(Constants.CONFIG_ENV_KEY);
         String configAddr = url.getBackupAddress();
         String configCluster = url.getParameter(Constants.CONFIG_CLUSTER_KEY);
diff --git a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/archaius/sources/ZooKeeperConfigurationSource.java b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/archaius/sources/ZooKeeperConfigurationSource.java
index 647dcf6..4366ac9 100644
--- a/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/archaius/sources/ZooKeeperConfigurationSource.java
+++ b/dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/archaius/sources/ZooKeeperConfigurationSource.java
@@ -39,6 +39,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
@@ -59,7 +60,7 @@ public class ZooKeeperConfigurationSource implements WatchedConfigurationSource,
     // The final root path would be: /configRootPath/"config"
     private final String configRootPath;
     private final TreeCache treeCache;
-    private boolean connected = false;
+    private CountDownLatch initializedLatch = new CountDownLatch(1);
 
     private final Charset charset = Charset.forName("UTF-8");
 
@@ -96,7 +97,7 @@ public class ZooKeeperConfigurationSource implements WatchedConfigurationSource,
                 new ExponentialBackoffRetry(1000, 3));
         client.start();
         try {
-            connected = client.blockUntilConnected(connectTimeout, TimeUnit.MILLISECONDS);
+            boolean connected = client.blockUntilConnected(connectTimeout, TimeUnit.MILLISECONDS);
             if (!connected) {
                 boolean check = Boolean.parseBoolean(System.getProperty(ARCHAIUS_CONFIG_CHECK_KEY, "false"));
                 if (check) {
@@ -138,8 +139,8 @@ public class ZooKeeperConfigurationSource implements WatchedConfigurationSource,
 
                 TreeCacheEvent.Type type = event.getType();
                 ChildData data = event.getData();
-                if (type == TreeCacheEvent.Type.INITIALIZED || type == TreeCacheEvent.Type.CONNECTION_RECONNECTED) {
-                    connected = true;
+                if (type == TreeCacheEvent.Type.INITIALIZED) {
+                    initializedLatch.countDown();
                 }
 
                 // TODO, ignore other event types
@@ -202,9 +203,10 @@ public class ZooKeeperConfigurationSource implements WatchedConfigurationSource,
 
         Map<String, Object> all = new HashMap<>();
 
-        if (!connected) {
-            logger.warn("ConfigCenter is not connected yet, zookeeper does't support local snapshot, so there's no backup data to use!");
-            return all;
+        try {
+            initializedLatch.await();
+        } catch (InterruptedException e) {
+            logger.error("Being interrupted unexpectedly when waiting zookeeper to initialize, the config data may not ready yet, be careful!");
         }
 
         Map<String, ChildData> dataMap = treeCache.getCurrentChildren(configRootPath);
@@ -257,8 +259,4 @@ public class ZooKeeperConfigurationSource implements WatchedConfigurationSource,
             logger.error("IOException should not have been thrown.", exc);
         }
     }
-
-    public boolean isConnected() {
-        return connected;
-    }
 }