Skip to content

Commit

Permalink
issue#4314: ZookeeperDynamicConfiguration will be busy wait if zk is …
Browse files Browse the repository at this point in the history
…unavailable (#4582)

* issue#4314: ZookeeperDynamicConfiguration will be busy wait if zk is unavailable
* fix logic issue
  • Loading branch information
beiwei30 authored and cvictory committed Jul 17, 2019
1 parent 82378a1 commit 77a69e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import static org.apache.dubbo.configcenter.Constants.CONFIG_NAMESPACE_KEY;

Expand Down Expand Up @@ -61,7 +62,12 @@ public class ZookeeperDynamicConfiguration implements DynamicConfiguration {
zkClient.addDataListener(rootPath, cacheListener, executor);
try {
// Wait for connection
this.initializedLatch.await();
long timeout = url.getParameter("init.timeout", 5000);
boolean isCountDown = this.initializedLatch.await(timeout, TimeUnit.MILLISECONDS);
if (!isCountDown) {
throw new IllegalStateException("Failed to receive INITIALIZED event from zookeeper, pls. check if url "
+ url + " is correct");
}
} catch (InterruptedException e) {
logger.warn("Failed to build local cache for config center (zookeeper)." + url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,14 @@ protected void addTargetDataListener(String path, CuratorZookeeperClient.Curator
try {
TreeCache treeCache = TreeCache.newBuilder(client, path).setCacheData(false).build();
treeCacheMap.putIfAbsent(path, treeCache);
treeCache.start();

if (executor == null) {
treeCache.getListenable().addListener(treeCacheListener);
} else {
treeCache.getListenable().addListener(treeCacheListener, executor);
}

treeCache.start();
} catch (Exception e) {
throw new IllegalStateException("Add treeCache listener for path:" + path, e);
}
Expand Down

0 comments on commit 77a69e0

Please sign in to comment.