Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4a0ec86
fix(metadata): make GetMetadataReport() deterministic in multi-regist…
XnLemon Jun 3, 2026
3e9ebc6
fix(metadata): Remove() fans out to all reports, consistent with Map()
XnLemon Jun 3, 2026
7ff288d
fix(metadata): thread registryId through GetMetadataFromMetadataRepor…
XnLemon Jun 4, 2026
4e83c0c
fix(metadata): scope revision calculation to per-registry services, t…
XnLemon Jun 4, 2026
7ebc49f
fix(metadata): GetMetadataReportByRegistry returns nil for unknown re…
XnLemon Jun 4, 2026
8008879
fix(metadata): ServiceNameMapping.Remove collects all errors instead …
XnLemon Jun 4, 2026
38ab94b
test: expand coverage for per-registry metadata report selection
XnLemon Jun 4, 2026
9ec6abc
chore: translate Chinese comments to English, remove UTF-8 BOM
XnLemon Jun 4, 2026
2388f30
style(metadata): fix import formatting
XnLemon Jun 4, 2026
663d4cf
fix(registry): upgrade missing-registryId log from Warn to Error with…
XnLemon Jun 4, 2026
e18c4b3
fix(registry): scope metaCache key to (registryId, revision) to preve…
XnLemon Jun 4, 2026
bd33338
docs(registry): restore TODO for multi-instance metadata service URL …
XnLemon Jun 4, 2026
5276882
Revert "docs(registry): restore TODO for multi-instance metadata serv…
xianingawa-wq Jun 4, 2026
a117cbd
style(metadata): fix import formatting
xianingawa-wq Jun 4, 2026
36719da
fix(debug) : fix review problems
xianingawa-wq Jun 7, 2026
a18c95c
style(metadata): fix format issue && revert some changes
xianingawa-wq Jun 8, 2026
81160b7
fix(metadata): update tests and comment to match default fallback in …
xianingawa-wq Jun 8, 2026
dbedc14
fix: address review comments on clarify-metadata-report-selection
XnLemon Jun 10, 2026
91b9136
fix: fix test isolation and cache key format after review changes
XnLemon Jun 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(metadata): make GetMetadataReport() deterministic in multi-regist…
…ry setup
  • Loading branch information
XnLemon authored and xianingawa-wq committed Jun 8, 2026
commit 4a0ec864ce4dc49af52312aed9a4bf7e7443ebd9
17 changes: 15 additions & 2 deletions metadata/report_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package metadata

import (
"sort"
"time"
)

Expand Down Expand Up @@ -51,9 +52,21 @@ 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
}
Expand Down
22 changes: 22 additions & 0 deletions metadata/report_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ func TestGetMetadataReport(t *testing.T) {
assert.NotNil(t, GetMetadataReport())
}

func TestGetMetadataReportIsDeterministic(t *testing.T) {
instances = make(map[string]report.MetadataReport)
r1 := new(mockMetadataReport)
r2 := new(mockMetadataReport)
// "aaa" 字母序在 "zzz" 之前,两者均不是 "default"
instances["zzz"] = r1
instances["aaa"] = r2

// 没有 "default" key 时,必须始终返回字母序第一个(r2)
for range 20 {
got := GetMetadataReport()
assert.Equal(t, r2, got, "期望返回 'aaa' 对应的 report")
}

// 存在 "default" key 时,必须始终返回它(r1),优先级高于字母序
instances[constant.DefaultKey] = r1
for range 20 {
got := GetMetadataReport()
assert.Equal(t, r1, got, "期望返回 'default' 对应的 report")
}
}

func TestGetMetadataReportByRegistry(t *testing.T) {
instances = make(map[string]report.MetadataReport)
assert.Nil(t, GetMetadataReportByRegistry("reg"))
Expand Down