Skip to content

Commit

Permalink
Try update value if node already exists (#2314)
Browse files Browse the repository at this point in the history
* Try update value if node already exists

* fix variable declaration shadow.
  • Loading branch information
chickenlj authored Jun 3, 2023
1 parent 4309dc5 commit 9d087ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 9 additions & 0 deletions config_center/zookeeper/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions remoting/zookeeper/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9d087ed

Please sign in to comment.