Skip to content

Commit

Permalink
dubbo zookeeper registry too slow (#5037)
Browse files Browse the repository at this point in the history
same as 4828
  • Loading branch information
qixiaobo authored and chickenlj committed Dec 12, 2019
1 parent 89b213f commit 07bcafb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void createEphemeral(String path) {
}

@Override
public void delete(String path) {
protected void deletePath(String path) {
try {
client.delete().forPath(path);
} catch (NoNodeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.utils.ConcurrentHashSet;
import com.alibaba.dubbo.remoting.zookeeper.ChildListener;
import com.alibaba.dubbo.remoting.zookeeper.StateListener;
import com.alibaba.dubbo.remoting.zookeeper.ZookeeperClient;
Expand All @@ -41,6 +42,8 @@ public abstract class AbstractZookeeperClient<TargetChildListener> implements Zo

private volatile boolean closed = false;

private final Set<String> persistentExistNodePath = new ConcurrentHashSet<String>();

public AbstractZookeeperClient(URL url) {
this.url = url;
}
Expand All @@ -50,10 +53,23 @@ public URL getUrl() {
return url;
}


@Override
public void delete(String path){
//never mind if ephemeral
persistentExistNodePath.remove(path);
deletePath(path);
}


@Override
public void create(String path, boolean ephemeral) {
if (!ephemeral) {
if(persistentExistNodePath.contains(path)){
return;
}
if (checkExists(path)) {
persistentExistNodePath.add(path);
return;
}
}
Expand All @@ -65,6 +81,8 @@ public void create(String path, boolean ephemeral) {
createEphemeral(path);
} else {
createPersistent(path);
persistentExistNodePath.add(path);

}
}

Expand Down Expand Up @@ -141,4 +159,9 @@ public void close() {

protected abstract void removeTargetChildListener(String path, TargetChildListener listener);

/**
* we invoke the zookeeper client to delete the node
* @param path the node path
*/
protected abstract void deletePath(String path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void createEphemeral(String path) {
}

@Override
public void delete(String path) {
protected void deletePath(String path) {
try {
client.delete(path);
} catch (ZkNoNodeException e) {
Expand Down

0 comments on commit 07bcafb

Please sign in to comment.