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]