Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-09-01 Thread via GitHub


Alanxtl merged PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-26 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5434765405

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [2.5% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-26 Thread via GitHub


ywxzm03 commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3864115449


##
config_center/zookeeper/impl.go:
##
@@ -134,23 +163,85 @@ func (c *zookeeperDynamicConfiguration) GetProperties(key 
string, opts ...config
} else {
key = c.GetURL().GetParam(constant.ConfigNamespaceKey, 
config_center.DefaultGroup) + "/" + key
}
-   content, _, err := c.client.GetContent(c.rootPath + "/" + key)
-   if errors.Is(err, zk.ErrNoNode) {
-   logger.Warnf("[ConfigCenter][Zookeeper] query rule fail, key=%s 
err=%v", key, err)
-   return "", nil
-   }
-   if err != nil {
-   return "", perrors.WithStack(err)
+   return buildPath(c.rootPath, key)
+}
+
+func (c *zookeeperDynamicConfiguration) loadProperties(path string, 
registerWatch bool) (configCacheEntry, watchRegistration, error) {
+   if !c.cache.enabled() || !registerWatch {
+   beforeSessionID := c.client.Conn.SessionID()
+   content, _, err := c.client.GetContent(path)
+   afterSessionID := c.client.Conn.SessionID()
+   registration := watchRegistration{
+   beforeSessionID: beforeSessionID,
+   afterSessionID:  afterSessionID,
+   }
+   if errors.Is(err, zk.ErrNoNode) {
+   logger.Warnf("[ConfigCenter][Zookeeper] query rule 
fail, key=%s err=%v", path, err)
+   return configCacheEntry{exists: false}, registration, 
nil
+   }
+   if err != nil {
+   return configCacheEntry{}, registration, 
perrors.WithStack(err)
+   }
+   return configCacheEntry{content: string(content), exists: 
true}, registration, nil
}
-   if !c.base64Enabled {
-   return string(content), nil
+
+   for {
+   beforeSessionID := c.client.Conn.SessionID()
+   content, _, events, err := c.client.Conn.GetW(path)
+   registration := watchRegistration{
+   events:  events,
+   beforeSessionID: beforeSessionID,
+   afterSessionID:  c.client.Conn.SessionID(),
+   }
+   if err == nil {
+   return configCacheEntry{content: string(content), 
exists: true}, registration, nil
+   }
+   if !errors.Is(err, zk.ErrNoNode) {
+   return configCacheEntry{}, watchRegistration{}, 
perrors.WithStack(err)
+   }
+
+   beforeSessionID = c.client.Conn.SessionID()
+   exists, _, events, watchErr := c.client.Conn.ExistsW(path)
+   registration = watchRegistration{
+   events:  events,
+   beforeSessionID: beforeSessionID,
+   afterSessionID:  c.client.Conn.SessionID(),
+   }
+   if watchErr != nil {
+   return configCacheEntry{}, watchRegistration{}, 
perrors.WithStack(watchErr)
+   }
+   if !exists {
+   logger.Warnf("[ConfigCenter][Zookeeper] query rule 
fail, key=%s err=%v", path, err)
+   return configCacheEntry{exists: false}, registration, 
nil
+   }
+
+   readBeforeSessionID := c.client.Conn.SessionID()
+   content, _, getErr := c.client.Conn.Get(path)
+   readAfterSessionID := c.client.Conn.SessionID()
+   registration.readBeforeSessionID = readBeforeSessionID
+   registration.readAfterSessionID = readAfterSessionID
+   if errors.Is(getErr, zk.ErrNoNode) {
+   continue
+   }
+   if getErr != nil {
+   return configCacheEntry{}, registration, 
perrors.WithStack(getErr)
+   }
+   return configCacheEntry{content: string(content), exists: 
true}, registration, nil
}
+}
 
-   decoded, err := base64.StdEncoding.DecodeString(string(content))
+func parseConfigCacheTTL(value string) (time.Duration, error) {
+   if value == "" {

Review Comment:
   fixed



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-26 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5427275991

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [2.5% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-25 Thread via GitHub


AlexStocks commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3853310934


##
config_center/zookeeper/config_cache.go:
##
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package zookeeper
+
+import (
+   "sync"
+   "time"
+)
+
+type configCacheEntry struct {
+   content   string
+   existsbool
+   expiresAt time.Time
+}
+
+type configCache struct {
+   ttl time.Duration
+
+   stateLock  sync.RWMutex
+   entriesmap[string]configCacheEntry
+   watchesmap[string]bool
+   generation uint64
+
+   pathLocks sync.Map
+}

Review Comment:
   [P1] 当前有界修复仍未关闭这个根因
   
   这里在 auto watch 已满时仅把最后一个业务 watch 标成 `retired`,只有该路径未来再次产生事件才会删除。exact Head 
探针先填满 1024 个 auto watches,再对 4096 个唯一 key 各执行一次 
AddListener/RemoveListener,在没有后续事件的情况下得到 
`tracked=5120、retired=4096、auto=1024`。上游 go-zookeeper v1.0.4 同样会把这些 channel 
保留到事件或连接失效,并在重连时重新提交,因此本地 map、客户端和服务端 watch 仍会按历史 key 线性增长。请让最后一个 listener 
退出时确定性注销并回收 watch,并补“无后续事件”的唯一 key churn 容量测试。



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-25 Thread via GitHub


AlexStocks commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3853324850


##
config_center/zookeeper/impl_test.go:
##
@@ -126,6 +138,335 @@ func TestGetPropertiesWithMockZk(t *testing.T) {
require.Empty(t, empty)
 }
 
+func TestLoadPropertiesRegistersWatchOnlyWhenInactive(t *testing.T) {
+   cluster, client, events, err := 
gxzookeeper.NewMockZookeeperClient("watch-selection", 5*time.Second)
+   if err != nil {
+   t.Skipf("skip mock zk setup: %v", err)
+   }
+   defer cluster.Stop()
+
+   cfg := &zookeeperDynamicConfiguration{
+   rootPath: "/dubbo/config",
+   client:   client,
+   url:  mustURL(t, "registry://127.0.0.1:2181"),
+   cache:newConfigCache(time.Minute),
+   }
+   activePath := cfg.getPath("active", "group")
+   inactivePath := cfg.getPath("inactive", "group")
+   require.NoError(t, cfg.PublishConfig("active", "group", "v1"))
+   require.NoError(t, cfg.PublishConfig("inactive", "group", "v1"))
+
+   waitForEvent := func(path string, timeout time.Duration) bool {
+   timer := time.NewTimer(timeout)
+   defer timer.Stop()
+   for {
+   select {
+   case event := <-events:
+   if event.Path == path && event.Type == 
zk.EventNodeDataChanged {
+   return true
+   }
+   case <-timer.C:
+   return false
+   }
+   }
+   }
+
+   activeWatcher := &zk.Watcher{}
+   _, watcher, err := cfg.loadProperties(activePath, activeWatcher, false)
+   require.NoError(t, err)
+   require.Same(t, activeWatcher, watcher)
+   _, stat, err := client.GetContent(activePath)
+   require.NoError(t, err)
+   _, err = client.SetContent(activePath, []byte("v2"), stat.Version)
+   require.NoError(t, err)
+   require.False(t, waitForEvent(activePath, time.Second))
+
+   _, watcher, err = cfg.loadProperties(inactivePath, nil, true)
+   require.NoError(t, err)
+   require.NotNil(t, watcher)
+   _, stat, err = client.GetContent(inactivePath)
+   require.NoError(t, err)
+   _, err = client.SetContent(inactivePath, []byte("v2"), stat.Version)
+   require.NoError(t, err)
+   require.True(t, waitForEvent(inactivePath, time.Second))
+}
+
+func TestListenerUsesGroupOption(t *testing.T) {
+   cluster, client, _, err := 
gxzookeeper.NewMockZookeeperClient("listener-group", 5*time.Second)
+   if err != nil {
+   t.Skipf("skip mock zk setup: %v", err)
+   }
+   defer cluster.Stop()
+
+   zkListener := remotingzookeeper.NewZkEventListener(client)
+   defer zkListener.Close()
+   cfg := &zookeeperDynamicConfiguration{
+   rootPath: "/dubbo/config",
+   client:   client,
+   url:  mustURL(t, "registry://127.0.0.1:2181"),
+   cache:newConfigCache(time.Minute),
+   listener: zkListener,
+   }
+   cfg.cacheListener = newCacheListener(cfg.rootPath, zkListener, 
&cfg.cache)
+   key := "app.properties"
+   group := "custom"
+   path := cfg.getPropertiesPath(key, config_center.WithGroup(group))
+   rec := &recListener{}
+
+   cfg.AddListener(key, rec, config_center.WithGroup(group))
+   _, ok := cfg.cacheListener.keyListeners.Load(path)
+   require.True(t, ok)
+
+   cfg.RemoveListener(key, rec, config_center.WithGroup(group))
+   _, ok = cfg.cacheListener.keyListeners.Load(path)
+   require.False(t, ok)
+}
+
+func TestGetPropertiesFallsBackToTTLAtAutoWatchLimit(t *testing.T) {
+   cluster, client, events, err := 
gxzookeeper.NewMockZookeeperClient("watch-limit", 5*time.Second)
+   if err != nil {
+   t.Skipf("skip mock zk setup: %v", err)
+   }
+   defer cluster.Stop()
+
+   cfg := &zookeeperDynamicConfiguration{
+   rootPath: "/dubbo/config",
+   client:   client,
+   url:  mustURL(t, "registry://127.0.0.1:2181"),
+   cache:newConfigCache(time.Minute),
+   }
+   for i := range maxAutoWatches {
+   require.True(t, cfg.cache.setWatch(fmt.Sprintf("/watch/%d", i), 
configWatchState{
+   watcher: &zk.Watcher{},
+   auto:true,
+   }))
+   }
+
+   require.NoError(t, cfg.PublishConfig("fallback", "group", "v1"))
+   value, err := cfg.GetProperties("fallback", 
config_center.WithGroup("group"))
+   require.NoError(t, err)
+   require.Equal(t, "v1", value)
+
+   path := cfg.getPath("fallback", "group")
+   _, watchState := cfg.cache.snapshot(path)
+   require.False(t, watchState.tracked())
+   require.Equal(t, 

Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-24 Thread via GitHub


1kasa commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3849481306


##
config_center/zookeeper/impl.go:
##
@@ -134,23 +163,85 @@ func (c *zookeeperDynamicConfiguration) GetProperties(key 
string, opts ...config
} else {
key = c.GetURL().GetParam(constant.ConfigNamespaceKey, 
config_center.DefaultGroup) + "/" + key
}
-   content, _, err := c.client.GetContent(c.rootPath + "/" + key)
-   if errors.Is(err, zk.ErrNoNode) {
-   logger.Warnf("[ConfigCenter][Zookeeper] query rule fail, key=%s 
err=%v", key, err)
-   return "", nil
-   }
-   if err != nil {
-   return "", perrors.WithStack(err)
+   return buildPath(c.rootPath, key)
+}
+
+func (c *zookeeperDynamicConfiguration) loadProperties(path string, 
registerWatch bool) (configCacheEntry, watchRegistration, error) {
+   if !c.cache.enabled() || !registerWatch {
+   beforeSessionID := c.client.Conn.SessionID()
+   content, _, err := c.client.GetContent(path)
+   afterSessionID := c.client.Conn.SessionID()
+   registration := watchRegistration{
+   beforeSessionID: beforeSessionID,
+   afterSessionID:  afterSessionID,
+   }
+   if errors.Is(err, zk.ErrNoNode) {
+   logger.Warnf("[ConfigCenter][Zookeeper] query rule 
fail, key=%s err=%v", path, err)
+   return configCacheEntry{exists: false}, registration, 
nil
+   }
+   if err != nil {
+   return configCacheEntry{}, registration, 
perrors.WithStack(err)
+   }
+   return configCacheEntry{content: string(content), exists: 
true}, registration, nil
}
-   if !c.base64Enabled {
-   return string(content), nil
+
+   for {
+   beforeSessionID := c.client.Conn.SessionID()
+   content, _, events, err := c.client.Conn.GetW(path)
+   registration := watchRegistration{
+   events:  events,
+   beforeSessionID: beforeSessionID,
+   afterSessionID:  c.client.Conn.SessionID(),
+   }
+   if err == nil {
+   return configCacheEntry{content: string(content), 
exists: true}, registration, nil
+   }
+   if !errors.Is(err, zk.ErrNoNode) {
+   return configCacheEntry{}, watchRegistration{}, 
perrors.WithStack(err)
+   }
+
+   beforeSessionID = c.client.Conn.SessionID()
+   exists, _, events, watchErr := c.client.Conn.ExistsW(path)
+   registration = watchRegistration{
+   events:  events,
+   beforeSessionID: beforeSessionID,
+   afterSessionID:  c.client.Conn.SessionID(),
+   }
+   if watchErr != nil {
+   return configCacheEntry{}, watchRegistration{}, 
perrors.WithStack(watchErr)
+   }
+   if !exists {
+   logger.Warnf("[ConfigCenter][Zookeeper] query rule 
fail, key=%s err=%v", path, err)
+   return configCacheEntry{exists: false}, registration, 
nil
+   }
+
+   readBeforeSessionID := c.client.Conn.SessionID()
+   content, _, getErr := c.client.Conn.Get(path)
+   readAfterSessionID := c.client.Conn.SessionID()
+   registration.readBeforeSessionID = readBeforeSessionID
+   registration.readAfterSessionID = readAfterSessionID
+   if errors.Is(getErr, zk.ErrNoNode) {
+   continue
+   }
+   if getErr != nil {
+   return configCacheEntry{}, registration, 
perrors.WithStack(getErr)
+   }
+   return configCacheEntry{content: string(content), exists: 
true}, registration, nil
}
+}
 
-   decoded, err := base64.StdEncoding.DecodeString(string(content))
+func parseConfigCacheTTL(value string) (time.Duration, error) {
+   if value == "" {

Review Comment:
   Add some upper and lower bound protection, for example, extremely small 
positive values will cause immediate expiration, and this service also requires 
the cost of watch/generation/reset.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: 

Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-24 Thread via GitHub


Alanxtl commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5392278806

   @1kasa help revie this


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-24 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5392087338

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [2.5% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-24 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5392021652

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [2.5% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-24 Thread via GitHub


ywxzm03 commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5392019726

   
由于ZK依赖从`github.com/dubbogo/go-zookeeper`迁移至`github.com/go-zookeeper/zk`,这边也做了一些兼容性处理,主要是重新设计了watch生命周期:
   
   - 适配 upstream `go-zookeeper` API,将 `*zk.Watcher` 改为事件通道,并移除对 `RemoveWatcher` 
的依赖;所以watch的删除行为需要改为事件消费清除watch:当 auto watch 已达到上限且最后一个业务 listener 被删除时,将该 
watch 标记为 `retired`;后续残留事件到达时不再重新注册 watch,而是使用普通 `Exists/Get` 更新缓存
   - 完善 auto watch 与 business watch 的 ownership、`pending`、`retired` 
状态及容量限制;容量达到上限时,普通缓存路径降级为 TTL
   - 增加 session ID 和 generation 校验,避免重连或并发过程中旧 watch、旧读取结果覆盖当前缓存状态
   - 同步 `AddListener`、`RemoveListener`、watch 重试和 `DataChange`,避免重复注册、无效重试及 
listener 删除竞态
   - 重构事件处理,区分 `Accepted`、`Reload` 和 `Discarded` 三种 watch 注册结果
   - 增加缓存边界、并发注册、重连恢复、旧结果隔离、事件处理及关闭退出相关测试


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-22 Thread via GitHub


Alanxtl commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5380366897

   gost 已打tag
   https://github.com/dubbogo/gost/releases/tag/v1.14.5


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-20 Thread via GitHub


ywxzm03 commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5365899178

   > > > > > > 执行`make 
test-race`时,`TestCacheListenerRemoveListenerDropsWatchAtAutoLimit`和`TestRestartCallBackResetsCache`发生了数据竞争;原因是单测中执行到`defer
 cluster.Stop()`时,停止 ZooKeeper 
服务端,接着`Conn.loop`检测到网络断开,触发的`setState`与`removeWatcher()`中的`invalidateWatcher()`存在并发访问窗口,发生了state的读写竞争(前者是原子写,但后者却是普通读);由于后来reviewer提出要引入zk服务端依赖,这个数据竞争问题得以才暴露出来;
   > > > > > > 
若要解决这个问题,可以在dubbogo/go-zookeeper中将`invalidateWatcher`的state读取改为已有的原子读取`State()`即可,是否需要我去`dubbogo/go-zookeeper`那提个pr改一下这个小问题?
   > > > > > 
   > > > > > 
   > > > > > 提一下吧
   > > > > 
   > > > > 
   > > > > 
fixed;已在go-zookeeper侧,将invalidateWatcher改为原子读:[dubbogo/go-zookeeper#12](https://github.com/dubbogo/go-zookeeper/pull/12)
   > > > 
   > > > 
   > > > 我发新tag了 go-zookeeper/v1.0.5 你更新到新版本吧
   > > 
   > > 
   > > 更新到1.0.5后,本地跑make test-race,gost编译失败:
   > > ```
   > > undefined: zk.TestCluster
   > > undefined: zk.StartTestCluster
   > > undefined: zk.WithRetryTimes
   > > ```
   > > 
   > > 
   > > 
   > >   
   > > 
   > > 
   > >   
   > > 
   > > 
   > > 
   > >   
   > > 
原因是更新后的zk将部分测试api搬到了_test.go(WithRetryTimes是直接被删除了),所以这些api不会被编译到普通依赖包,而gost还用的之前的api,编译失败;如果要修这个,又要去gost那边将`TestCluster`、`StartTestCluster`、`WithRetryTimes`
 由 `go-zookeeper` 转移到 `gost` 自己维护,我再去提个pr?
   > 
   > ok 去 gost 也提一个pr吧
   
   
gost已经将TestCluster、StartTestCluster、WithRetryTimes转移到本地维护了:https://github.com/dubbogo/gost/pull/145
   
   但在这之后,我尝试dubbogo依赖本地gost,重新跑了一遍make 
test-race,但etcd服务没连上导致测试超时,测试fail;原因是gost之前移除了grpc.WithBlock(),grpc.DialContext 
不等待 
Ready直接返回,超时没覆盖到后续Grant;所以我在另一个pr(https://github.com/dubbogo/gost/pull/146)中,在keepSession中,用独立的短超时
 context发起首次Grant,且保留了gost删除WithBlock()的行为


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-20 Thread via GitHub


Alanxtl commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5353424389

   > > > > > 执行`make 
test-race`时,`TestCacheListenerRemoveListenerDropsWatchAtAutoLimit`和`TestRestartCallBackResetsCache`发生了数据竞争;原因是单测中执行到`defer
 cluster.Stop()`时,停止 ZooKeeper 
服务端,接着`Conn.loop`检测到网络断开,触发的`setState`与`removeWatcher()`中的`invalidateWatcher()`存在并发访问窗口,发生了state的读写竞争(前者是原子写,但后者却是普通读);由于后来reviewer提出要引入zk服务端依赖,这个数据竞争问题得以才暴露出来;
   > > > > > 
若要解决这个问题,可以在dubbogo/go-zookeeper中将`invalidateWatcher`的state读取改为已有的原子读取`State()`即可,是否需要我去`dubbogo/go-zookeeper`那提个pr改一下这个小问题?
   > > > > 
   > > > > 
   > > > > 提一下吧
   > > > 
   > > > 
   > > > 
fixed;已在go-zookeeper侧,将invalidateWatcher改为原子读:[dubbogo/go-zookeeper#12](https://github.com/dubbogo/go-zookeeper/pull/12)
   > > 
   > > 
   > > 我发新tag了 go-zookeeper/v1.0.5 你更新到新版本吧
   > 
   > 更新到1.0.5后,本地跑make test-race,gost编译失败:
   > 
   > ```
   > undefined: zk.TestCluster
   > undefined: zk.StartTestCluster
   > undefined: zk.WithRetryTimes
   > ```
   > 
   > 
原因是更新后的zk将部分测试api搬到了_test.go(WithRetryTimes是直接被删除了),所以这些api不会被编译到普通依赖包,而gost还用的之前的api,编译失败;如果要修这个,又要去gost那边将`TestCluster`、`StartTestCluster`、`WithRetryTimes`
 由 `go-zookeeper` 转移到 `gost` 自己维护,我再去提个pr?
   
   ok 去 gost 也提一个pr吧


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-20 Thread via GitHub


ywxzm03 commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5353269738

   > > > > 执行`make 
test-race`时,`TestCacheListenerRemoveListenerDropsWatchAtAutoLimit`和`TestRestartCallBackResetsCache`发生了数据竞争;原因是单测中执行到`defer
 cluster.Stop()`时,停止 ZooKeeper 
服务端,接着`Conn.loop`检测到网络断开,触发的`setState`与`removeWatcher()`中的`invalidateWatcher()`存在并发访问窗口,发生了state的读写竞争(前者是原子写,但后者却是普通读);由于后来reviewer提出要引入zk服务端依赖,这个数据竞争问题得以才暴露出来;
   > > > > 
若要解决这个问题,可以在dubbogo/go-zookeeper中将`invalidateWatcher`的state读取改为已有的原子读取`State()`即可,是否需要我去`dubbogo/go-zookeeper`那提个pr改一下这个小问题?
   > > > 
   > > > 
   > > > 提一下吧
   > > 
   > > 
   > > 
fixed;已在go-zookeeper侧,将invalidateWatcher改为原子读:[dubbogo/go-zookeeper#12](https://github.com/dubbogo/go-zookeeper/pull/12)
   > 
   > 我发新tag了 go-zookeeper/v1.0.5 你更新到新版本吧
   
   更新到1.0.5后,本地跑make test-race,gost编译失败:
   
   ```
   undefined: zk.TestCluster
   undefined: zk.StartTestCluster
   undefined: zk.WithRetryTimes
   ```
   
   
原因是更新后的zk将部分测试api搬到了_test.go(WithRetryTimes是直接被删除了),所以这些api不会被编译到普通依赖包,而gost还用的之前的api,编译失败;如果要修这个,又要去gost那边将`TestCluster`、`StartTestCluster`、`WithRetryTimes`
 由 `go-zookeeper` 转移到 `gost` 自己维护,我再去提个pr?


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-20 Thread via GitHub


Alanxtl commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5352807973

   > > > 执行`make 
test-race`时,`TestCacheListenerRemoveListenerDropsWatchAtAutoLimit`和`TestRestartCallBackResetsCache`发生了数据竞争;原因是单测中执行到`defer
 cluster.Stop()`时,停止 ZooKeeper 
服务端,接着`Conn.loop`检测到网络断开,触发的`setState`与`removeWatcher()`中的`invalidateWatcher()`存在并发访问窗口,发生了state的读写竞争(前者是原子写,但后者却是普通读);由于后来reviewer提出要引入zk服务端依赖,这个数据竞争问题得以才暴露出来;
   > > > 
若要解决这个问题,可以在dubbogo/go-zookeeper中将`invalidateWatcher`的state读取改为已有的原子读取`State()`即可,是否需要我去`dubbogo/go-zookeeper`那提个pr改一下这个小问题?
   > > 
   > > 
   > > 提一下吧
   > 
   > 
fixed;已在go-zookeeper侧,将invalidateWatcher改为原子读:[dubbogo/go-zookeeper#12](https://github.com/dubbogo/go-zookeeper/pull/12)
   
   我发新tag了 go-zookeeper/v1.0.5 你更新到新版本吧


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-20 Thread via GitHub


ywxzm03 commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3819265407


##
config_center/zookeeper/impl.go:
##
@@ -274,9 +343,22 @@ func (c *zookeeperDynamicConfiguration) closeConfigs() {
 }
 
 func (c *zookeeperDynamicConfiguration) RestartCallBack() bool {
+   for _, watcher := range c.cache.reset() {
+   c.removeWatcher(watcher)
+   }
+   if c.cacheListener != nil {
+   c.cacheListener.restoreBusinessWatches()
+   }
return true
 }
 
+func (c *zookeeperDynamicConfiguration) removeWatcher(watcher *zk.Watcher) {
+   if watcher == nil || c.client == nil || c.client.Conn == nil {
+   return
+   }
+   c.client.Conn.RemoveWatcher(watcher)

Review Comment:
   
fixed;已在go-zookeeper侧,将invalidateWatcher改为原子读:https://github.com/dubbogo/go-zookeeper/pull/12



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-19 Thread via GitHub


ywxzm03 commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5352453825

   > > 执行`make 
test-race`时,`TestCacheListenerRemoveListenerDropsWatchAtAutoLimit`和`TestRestartCallBackResetsCache`发生了数据竞争;原因是单测中执行到`defer
 cluster.Stop()`时,停止 ZooKeeper 
服务端,接着`Conn.loop`检测到网络断开,触发的`setState`与`removeWatcher()`中的`invalidateWatcher()`存在并发访问窗口,发生了state的读写竞争(前者是原子写,但后者却是普通读);由于后来reviewer提出要引入zk服务端依赖,这个数据竞争问题得以才暴露出来;
   > > 
若要解决这个问题,可以在dubbogo/go-zookeeper中将`invalidateWatcher`的state读取改为已有的原子读取`State()`即可,是否需要我去`dubbogo/go-zookeeper`那提个pr改一下这个小问题?
   > 
   > 提一下吧
   
   
fixed;已在go-zookeeper侧,将invalidateWatcher改为原子读:https://github.com/dubbogo/go-zookeeper/pull/12


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-19 Thread via GitHub


AlexStocks commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3819234090


##
config_center/zookeeper/impl.go:
##
@@ -274,9 +343,22 @@ func (c *zookeeperDynamicConfiguration) closeConfigs() {
 }
 
 func (c *zookeeperDynamicConfiguration) RestartCallBack() bool {
+   for _, watcher := range c.cache.reset() {
+   c.removeWatcher(watcher)
+   }
+   if c.cacheListener != nil {
+   c.cacheListener.restoreBusinessWatches()
+   }
return true
 }
 
+func (c *zookeeperDynamicConfiguration) removeWatcher(watcher *zk.Watcher) {
+   if watcher == nil || c.client == nil || c.client.Conn == nil {
+   return
+   }
+   c.client.Conn.RemoveWatcher(watcher)

Review Comment:
   [P1] 这里新增的 `RemoveWatcher` 会直接触发当前 go-zookeeper 依赖中的并发读写竞态。当前 Head 的 Unit 
Test 已在 `TestRestartCallBackResetsCache` 和 
`TestCacheListenerRemoveListenerDropsWatchAtAutoLimit` 稳定报 race:连接循环在 
`setState` 写 `Conn.state`,`RemoveWatcher -> invalidateWatcher` 同时读取该字段;另一处 
`CacheListener.removeWatcher` 也走同一路径。Base 没有任何 `RemoveWatcher` 调用,因此这是本 PR 
新增路径,当前 Unit Test 也因此失败。请先升级/修复依赖使 watcher invalidation 
使用一致的原子访问或同步,再保留主动移除逻辑,并让这两个真实 ZooKeeper `-race` 用例通过。



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-19 Thread via GitHub


Alanxtl commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5351888150

   > 执行`make 
test-race`时,`TestCacheListenerRemoveListenerDropsWatchAtAutoLimit`和`TestRestartCallBackResetsCache`发生了数据竞争;原因是单测中执行到`defer
 cluster.Stop()`时,停止 ZooKeeper 
服务端,接着`Conn.loop`检测到网络断开,触发的`setState`与`removeWatcher()`中的`invalidateWatcher()`存在并发访问窗口,发生了state的读写竞争(前者是原子写,但后者却是普通读);由于后来reviewer提出要引入zk服务端依赖,这个数据竞争问题得以才暴露出来;
   > 
   > 
若要解决这个问题,可以在dubbogo/go-zookeeper中将`invalidateWatcher`的state读取改为已有的原子读取`State()`即可,是否需要我去`dubbogo/go-zookeeper`那提个pr改一下这个小问题?
   
   提一下吧


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-19 Thread via GitHub


ywxzm03 commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5351794135

   执行`make 
test-race`时,`TestCacheListenerRemoveListenerDropsWatchAtAutoLimit`和`TestRestartCallBackResetsCache`发生了race;原因是单测中执行到`defer
 cluster.Stop()`时,停止 ZooKeeper 
服务端,接着`Conn.loop`检测到网络断开,触发的`setState`与`removeWatcher()`中的`invalidateWatcher()`存在并发访问窗口,发生了state的读写竞争(前者是原子写,但后者却是普通读);由于后来reviewer提出要引入zk服务端依赖,这个race才暴露出来;
   
   
若要解决这个问题,可以在dubbogo/go-zookeeper中将`invalidateWatcher`的state读取改为已有的原子读取`State()`即可,是否需要我去`dubbogo/go-zookeeper`那提个pr改一下这个小问题?


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-19 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5344393519

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [1.8% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-19 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5342412240

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [1.8% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-19 Thread via GitHub


ywxzm03 commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3813125589


##
config_center/zookeeper/impl_test.go:
##
@@ -126,6 +138,335 @@ func TestGetPropertiesWithMockZk(t *testing.T) {
require.Empty(t, empty)
 }
 
+func TestLoadPropertiesRegistersWatchOnlyWhenInactive(t *testing.T) {
+   cluster, client, events, err := 
gxzookeeper.NewMockZookeeperClient("watch-selection", 5*time.Second)
+   if err != nil {
+   t.Skipf("skip mock zk setup: %v", err)
+   }
+   defer cluster.Stop()
+
+   cfg := &zookeeperDynamicConfiguration{
+   rootPath: "/dubbo/config",
+   client:   client,
+   url:  mustURL(t, "registry://127.0.0.1:2181"),
+   cache:newConfigCache(time.Minute),
+   }
+   activePath := cfg.getPath("active", "group")
+   inactivePath := cfg.getPath("inactive", "group")
+   require.NoError(t, cfg.PublishConfig("active", "group", "v1"))
+   require.NoError(t, cfg.PublishConfig("inactive", "group", "v1"))
+
+   waitForEvent := func(path string, timeout time.Duration) bool {
+   timer := time.NewTimer(timeout)
+   defer timer.Stop()
+   for {
+   select {
+   case event := <-events:
+   if event.Path == path && event.Type == 
zk.EventNodeDataChanged {
+   return true
+   }
+   case <-timer.C:
+   return false
+   }
+   }
+   }
+
+   activeWatcher := &zk.Watcher{}
+   _, watcher, err := cfg.loadProperties(activePath, activeWatcher, false)
+   require.NoError(t, err)
+   require.Same(t, activeWatcher, watcher)
+   _, stat, err := client.GetContent(activePath)
+   require.NoError(t, err)
+   _, err = client.SetContent(activePath, []byte("v2"), stat.Version)
+   require.NoError(t, err)
+   require.False(t, waitForEvent(activePath, time.Second))
+
+   _, watcher, err = cfg.loadProperties(inactivePath, nil, true)
+   require.NoError(t, err)
+   require.NotNil(t, watcher)
+   _, stat, err = client.GetContent(inactivePath)
+   require.NoError(t, err)
+   _, err = client.SetContent(inactivePath, []byte("v2"), stat.Version)
+   require.NoError(t, err)
+   require.True(t, waitForEvent(inactivePath, time.Second))
+}
+
+func TestListenerUsesGroupOption(t *testing.T) {
+   cluster, client, _, err := 
gxzookeeper.NewMockZookeeperClient("listener-group", 5*time.Second)
+   if err != nil {
+   t.Skipf("skip mock zk setup: %v", err)
+   }
+   defer cluster.Stop()
+
+   zkListener := remotingzookeeper.NewZkEventListener(client)
+   defer zkListener.Close()
+   cfg := &zookeeperDynamicConfiguration{
+   rootPath: "/dubbo/config",
+   client:   client,
+   url:  mustURL(t, "registry://127.0.0.1:2181"),
+   cache:newConfigCache(time.Minute),
+   listener: zkListener,
+   }
+   cfg.cacheListener = newCacheListener(cfg.rootPath, zkListener, 
&cfg.cache)
+   key := "app.properties"
+   group := "custom"
+   path := cfg.getPropertiesPath(key, config_center.WithGroup(group))
+   rec := &recListener{}
+
+   cfg.AddListener(key, rec, config_center.WithGroup(group))
+   _, ok := cfg.cacheListener.keyListeners.Load(path)
+   require.True(t, ok)
+
+   cfg.RemoveListener(key, rec, config_center.WithGroup(group))
+   _, ok = cfg.cacheListener.keyListeners.Load(path)
+   require.False(t, ok)
+}
+
+func TestGetPropertiesFallsBackToTTLAtAutoWatchLimit(t *testing.T) {
+   cluster, client, events, err := 
gxzookeeper.NewMockZookeeperClient("watch-limit", 5*time.Second)
+   if err != nil {
+   t.Skipf("skip mock zk setup: %v", err)
+   }
+   defer cluster.Stop()
+
+   cfg := &zookeeperDynamicConfiguration{
+   rootPath: "/dubbo/config",
+   client:   client,
+   url:  mustURL(t, "registry://127.0.0.1:2181"),
+   cache:newConfigCache(time.Minute),
+   }
+   for i := range maxAutoWatches {
+   require.True(t, cfg.cache.setWatch(fmt.Sprintf("/watch/%d", i), 
configWatchState{
+   watcher: &zk.Watcher{},
+   auto:true,
+   }))
+   }
+
+   require.NoError(t, cfg.PublishConfig("fallback", "group", "v1"))
+   value, err := cfg.GetProperties("fallback", 
config_center.WithGroup("group"))
+   require.NoError(t, err)
+   require.Equal(t, "v1", value)
+
+   path := cfg.getPath("fallback", "group")
+   _, watchState := cfg.cache.snapshot(path)
+   require.False(t, watchState.tracked())
+   require.Equal(t, 

Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-18 Thread via GitHub


AlexStocks commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3810174359


##
config_center/zookeeper/impl_test.go:
##
@@ -126,6 +138,335 @@ func TestGetPropertiesWithMockZk(t *testing.T) {
require.Empty(t, empty)
 }
 
+func TestLoadPropertiesRegistersWatchOnlyWhenInactive(t *testing.T) {
+   cluster, client, events, err := 
gxzookeeper.NewMockZookeeperClient("watch-selection", 5*time.Second)
+   if err != nil {
+   t.Skipf("skip mock zk setup: %v", err)
+   }
+   defer cluster.Stop()
+
+   cfg := &zookeeperDynamicConfiguration{
+   rootPath: "/dubbo/config",
+   client:   client,
+   url:  mustURL(t, "registry://127.0.0.1:2181"),
+   cache:newConfigCache(time.Minute),
+   }
+   activePath := cfg.getPath("active", "group")
+   inactivePath := cfg.getPath("inactive", "group")
+   require.NoError(t, cfg.PublishConfig("active", "group", "v1"))
+   require.NoError(t, cfg.PublishConfig("inactive", "group", "v1"))
+
+   waitForEvent := func(path string, timeout time.Duration) bool {
+   timer := time.NewTimer(timeout)
+   defer timer.Stop()
+   for {
+   select {
+   case event := <-events:
+   if event.Path == path && event.Type == 
zk.EventNodeDataChanged {
+   return true
+   }
+   case <-timer.C:
+   return false
+   }
+   }
+   }
+
+   activeWatcher := &zk.Watcher{}
+   _, watcher, err := cfg.loadProperties(activePath, activeWatcher, false)
+   require.NoError(t, err)
+   require.Same(t, activeWatcher, watcher)
+   _, stat, err := client.GetContent(activePath)
+   require.NoError(t, err)
+   _, err = client.SetContent(activePath, []byte("v2"), stat.Version)
+   require.NoError(t, err)
+   require.False(t, waitForEvent(activePath, time.Second))
+
+   _, watcher, err = cfg.loadProperties(inactivePath, nil, true)
+   require.NoError(t, err)
+   require.NotNil(t, watcher)
+   _, stat, err = client.GetContent(inactivePath)
+   require.NoError(t, err)
+   _, err = client.SetContent(inactivePath, []byte("v2"), stat.Version)
+   require.NoError(t, err)
+   require.True(t, waitForEvent(inactivePath, time.Second))
+}
+
+func TestListenerUsesGroupOption(t *testing.T) {
+   cluster, client, _, err := 
gxzookeeper.NewMockZookeeperClient("listener-group", 5*time.Second)
+   if err != nil {
+   t.Skipf("skip mock zk setup: %v", err)
+   }
+   defer cluster.Stop()
+
+   zkListener := remotingzookeeper.NewZkEventListener(client)
+   defer zkListener.Close()
+   cfg := &zookeeperDynamicConfiguration{
+   rootPath: "/dubbo/config",
+   client:   client,
+   url:  mustURL(t, "registry://127.0.0.1:2181"),
+   cache:newConfigCache(time.Minute),
+   listener: zkListener,
+   }
+   cfg.cacheListener = newCacheListener(cfg.rootPath, zkListener, 
&cfg.cache)
+   key := "app.properties"
+   group := "custom"
+   path := cfg.getPropertiesPath(key, config_center.WithGroup(group))
+   rec := &recListener{}
+
+   cfg.AddListener(key, rec, config_center.WithGroup(group))
+   _, ok := cfg.cacheListener.keyListeners.Load(path)
+   require.True(t, ok)
+
+   cfg.RemoveListener(key, rec, config_center.WithGroup(group))
+   _, ok = cfg.cacheListener.keyListeners.Load(path)
+   require.False(t, ok)
+}
+
+func TestGetPropertiesFallsBackToTTLAtAutoWatchLimit(t *testing.T) {
+   cluster, client, events, err := 
gxzookeeper.NewMockZookeeperClient("watch-limit", 5*time.Second)
+   if err != nil {
+   t.Skipf("skip mock zk setup: %v", err)
+   }
+   defer cluster.Stop()
+
+   cfg := &zookeeperDynamicConfiguration{
+   rootPath: "/dubbo/config",
+   client:   client,
+   url:  mustURL(t, "registry://127.0.0.1:2181"),
+   cache:newConfigCache(time.Minute),
+   }
+   for i := range maxAutoWatches {
+   require.True(t, cfg.cache.setWatch(fmt.Sprintf("/watch/%d", i), 
configWatchState{
+   watcher: &zk.Watcher{},
+   auto:true,
+   }))
+   }
+
+   require.NoError(t, cfg.PublishConfig("fallback", "group", "v1"))
+   value, err := cfg.GetProperties("fallback", 
config_center.WithGroup("group"))
+   require.NoError(t, err)
+   require.Equal(t, "v1", value)
+
+   path := cfg.getPath("fallback", "group")
+   _, watchState := cfg.cache.snapshot(path)
+   require.False(t, watchState.tracked())
+   require.Equal(t, 

Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-18 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5329717110

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [1.9% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-16 Thread via GitHub


Alanxtl commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5312507238

   we are fixing the ci fail https://github.com/apache/dubbo-go/pull/3669


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-16 Thread via GitHub


ywxzm03 commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3794081315


##
config_center/zookeeper/listener.go:
##
@@ -58,31 +88,157 @@ func (l *CacheListener) AddListener(key string, listener 
config_center.Configura

listeners.(map[config_center.ConfigurationListener]struct{})[listener] = 
struct{}{}
l.keyListeners.Store(key, listeners)
}
+   if l.cache != nil {
+   l.cache.promoteWatch(key)
+   }
+}
+
+func (l *CacheListener) restoreBusinessWatches() {
+   if l.cache == nil || !l.cache.enabled() || l.zkEventListener == nil ||
+   l.zkEventListener.Client == nil || 
l.zkEventListener.Client.Conn == nil {
+   return
+   }

Review Comment:
   fixed



##
config_center/zookeeper/config_cache.go:
##
@@ -0,0 +1,433 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package zookeeper
+
+import (
+   "sync"
+   "time"
+)
+
+import (
+   "github.com/dubbogo/go-zookeeper/zk"
+
+   "github.com/hashicorp/golang-lru"
+)
+
+const (
+   pathLockShardCount = 128
+   maxCacheEntries= 1024
+   maxAutoWatches = 1024
+)
+
+type configCacheEntry struct {
+   content   string
+   existsbool
+   expiresAt time.Time
+}
+
+type configWatchState struct {
+   watcher *zk.Watcher
+   autobool
+   pending bool
+}
+
+func (s configWatchState) tracked() bool {
+   return s.watcher != nil || s.pending
+}
+
+func (s configWatchState) holdsAutoSlot() bool {
+   return s.auto && s.tracked()
+}
+
+func (s configWatchState) holdsAutoWatch() bool {
+   return s.auto && s.watcher != nil
+}
+
+func (s configWatchState) holdsAutoReservation() bool {
+   return s.auto && s.pending
+}
+
+type configCache struct {
+   ttl time.Duration
+
+   stateLock sync.RWMutex
+   entries   *lru.Cache
+   watches   map[string]configWatchState
+   autoWatchCountint
+   autoWatchReservations int
+   generationuint64
+
+   pathLocks [pathLockShardCount]sync.Mutex
+}
+
+func newConfigCache(ttl time.Duration) configCache {
+   entries, err := lru.New(maxCacheEntries)
+   if err != nil {
+   panic(err)
+   }
+   return configCache{
+   ttl: ttl,
+   entries: entries,
+   watches: make(map[string]configWatchState),
+   }
+}
+
+func (c *configCache) enabled() bool {
+   return c.ttl > 0
+}
+
+func (c *configCache) load(
+   path string,
+   loader func(*zk.Watcher, bool) (configCacheEntry, *zk.Watcher, error),
+   removeWatcher func(*zk.Watcher),
+) (configCacheEntry, error) {
+   if !c.enabled() {
+   entry, _, err := loader(nil, false)
+   return entry, err
+   }
+   if entry, ok := c.getFresh(path); ok {
+   return entry, nil
+   }
+
+   pathLock := c.pathLock(path)
+   pathLock.Lock()
+   defer pathLock.Unlock()
+
+   for {
+   if entry, ok := c.getFresh(path); ok {
+   return entry, nil
+   }
+
+   generation, watchState, registerWatch := c.prepareLoad(path)
+   entry, watcher, err := loader(watchState.watcher, registerWatch)
+   nextWatchState := watchState
+   if registerWatch {
+   nextWatchState = configWatchState{}
+   if watcher != nil {
+   nextWatchState = configWatchState{watcher: 
watcher, auto: true}
+   }
+   }
+   if err != nil {
+   if !c.storeWatchState(path, generation, nextWatchState) 
{
+   if registerWatch {
+   removeRegisteredWatcher(removeWatcher, 
watcher)
+   }
+   continue
+   }
+   return configCacheEntry{}, err
+   }
+   if !c.storeLoad(path, generation, entry, nextWatchState) {
+   

Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-16 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5312358045

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [1.9% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-14 Thread via GitHub


AlexStocks commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3788484596


##
config_center/zookeeper/listener.go:
##
@@ -58,31 +88,157 @@ func (l *CacheListener) AddListener(key string, listener 
config_center.Configura

listeners.(map[config_center.ConfigurationListener]struct{})[listener] = 
struct{}{}
l.keyListeners.Store(key, listeners)
}
+   if l.cache != nil {
+   l.cache.promoteWatch(key)
+   }
+}
+
+func (l *CacheListener) restoreBusinessWatches() {
+   if l.cache == nil || !l.cache.enabled() || l.zkEventListener == nil ||
+   l.zkEventListener.Client == nil || 
l.zkEventListener.Client.Conn == nil {
+   return
+   }

Review Comment:
   [P1] cache-ttl=0 的重连路径仍会永久丢失业务 watch
   
   当前 AddListener 在缓存关闭时仍会为业务 listener 建立 ZooKeeper watch;重连后 RestartCallBack() 
会先 reset 旧 watch,再调用这里恢复。但这里在 !l.cache.enabled() 
时直接返回,因此缓存关闭这一受支持配置下没有任何重新注册路径,后续节点更新不会再通知 listener。请把业务 watch 的恢复与 
read-through cache 是否启用解耦,并补充 cache-ttl=0 -> AddListener -> reconnect -> 
更新节点仍收到事件 的回归测试。



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-14 Thread via GitHub


Copilot commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3788385437


##
config_center/zookeeper/listener.go:
##
@@ -58,31 +88,157 @@ func (l *CacheListener) AddListener(key string, listener 
config_center.Configura

listeners.(map[config_center.ConfigurationListener]struct{})[listener] = 
struct{}{}
l.keyListeners.Store(key, listeners)
}
+   if l.cache != nil {
+   l.cache.promoteWatch(key)
+   }
+}
+
+func (l *CacheListener) restoreBusinessWatches() {
+   if l.cache == nil || !l.cache.enabled() || l.zkEventListener == nil ||
+   l.zkEventListener.Client == nil || 
l.zkEventListener.Client.Conn == nil {
+   return
+   }

Review Comment:
   `restoreBusinessWatches` returns early when `cache-ttl` disables the cache 
(`!l.cache.enabled()`). ZooKeeper reconnects still invalidate *all* watches 
(including those created by `AddListener`), so with cache disabled listeners 
may stop receiving updates after a reconnect because no re-registration happens 
(see `config_center/zookeeper/impl.go:345-351`).



##
config_center/zookeeper/config_cache.go:
##
@@ -0,0 +1,433 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package zookeeper
+
+import (
+   "sync"
+   "time"
+)
+
+import (
+   "github.com/dubbogo/go-zookeeper/zk"
+
+   "github.com/hashicorp/golang-lru"
+)
+
+const (
+   pathLockShardCount = 128
+   maxCacheEntries= 1024
+   maxAutoWatches = 1024
+)
+
+type configCacheEntry struct {
+   content   string
+   existsbool
+   expiresAt time.Time
+}
+
+type configWatchState struct {
+   watcher *zk.Watcher
+   autobool
+   pending bool
+}
+
+func (s configWatchState) tracked() bool {
+   return s.watcher != nil || s.pending
+}
+
+func (s configWatchState) holdsAutoSlot() bool {
+   return s.auto && s.tracked()
+}
+
+func (s configWatchState) holdsAutoWatch() bool {
+   return s.auto && s.watcher != nil
+}
+
+func (s configWatchState) holdsAutoReservation() bool {
+   return s.auto && s.pending
+}
+
+type configCache struct {
+   ttl time.Duration
+
+   stateLock sync.RWMutex
+   entries   *lru.Cache
+   watches   map[string]configWatchState
+   autoWatchCountint
+   autoWatchReservations int
+   generationuint64
+
+   pathLocks [pathLockShardCount]sync.Mutex
+}
+
+func newConfigCache(ttl time.Duration) configCache {
+   entries, err := lru.New(maxCacheEntries)
+   if err != nil {
+   panic(err)
+   }
+   return configCache{
+   ttl: ttl,
+   entries: entries,
+   watches: make(map[string]configWatchState),
+   }
+}
+
+func (c *configCache) enabled() bool {
+   return c.ttl > 0
+}
+
+func (c *configCache) load(
+   path string,
+   loader func(*zk.Watcher, bool) (configCacheEntry, *zk.Watcher, error),
+   removeWatcher func(*zk.Watcher),
+) (configCacheEntry, error) {
+   if !c.enabled() {
+   entry, _, err := loader(nil, false)
+   return entry, err
+   }
+   if entry, ok := c.getFresh(path); ok {
+   return entry, nil
+   }
+
+   pathLock := c.pathLock(path)
+   pathLock.Lock()
+   defer pathLock.Unlock()
+
+   for {
+   if entry, ok := c.getFresh(path); ok {
+   return entry, nil
+   }
+
+   generation, watchState, registerWatch := c.prepareLoad(path)
+   entry, watcher, err := loader(watchState.watcher, registerWatch)
+   nextWatchState := watchState
+   if registerWatch {
+   nextWatchState = configWatchState{}
+   if watcher != nil {
+   nextWatchState = configWatchState{watcher: 
watcher, auto: true}
+   }
+   }
+   if err != nil {
+   if !c.storeWatchState(path, generation, nextWatchState) 
{
+   if 

Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-14 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5300118643

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-14 Thread via GitHub


Alanxtl commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5299579940

   update to the latest develop to fix the ci fail


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-14 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5297770250

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-14 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5297454252

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-14 Thread via GitHub


ywxzm03 commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3786643315


##
config_center/zookeeper/impl.go:
##


Review Comment:
   fixed



##
config_center/zookeeper/listener_test.go:
##
@@ -62,6 +68,48 @@ func TestCacheListenerDataChangeEmptyContent(t *testing.T) {
if len(rec.events) != 1 || rec.events[0].ConfigType != 
remoting.EventTypeDel {
t.Fatalf("unexpected events %+v", rec.events)
}
+   entry, ok := cache.getFresh(path)
+   if !ok || !entry.exists || entry.content != "" {
+   t.Fatalf("empty configuration should be cached as existing: 
%+v", entry)
+   }
+
+   l.DataChange(remoting.Event{Path: path, Action: remoting.EventTypeDel})
+   entry, ok = cache.getFresh(path)
+   if !ok || entry.exists {
+   t.Fatalf("deleted configuration should be cached as missing: 
%+v", entry)
+   }
+}
+
+func TestCacheListenerIgnoresEventAcrossReset(t *testing.T) {
+   cache := newConfigCache(time.Minute)
+   l := &CacheListener{rootPath: "/dubbo/config", cache: &cache}
+   path := "/dubbo/config/group/app"
+   pathLock := cache.pathLock(path)
+   pathLock.Lock()
+   watchStateDone := make(chan struct{})
+   go func() {
+   l.WatchStateChanged(path, false)
+   close(watchStateDone)
+   }()
+   require.Eventually(t, func() bool {
+   _, ok := l.eventGeneration.Load(path)
+   return ok
+   }, time.Second, time.Millisecond)
+
+   cache.reset()
+   pathLock.Unlock()
+   <-watchStateDone
+   l.WatchStateChanged(path, true)
+   l.DataChange(remoting.Event{Path: path, Action: 
remoting.EventTypeUpdate, Content: "old"})
+
+   _, ok := cache.getFresh(path)
+   if ok {
+   t.Fatal("event started before reset should not repopulate 
cache")
+   }
+   _, watchActive := cache.snapshot(path)
+   if watchActive {
+   t.Fatal("event started before reset should not reactivate watch 
state")
+   }

Review Comment:
   fixed



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-14 Thread via GitHub


ywxzm03 commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3786642100


##
config_center/zookeeper/config_cache.go:
##
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package zookeeper
+
+import (
+   "sync"
+   "time"
+)
+
+type configCacheEntry struct {
+   content   string
+   existsbool
+   expiresAt time.Time
+}
+
+type configCache struct {
+   ttl time.Duration
+
+   stateLock  sync.RWMutex
+   entriesmap[string]configCacheEntry
+   watchesmap[string]bool
+   generation uint64
+
+   pathLocks sync.Map
+}
+
+func newConfigCache(ttl time.Duration) configCache {
+   return configCache{
+   ttl: ttl,
+   entries: make(map[string]configCacheEntry),
+   watches: make(map[string]bool),
+   }
+}
+
+func (c *configCache) enabled() bool {
+   return c.ttl > 0
+}
+
+func (c *configCache) load(path string, loader func(bool) (configCacheEntry, 
bool, error)) (configCacheEntry, error) {
+   if !c.enabled() {
+   entry, _, err := loader(false)
+   return entry, err
+   }
+   if entry, ok := c.getFresh(path); ok {
+   return entry, nil
+   }
+
+   pathLock := c.pathLock(path)
+   pathLock.Lock()
+   defer pathLock.Unlock()
+
+   for {
+   if entry, ok := c.getFresh(path); ok {
+   return entry, nil
+   }
+
+   generation, watchActive := c.snapshot(path)
+   entry, nextWatchActive, err := loader(watchActive)
+   if err != nil {
+   if !c.storeWatchState(path, generation, 
nextWatchActive) {
+   continue
+   }
+   return configCacheEntry{}, err
+   }
+   if !c.storeLoad(path, generation, entry, nextWatchActive) {
+   continue
+   }
+   return entry, nil
+   }
+}
+
+func (c *configCache) store(path string, entry configCacheEntry) {
+   if !c.enabled() {
+   return
+   }
+   pathLock := c.pathLock(path)
+   pathLock.Lock()
+   defer pathLock.Unlock()
+
+   c.stateLock.Lock()
+   defer c.stateLock.Unlock()
+   c.storeEntryLocked(path, entry)
+}
+
+func (c *configCache) storeAtGeneration(path string, generation uint64, entry 
configCacheEntry) {
+   if !c.enabled() {
+   return
+   }
+   pathLock := c.pathLock(path)
+   pathLock.Lock()
+   defer pathLock.Unlock()
+
+   c.stateLock.Lock()
+   defer c.stateLock.Unlock()
+   if c.generation == generation {
+   c.storeEntryLocked(path, entry)
+   }
+}
+
+func (c *configCache) getFresh(path string) (configCacheEntry, bool) {
+   c.stateLock.RLock()
+   defer c.stateLock.RUnlock()
+
+   entry, ok := c.entries[path]
+   if !ok {
+   return configCacheEntry{}, false
+   }
+   return entry, entry.expiresAt.After(time.Now())
+}
+
+func (c *configCache) storeEntryLocked(path string, entry configCacheEntry) {
+   entry.expiresAt = time.Now().Add(c.ttl)
+   c.entries[path] = entry
+}
+
+func (c *configCache) snapshot(path string) (uint64, bool) {
+   c.stateLock.RLock()
+   defer c.stateLock.RUnlock()
+   return c.generation, c.watches[path]
+}
+
+func (c *configCache) isCurrentGeneration(generation uint64) bool {
+   c.stateLock.RLock()
+   defer c.stateLock.RUnlock()
+   return c.generation == generation
+}
+
+func (c *configCache) storeLoad(path string, generation uint64, entry 
configCacheEntry, watchActive bool) bool {
+   c.stateLock.Lock()
+   defer c.stateLock.Unlock()
+   if c.generation != generation {
+   return false
+   }
+
+   c.storeEntryLocked(path, entry)
+   c.setWatchActiveLocked(path, watchActive)
+   return true
+}
+
+func (c *configCache) storeWatchState(path string, generation uint64, 
watchActive bool) bool {
+   c.stateLock.Lock()
+   defer c.stateLock.Unlock()
+   if c.generation != generation {

Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-14 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5297389477

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-14 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5297371748

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [3 New 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-11 Thread via GitHub


Alanxtl commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3757261481


##
config_center/zookeeper/impl.go:
##


Review Comment:
   Public `RemoveListener` 删除不到 `AddListener` 注册的 listener  
   
   `AddListener` 存的是 `buildPath(rootPath, namespace/key)`,但 `RemoveListener` 
直接拿原始 `key` 去删,路径不一致,实际移除失败。并且 `AddListener` 也仍然忽略传入的 `options` group。PR 描述说修了 
group/option path handling,但代码没有完整做到。
   



##
config_center/zookeeper/config_cache.go:
##
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package zookeeper
+
+import (
+   "sync"
+   "time"
+)
+
+type configCacheEntry struct {
+   content   string
+   existsbool
+   expiresAt time.Time
+}
+
+type configCache struct {
+   ttl time.Duration
+
+   stateLock  sync.RWMutex
+   entriesmap[string]configCacheEntry
+   watchesmap[string]bool
+   generation uint64
+
+   pathLocks sync.Map
+}

Review Comment:
   
   `entries` / `watches` 只判断过期,不删除;`pathLocks sync.Map` 永不回收,`reset()` 
也不清理。`GetProperties` 的 key/group 是外部输入,动态 dataId、错误 key、探测 key 
多了以后,内存会线性增长。这个问题 PR 里已经有人评论了,我同意是 P1,需要 bounded cache 或 TTL/LRU 回收。
   



##
config_center/zookeeper/listener_test.go:
##
@@ -62,6 +68,48 @@ func TestCacheListenerDataChangeEmptyContent(t *testing.T) {
if len(rec.events) != 1 || rec.events[0].ConfigType != 
remoting.EventTypeDel {
t.Fatalf("unexpected events %+v", rec.events)
}
+   entry, ok := cache.getFresh(path)
+   if !ok || !entry.exists || entry.content != "" {
+   t.Fatalf("empty configuration should be cached as existing: 
%+v", entry)
+   }
+
+   l.DataChange(remoting.Event{Path: path, Action: remoting.EventTypeDel})
+   entry, ok = cache.getFresh(path)
+   if !ok || entry.exists {
+   t.Fatalf("deleted configuration should be cached as missing: 
%+v", entry)
+   }
+}
+
+func TestCacheListenerIgnoresEventAcrossReset(t *testing.T) {
+   cache := newConfigCache(time.Minute)
+   l := &CacheListener{rootPath: "/dubbo/config", cache: &cache}
+   path := "/dubbo/config/group/app"
+   pathLock := cache.pathLock(path)
+   pathLock.Lock()
+   watchStateDone := make(chan struct{})
+   go func() {
+   l.WatchStateChanged(path, false)
+   close(watchStateDone)
+   }()
+   require.Eventually(t, func() bool {
+   _, ok := l.eventGeneration.Load(path)
+   return ok
+   }, time.Second, time.Millisecond)
+
+   cache.reset()
+   pathLock.Unlock()
+   <-watchStateDone
+   l.WatchStateChanged(path, true)
+   l.DataChange(remoting.Event{Path: path, Action: 
remoting.EventTypeUpdate, Content: "old"})
+
+   _, ok := cache.getFresh(path)
+   if ok {
+   t.Fatal("event started before reset should not repopulate 
cache")
+   }
+   _, watchActive := cache.snapshot(path)
+   if watchActive {
+   t.Fatal("event started before reset should not reactivate watch 
state")
+   }

Review Comment:
   “空内容节点”和“不存在节点”的区分没有贯穿 listener 语义  

   缓存写入时会把 empty content 作为 exists=true 存下来,但随后 `event.Content == ""` 仍然把 
change type 改成 `EventTypeDel`。所以监听者和 metrics 看到的还是删除事件。测试 
`listener_test.go:64-73` 甚至把这个行为固化了。



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-08 Thread via GitHub


AlexStocks commented on code in PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#discussion_r3740276207


##
config_center/zookeeper/config_cache.go:
##
@@ -0,0 +1,237 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package zookeeper
+
+import (
+   "sync"
+   "time"
+)
+
+type configCacheEntry struct {
+   content   string
+   existsbool
+   expiresAt time.Time
+}
+
+type configCache struct {
+   ttl time.Duration
+
+   stateLock  sync.RWMutex
+   entriesmap[string]configCacheEntry
+   watchesmap[string]bool
+   generation uint64
+
+   pathLocks sync.Map
+}
+
+func newConfigCache(ttl time.Duration) configCache {
+   return configCache{
+   ttl: ttl,
+   entries: make(map[string]configCacheEntry),
+   watches: make(map[string]bool),
+   }
+}
+
+func (c *configCache) enabled() bool {
+   return c.ttl > 0
+}
+
+func (c *configCache) load(path string, loader func(bool) (configCacheEntry, 
bool, error)) (configCacheEntry, error) {
+   if !c.enabled() {
+   entry, _, err := loader(false)
+   return entry, err
+   }
+   if entry, ok := c.getFresh(path); ok {
+   return entry, nil
+   }
+
+   pathLock := c.pathLock(path)
+   pathLock.Lock()
+   defer pathLock.Unlock()
+
+   for {
+   if entry, ok := c.getFresh(path); ok {
+   return entry, nil
+   }
+
+   generation, watchActive := c.snapshot(path)
+   entry, nextWatchActive, err := loader(watchActive)
+   if err != nil {
+   if !c.storeWatchState(path, generation, 
nextWatchActive) {
+   continue
+   }
+   return configCacheEntry{}, err
+   }
+   if !c.storeLoad(path, generation, entry, nextWatchActive) {
+   continue
+   }
+   return entry, nil
+   }
+}
+
+func (c *configCache) store(path string, entry configCacheEntry) {
+   if !c.enabled() {
+   return
+   }
+   pathLock := c.pathLock(path)
+   pathLock.Lock()
+   defer pathLock.Unlock()
+
+   c.stateLock.Lock()
+   defer c.stateLock.Unlock()
+   c.storeEntryLocked(path, entry)
+}
+
+func (c *configCache) storeAtGeneration(path string, generation uint64, entry 
configCacheEntry) {
+   if !c.enabled() {
+   return
+   }
+   pathLock := c.pathLock(path)
+   pathLock.Lock()
+   defer pathLock.Unlock()
+
+   c.stateLock.Lock()
+   defer c.stateLock.Unlock()
+   if c.generation == generation {
+   c.storeEntryLocked(path, entry)
+   }
+}
+
+func (c *configCache) getFresh(path string) (configCacheEntry, bool) {
+   c.stateLock.RLock()
+   defer c.stateLock.RUnlock()
+
+   entry, ok := c.entries[path]
+   if !ok {
+   return configCacheEntry{}, false
+   }
+   return entry, entry.expiresAt.After(time.Now())
+}
+
+func (c *configCache) storeEntryLocked(path string, entry configCacheEntry) {
+   entry.expiresAt = time.Now().Add(c.ttl)
+   c.entries[path] = entry
+}
+
+func (c *configCache) snapshot(path string) (uint64, bool) {
+   c.stateLock.RLock()
+   defer c.stateLock.RUnlock()
+   return c.generation, c.watches[path]
+}
+
+func (c *configCache) isCurrentGeneration(generation uint64) bool {
+   c.stateLock.RLock()
+   defer c.stateLock.RUnlock()
+   return c.generation == generation
+}
+
+func (c *configCache) storeLoad(path string, generation uint64, entry 
configCacheEntry, watchActive bool) bool {
+   c.stateLock.Lock()
+   defer c.stateLock.Unlock()
+   if c.generation != generation {
+   return false
+   }
+
+   c.storeEntryLocked(path, entry)
+   c.setWatchActiveLocked(path, watchActive)
+   return true
+}
+
+func (c *configCache) storeWatchState(path string, generation uint64, 
watchActive bool) bool {
+   c.stateLock.Lock()
+   defer c.stateLock.Unlock()
+   if c.generation != generation 

Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-06 Thread via GitHub


codecov-commenter commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5212718788

   ## 
[Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 Report
   :x: Patch coverage is `47.03390%` with `125 lines` in your changes missing 
coverage. Please review.
   :white_check_mark: Project coverage is 53.90%. Comparing base 
([`60d1c2a`](https://app.codecov.io/gh/apache/dubbo-go/commit/60d1c2a949f0ee0da4be3fe09fb79d295491e040?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`9ce4e2e`](https://app.codecov.io/gh/apache/dubbo-go/commit/9ce4e2e23d1ee9de8fdcdbc549da3d74d4060535?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 896 commits behind head on develop.
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Patch % | Lines |
   |---|---|---|
   | 
[config\_center/zookeeper/impl.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?src=pr&el=tree&filepath=config_center%2Fzookeeper%2Fimpl.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29uZmlnX2NlbnRlci96b29rZWVwZXIvaW1wbC5nbw==)
 | 9.83% | [50 Missing and 5 partials :warning: 
](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   | 
[config\_center/zookeeper/config\_cache.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?src=pr&el=tree&filepath=config_center%2Fzookeeper%2Fconfig_cache.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29uZmlnX2NlbnRlci96b29rZWVwZXIvY29uZmlnX2NhY2hlLmdv)
 | 67.69% | [34 Missing and 8 partials :warning: 
](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   | 
[config\_center/zookeeper/listener.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?src=pr&el=tree&filepath=config_center%2Fzookeeper%2Flistener.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y29uZmlnX2NlbnRlci96b29rZWVwZXIvbGlzdGVuZXIuZ28=)
 | 54.83% | [13 Missing and 1 partial :warning: 
](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   | 
[remoting/zookeeper/listener.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?src=pr&el=tree&filepath=remoting%2Fzookeeper%2Flistener.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cmVtb3Rpbmcvem9va2VlcGVyL2xpc3RlbmVyLmdv)
 | 0.00% | [14 Missing :warning: 
](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 |
   
   Additional details and impacted files
   
   
   
   ```diff
   @@ Coverage Diff @@
   ##   develop#3612  +/-   ##
   ===
   + Coverage46.76%   53.90%   +7.13% 
   ===
 Files  295  475 +180 
 Lines1717236600   +19428 
   ===
   + Hits  803119729   +11698 
   - Misses828715281+6994 
   - Partials   854 1590 +736 
   ```
   
   
   [:umbrella: View full report in Codecov by 
Harness](https://app.codecov.io/gh/apache/dubbo-go/pull/3612?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   :loudspeaker: Have feedback on the report? [Share it 
here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:rocket: New features to boost your workflow: 
   
   - :snowflake: [Test 
Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, 
report on failures, and find test suite problems.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:

Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-06 Thread via GitHub


sonarqubecloud[bot] commented on PR #3612:
URL: https://github.com/apache/dubbo-go/pull/3612#issuecomment-5212695031

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [1 New 
issue](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3612&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3612&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3612&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3612)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-06 Thread via GitHub


ywxzm03 closed pull request #3611: Feat: Add ZK config cache
URL: https://github.com/apache/dubbo-go/pull/3611


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



Re: [PR] Feat: Add ZK config cache [dubbo-go]

2026-08-06 Thread via GitHub


sonarqubecloud[bot] commented on PR #3611:
URL: https://github.com/apache/dubbo-go/pull/3611#issuecomment-5212524694

   ## [![Quality Gate 
Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png
 'Quality Gate 
Passed')](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3611) 
**Quality Gate passed**  
   Issues  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [1 New 
issue](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3611&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png
 '') [0 Accepted 
issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3611&issueStatuses=ACCEPTED)
   
   Measures  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0 Security 
Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3611&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Coverage on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3611&metric=new_coverage&view=list)
  
   
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png
 '') [0.0% Duplication on New 
Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3611&metric=new_duplicated_lines_density&view=list)
  
 
   
   [See analysis details on SonarQube 
Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3611)
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


-
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]