You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/12/17 01:51:04 UTC
[GitHub] [dubbo-go] sanxun0325 commented on a change in pull request #1665: refactor zk dynamic configuration listener
sanxun0325 commented on a change in pull request #1665:
URL: https://github.com/apache/dubbo-go/pull/1665#discussion_r771041699
##########
File path: remoting/zookeeper/listener.go
##########
@@ -81,6 +76,56 @@ func (l *ZkEventListener) ListenServiceNodeEvent(zkPath string, listener remotin
}(zkPath, listener)
}
+// ListenConfigurationEvent listen a path node event
+func (l *ZkEventListener) ListenConfigurationEvent(zkPath string, listener remoting.DataListener) {
+ // listen l service node
+ l.wg.Add(1)
+ go func(zkPath string, listener remoting.DataListener) {
+ var eventChan = make(chan zk.Event, 16)
+ l.Client.RegisterEvent(zkPath, eventChan)
+ for {
+ select {
+ case event := <-eventChan:
+ logger.Infof("[ZkEventListener]Receive configuration change event:%#v", event)
+ if event.Type == zk.EventNodeChildrenChanged || event.Type == zk.EventNotWatching {
+ continue
+ }
+ // 1. Re-set watcher for the zk node
+ _, _, _, err := l.Client.Conn.ExistsW(event.Path)
+ if err != nil {
+ logger.Warnf("[ZkEventListener]Re-set watcher error, the reason is %+v", err)
+ }
+
+ action := remoting.EventTypeAdd
+ var content string
+ if event.Type == zk.EventNodeDeleted {
+ action = remoting.EventTypeDel
+ } else {
+ // 2. Try to get new configuration value of the zk node
+ // Notice: The order of step 1 and step 2 cannot be swapped, if you get value(with timestamp t1)
+ // before re-set the watcher(with timestamp t2), and some one change the data of the zk node after
+ // t2 but before t1, you may get the old value, and the new value will not trigger the event.
+ contentBytes, _, err := l.Client.Conn.Get(event.Path)
+ if err != nil {
Review comment:
If an error occurs, need continue execution?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org