This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/develop by this push:
new 1ebf6e081 fix: Resolve the latency issue caused by the lack of timely
perception of existing nodes when connecting to the zookeeper client (#2930)
1ebf6e081 is described below
commit 1ebf6e081200fa1aa22083fbd161a22c8a6c6ed2
Author: 1kasa <[email protected]>
AuthorDate: Mon Jul 14 13:45:45 2025 +0800
fix: Resolve the latency issue caused by the lack of timely perception of
existing nodes when connecting to the zookeeper client (#2930)
* fix: Delay issue
* Save current changes
* fix zknode
* Merge and fix
* wrong commit
* Add constants
---
remoting/zookeeper/listener.go | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/remoting/zookeeper/listener.go b/remoting/zookeeper/listener.go
index c2b21448e..c53e074c6 100644
--- a/remoting/zookeeper/listener.go
+++ b/remoting/zookeeper/listener.go
@@ -42,9 +42,11 @@ import (
"dubbo.apache.org/dubbo-go/v3/remoting"
)
-var defaultTTL = 10 * time.Minute
+var (
+ defaultTTL = 10 * time.Minute
+ maxScheduleTTL = 20 * time.Second
+)
-// nolint
type ZkEventListener struct {
Client *gxzookeeper.ZookeeperClient
pathMapLock sync.Mutex
@@ -209,6 +211,7 @@ func (l *ZkEventListener) handleZkNodeEvent(zkPath string,
children []string, li
logger.Errorf("Get new node path {%v} 's content
error,message is {%v}",
newNode, perrors.WithStack(connErr))
}
+
if !listener.DataChange(remoting.Event{Path: newNode, Action:
remoting.EventTypeAdd, Content: string(content)}) {
continue
}
@@ -253,8 +256,8 @@ func (l *ZkEventListener) listenAllDirEvents(conf
*common.URL, listener remoting
logger.Warnf("[Zookeeper EventListener][listenDirEvent]
Wrong configuration for registry.ttl, error=%+v, using default value %v
instead", err, defaultTTL)
}
}
- if ttl > 20e9 {
- ttl = 20e9
+ if ttl > maxScheduleTTL {
+ ttl = maxScheduleTTL
}
rootPath := path.Join(constant.PathSeparator, constant.Dubbo)
@@ -334,6 +337,7 @@ func (l *ZkEventListener) listenDirEvent(conf *common.URL,
zkRootPath string, li
logger.Warnf("[Zookeeper EventListener][listenDirEvent]
Wrong configuration for registry.ttl, error=%+v, using default value %v
instead", err, defaultTTL)
}
}
+
for {
// Get current children with watcher for the zkRootPath
children, childEventCh, err := l.Client.GetChildrenW(zkRootPath)
@@ -430,9 +434,15 @@ func (l *ZkEventListener) startScheduleWatchTask(
zkRootPath string, children []string, ttl time.Duration,
listener remoting.DataListener, childEventCh <-chan zk.Event) bool {
tickerTTL := ttl
- if tickerTTL > 20e9 {
- tickerTTL = 20e9
+ if tickerTTL > maxScheduleTTL {
+ tickerTTL = maxScheduleTTL
}
+
+ childrenNode, err := l.Client.GetChildren(zkRootPath)
+ if err == nil {
+ l.handleZkNodeEvent(zkRootPath, childrenNode, listener)
+ }
+
ticker := time.NewTicker(tickerTTL)
for {
select {