XnLemon commented on code in PR #3369:
URL: https://github.com/apache/dubbo-go/pull/3369#discussion_r3385019792


##########
metadata/report_instance.go:
##########
@@ -51,21 +58,46 @@ func addMetadataReport(registryId string, url *common.URL) 
error {
        return nil
 }
 
+// GetMetadataReport returns a single metadata report for callers that lack
+// registry context. It prefers the "default" registry's report; when absent
+// it falls back to the lexicographically first registry id so the selection
+// is always stable across calls.
 func GetMetadataReport() report.MetadataReport {
-       for _, v := range instances {
-               return v
+       if r, ok := instances[constant.DefaultKey]; ok {
+               return r
+       }
+       keys := make([]string, 0, len(instances))
+       for k := range instances {
+               keys = append(keys, k)
+       }
+       sort.Strings(keys)
+       if len(keys) > 0 {
+               return instances[keys[0]]
        }
        return nil
 }
 
+// GetMetadataReportByRegistry returns the metadata report bound to the given
+// registry id. When the registry id is empty the caller has no registry 
context,
+// so the stable default returned by GetMetadataReport is used. When a specific
+// (non-empty) registry id is not found, it falls back to the "default" report
+// if one exists. This handles the common case where a standalone 
metadata-report
+// config is registered under "default" while named registries (e.g. nacos, zk)
+// need to use it. nil is returned only when neither the specific id nor 
"default"
+// is registered.
 func GetMetadataReportByRegistry(registry string) report.MetadataReport {
        if len(registry) == 0 {
-               registry = constant.DefaultKey
+               return GetMetadataReport()
        }
        if r, ok := instances[registry]; ok {
                return r
        }
-       return GetMetadataReport()
+       if r, ok := instances[constant.DefaultKey]; ok {
+               logger.Infof("[Metadata] no metadata report bound to 
registryId=%s, falling back to default", registry)
+               return r
+       }
+       logger.Warnf("[Metadata] no metadata report found for registryId=%s", 
registry)
+       return nil

Review Comment:
   预期行为 不改了



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