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

alexstocks pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 9d087ed79 Try update value if node already exists (#2314)
9d087ed79 is described below

commit 9d087ed79f5c83e6f585e789300925368f0c65bb
Author: Ken Liu <[email protected]>
AuthorDate: Sat Jun 3 13:21:20 2023 +0800

    Try update value if node already exists (#2314)
    
    * Try update value if node already exists
    
    * fix variable declaration shadow.
---
 config_center/zookeeper/impl.go | 9 +++++++++
 remoting/zookeeper/listener.go  | 3 +--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/config_center/zookeeper/impl.go b/config_center/zookeeper/impl.go
index feafea489..b6c3e6be5 100644
--- a/config_center/zookeeper/impl.go
+++ b/config_center/zookeeper/impl.go
@@ -167,6 +167,15 @@ func (c *zookeeperDynamicConfiguration) PublishConfig(key 
string, group string,
        // create every node in the path with given value which we may not 
expected.
        err := c.client.CreateWithValue(path, valueBytes)
        if err != nil {
+               // try update value if node already exists
+               if perrors.Is(err, zk.ErrNodeExists) {
+                       _, stat, _ := c.client.GetContent(path)
+                       _, setErr := c.client.SetContent(path, valueBytes, 
stat.Version)
+                       if setErr != nil {
+                               return perrors.WithStack(setErr)
+                       }
+                       return nil
+               }
                return perrors.WithStack(err)
        }
        return nil
diff --git a/remoting/zookeeper/listener.go b/remoting/zookeeper/listener.go
index b36d8830c..673e0119a 100644
--- a/remoting/zookeeper/listener.go
+++ b/remoting/zookeeper/listener.go
@@ -344,8 +344,7 @@ func (l *ZkEventListener) listenDirEvent(conf *common.URL, 
zkRootPath string, li
                                failTimes = MaxFailTimes
                        }
 
-                       err = perrors.Cause(err)
-                       if !strings.Contains(err.Error(), "node does not 
exist") { // ignore if node not exist
+                       if !perrors.Is(err, zk.ErrNoNode) { // ignore if node 
not exist
                                logger.Errorf("[Zookeeper 
EventListener][listenDirEvent] Get children of path {%s} with watcher failed, 
the error is %+v", zkRootPath, err)
                        }
                        // Maybe the provider does not ready yet, sleep 
failTimes * ConnDelay senconds to wait

Reply via email to