AsperforMias commented on code in PR #3798:
URL: https://github.com/apache/dubbo-go/pull/3798#discussion_r4501579421


##########
metadata/report/zookeeper/report.go:
##########
@@ -89,6 +90,57 @@ type zookeeperMetadataReport struct {
        url           *common.URL
 }
 
+var _ report.ServiceDefinitionPublisher = (*zookeeperMetadataReport)(nil)
+
+// PublishServiceDefinition implements report.ServiceDefinitionPublisher. It
+// stores one interface-level service definition at the node Java's
+// ZookeeperMetadataReport writes for a provider MetadataIdentifier, which is
+// also the subtree Dubbo Admin watches:
+//
+//     {root}/metadata/{interface}/{version}/{group}/provider/{application}
+//
+// Admin takes the service name, version and group from the JSON body and only
+// uses the path to tell provider definitions apart ("provider" must be the
+// second-to-last segment). So the path shape and the interface escaping are
+// what must match Java; everything else travels in the body.
+//
+// The node is persistent and overwritten without a version check. Instances
+// of one application normally derive identical definitions, so last writer
+// wins is harmless. During a rolling upgrade old and new instances may
+// overwrite each other until the old ones are gone; a compare-and-set would
+// not decide which version is right either, so it is not worth the retries.
+func (m *zookeeperMetadataReport) PublishServiceDefinition(serviceInterface, 
version, group, application, definitionJSON string) error {
+       // Java escapes the interface with URLEncoder. url.QueryEscape matches 
it
+       // except that URLEncoder keeps '*' and escapes '~', so patch those two
+       // characters; otherwise names containing them would land on another 
node.
+       encoded := 
strings.ReplaceAll(strings.ReplaceAll(url.QueryEscape(serviceInterface), "%2A", 
"*"), "~", "%7E")
+       if serviceInterface == "*" {
+               encoded = "" // Java maps the wildcard interface to an empty 
segment.
+       }
+       root := strings.TrimSuffix(m.rootDir, "/")
+       // dubbo-go writes app metadata directly under rootDir, while Java 
keeps it
+       // under {root}/metadata, so some users set the group to 
"dubbo/metadata".
+       // Java would then write .../metadata/metadata/..., which Admin never
+       // watches. We deliberately strip the suffix so definitions still land
+       // under /dubbo/metadata; with the default root the path equals Java's.
+       root = strings.TrimSuffix(root, "/metadata")

Review Comment:
   done



-- 
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]

Reply via email to