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
Prev Previous commit
Next Next commit
fix(metadata): GetMetadataReportByRegistry returns nil for unknown re…
…gistryId instead of silently falling back to wrong registry

When a caller provides a specific non-empty registryId that has no
registered report, the previous implementation silently fell back to
GetMetadataReport() and returned an arbitrary report from a different
registry. This undermined the per-registry scoping added in the earlier
commits: metadata for registry A could be fetched from registry B's
report without any indication.

Fix: return nil (with a Warnf log) when a specific registryId is not
found. The existing nil-guard in GetMetadataFromMetadataReport (client.go)
already surfaces this as an error to the caller, which is the correct
behaviour.

The empty-string path is unchanged: it still delegates to
GetMetadataReport() because callers that pass "" have no registry
context and should receive the stable default.

Also expose ClearMetadataReportInstances() to allow cross-package test
isolation of the package-level instances map.
  • Loading branch information
XnLemon authored and xianingawa-wq committed Jun 8, 2026
commit 7ebc49f29f4779cf05e892bf73f42c22052f9059
27 changes: 18 additions & 9 deletions metadata/report_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,30 @@ package metadata
import (
"sort"
"time"
)

import (
"github.com/dubbogo/gost/container/set"
"github.com/dubbogo/gost/log/logger"
)

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/metadata/info"
"dubbo.apache.org/dubbo-go/v3/metadata/mapping"
"dubbo.apache.org/dubbo-go/v3/metadata/report"
"dubbo.apache.org/dubbo-go/v3/metrics"
gxset "github.com/dubbogo/gost/container/set"
"github.com/dubbogo/gost/log/logger"

metadataMetrics "dubbo.apache.org/dubbo-go/v3/metrics/metadata"
)

var (
instances = make(map[string]report.MetadataReport)
)

// ClearMetadataReportInstances resets the package-level instances map.
// Intended for test isolation only; do not call in production code.
func ClearMetadataReportInstances() {
instances = make(map[string]report.MetadataReport)
}
Comment thread
Alanxtl marked this conversation as resolved.
Resolved

func addMetadataReport(registryId string, url *common.URL) error {
fac := extension.GetMetadataReportFactory(url.Protocol)
if fac == nil {
Expand Down Expand Up @@ -71,14 +73,21 @@ func GetMetadataReport() report.MetadataReport {
return nil
}

// GetMetadataReportByRegistry returns the metadata report bound to the given
// registry id. When registry 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 given but is not registered, nil is returned so
// the caller receives an explicit failure rather than silently operating
// against the wrong registry's report.
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()
logger.Warnf("[Metadata] no metadata report found for registryId=%s", registry)
return nil
Comment thread
XnLemon marked this conversation as resolved.
Resolved
}

func GetMetadataReports() []report.MetadataReport {
Expand Down
34 changes: 30 additions & 4 deletions metadata/report_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,37 @@ func TestGetMetadataReportIsDeterministic(t *testing.T) {

func TestGetMetadataReportByRegistry(t *testing.T) {
instances = make(map[string]report.MetadataReport)
// nothing registered: all paths return nil
assert.Nil(t, GetMetadataReportByRegistry(""))
assert.Nil(t, GetMetadataReportByRegistry("reg"))
instances["default"] = new(mockMetadataReport)
assert.NotNil(t, GetMetadataReportByRegistry("default"))
assert.NotNil(t, GetMetadataReportByRegistry("reg"))
assert.NotNil(t, GetMetadataReportByRegistry(""))

defaultReport := new(mockMetadataReport)
instances["default"] = defaultReport

// exact hit
assert.Equal(t, defaultReport, GetMetadataReportByRegistry("default"))
// empty string → no registry context → falls through to GetMetadataReport() → "default"
assert.Equal(t, defaultReport, GetMetadataReportByRegistry(""))
// specific but unknown id → nil (not a silent wrong-registry fallback)
assert.Nil(t, GetMetadataReportByRegistry("reg"))
}

func TestGetMetadataReportByRegistryFallsBackDeterministically(t *testing.T) {
instances = make(map[string]report.MetadataReport)
rA := new(mockMetadataReport)
rB := new(mockMetadataReport)
instances["aaa"] = rA // lex-first
instances["zzz"] = rB

// known key → exact report
assert.Equal(t, rA, GetMetadataReportByRegistry("aaa"))
assert.Equal(t, rB, GetMetadataReportByRegistry("zzz"))

// unknown specific id → nil, not the lex-first fallback
assert.Nil(t, GetMetadataReportByRegistry("unknown-registry"))

// empty string → falls through to GetMetadataReport() → lex-first ("aaa" → rA)
assert.Equal(t, rA, GetMetadataReportByRegistry(""))
}

func TestGetMetadataReports(t *testing.T) {
Expand Down