Qiao-yq commented on code in PR #3578:
URL: https://github.com/apache/dubbo-go/pull/3578#discussion_r3719133336
##########
metadata/info/metadata_info.go:
##########
@@ -287,8 +288,8 @@ func NewServiceInfoWithURL(url *common.URL) *ServiceInfo {
}
}
}
- p[constant.MethodsKey] = strings.Join(url.Methods, ",")
service.Params = p
+ service.Methods = url.Methods
Review Comment:
<img width="1793" height="1321" alt="image"
src="https://github.com/user-attachments/assets/49dd8a8a-e54d-4300-91b2-ae69d0d99d10"
/>
不应将 methods 从 Params 迁移到独立字段,
Java Dubbo 3.3 的 ServiceInfo 没有独立的 methods 字段,方法列表保存在 params 中,并参与
toDescString() 和 revision 计算。另外,MetadataServiceV2 的 protobuf 没有 methods
字段,当前转换逻辑也只传输 Params。迁移后,方法列表会在 V2 metadata 往返过程中丢失。
##########
metadata/info/metadata_info.go:
##########
@@ -364,90 +364,79 @@ func (si *ServiceInfo) DeepCopy() *ServiceInfo {
Port: si.Port,
Path: si.Path,
Params: params,
+ Methods: methods,
ServiceKey: si.GetServiceKey(),
MatchKey: si.GetMatchKey(),
URL: si.URL,
}
}
// toDescString returns a deterministic string representation of ServiceInfo
-// for revision calculation. Aligned with Java dubbo
ServiceInfo.toDescString().
+// for revision calculation. It strictly mirrors the Java dubbo
+// ServiceInfo.toDescString() algorithm so that CalRevision produces the exact
+// same 32-char lowercase MD5 digest as the Java side.
+//
+// Format (no separators between segments, methods are excluded):
//
-// Format: name|group|version|protocol|port|path|params|methods
+// getMatchKey() + port + path + sortedTreeMap(params).toString()
//
-// Empty fields use "" as placeholder to keep separator count stable.
-// Params are sorted by key alphabetically, joined as k=v&k=v.
-// The "methods" key is excluded from params and appended separately.
-// Methods are sorted alphabetically and comma-joined.
-// No escaping is performed on param values (aligned with Java behavior).
+// where:
+// - getMatchKey() = serviceKey + ":" + protocol (protocol must be non-empty)
+// - port is the int value concatenated verbatim
+// - path is concatenated verbatim
+// - The params TreeMap string uses Java's TreeMap.toString() format:
+// "{k1=v1, k2=v2}" — braces wrapped, "key=value" joined by ", ",
+// keys in natural ascending order. An empty params map renders as "{}".
+// - Methods are intentionally NOT part of the revision serialization.
func (si *ServiceInfo) toDescString() string {
- var b strings.Builder
+ return si.GetMatchKey() + strconv.Itoa(si.Port) + si.Path +
renderParams(si.Params)
+}
- b.WriteString(si.Name)
- b.WriteByte('|')
- b.WriteString(si.Group)
- b.WriteByte('|')
- b.WriteString(si.Version)
- b.WriteByte('|')
- b.WriteString(si.Protocol)
- b.WriteByte('|')
- b.WriteString(strconv.Itoa(si.Port))
- b.WriteByte('|')
- b.WriteString(si.Path)
- b.WriteByte('|')
-
- // params: sorted keys, exclude methods key
- keys := make([]string, 0, len(si.Params))
- for k := range si.Params {
- if k == constant.MethodsKey {
- continue
- }
+// renderParams renders a param map as a Java TreeMap.toString() equivalent:
+// "{k1=v1, k2=v2}" with keys in natural ascending order, joined by ", ".
+// An empty map renders as "{}". This mirrors Java's
+// `new TreeMap<>(params).toString()` used by ServiceInfo.toDescString(), which
+// is what makes the revision digest byte-for-byte identical to the Java side.
Review Comment:
https://github.com/apache/dubbo/blob/3.3/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/DefaultMetadataParamsFilter.java#L38-L65
这里虽然对齐了参数序列化格式,但现有 Go IncludeKeys 与 Java 默认过滤规则有一些不同,Go 包含 timestamp,Java
默认排除它。
--
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]