Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try update value if node already exists #2314

Merged
merged 3 commits into from
Jun 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

@AlexStocks AlexStocks May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chickenlj 这个地方我有异议,这个地方不需要修改啊,原来的没啥问题。你修改后,会不会遗漏一些case就不晓得了。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

实际上,上面的字符串关键字 node does not exist 也是从 ErrNoNode 定义中取的,因此两者能检查的范围应该是一致的。

ErrNoNode = errors.New("zk: node does not exist")

perrors.Is 文档说是会嵌套往下检查,理论上与应该没啥问题。

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