From 6140bc2a653cc3066d15ceeff5a3f06962fb32ad Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Wed, 21 Nov 2018 14:40:03 +0800 Subject: [PATCH] Fix concurrent problem of zookeeper configcenter, wait to start until cache being fully populated. --- .../apache/dubbo/config/AbstractConfig.java | 2 -- .../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 f60b378593..a894d7683a 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 f5f2cc0fa4..f3f392d394 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 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 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; - } }