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): ServiceNameMapping.Remove collects all errors instead …
…of returning only the last one

The previous implementation used a lastErr variable that was overwritten
on each iteration. If the first report failed and the second succeeded,
the error was silently discarded and the caller saw no error despite a
partial failure — leaving a stale mapping in the first registry.

Fix: collect all errors with errors.Join so the caller receives the full
failure picture. The loop continues past individual failures (best-effort
fan-out) so a transient error in one registry does not prevent removal
from the others.

Add a comment explaining the intentional behavioural difference from
Map(), which is fail-fast: Map stops at the first report failure, while
Remove continues and collects all errors so every reachable registry gets
the removal attempt.
  • Loading branch information
XnLemon authored and xianingawa-wq committed Jun 8, 2026
commit 8008879a94a14e99f5a5dd0cd27167063a6d04e2
13 changes: 10 additions & 3 deletions metadata/mapping/metadata/service_name_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package metadata

import (
"errors"
"sync"
)

Expand Down Expand Up @@ -96,17 +97,23 @@ func (d *ServiceNameMapping) Get(url *common.URL, listener mapping.MappingListen
return metadataReport.GetServiceAppMapping(serviceInterface, DefaultGroup, listener)
}

// Remove removes the service-to-app mapping for the given URL from all
// registered metadata reports. Unlike Map (which stops on the first failure),
// Remove is best-effort: it attempts every report and returns all errors
// joined together so the caller can see the full failure picture. The
// intent is to avoid leaving stale entries in any registry due to a transient
// error in one of the others.
func (d *ServiceNameMapping) Remove(url *common.URL) error {
serviceInterface := url.GetParam(constant.InterfaceKey, "")
metadataReports := metadata.GetMetadataReports()
if len(metadataReports) == 0 {
Comment thread
Alanxtl marked this conversation as resolved.
Resolved
return perrors.New("can not remove mapping in remote cause no metadata report instance found")
}
var lastErr error
var errs []error
for _, metadataReport := range metadataReports {
if err := metadataReport.RemoveServiceAppMappingListener(serviceInterface, DefaultGroup); err != nil {
lastErr = err
errs = append(errs, err)
}
}
return lastErr
return errors.Join(errs...)
}
62 changes: 62 additions & 0 deletions metadata/mapping/metadata/service_name_mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func initMockWithId(t *testing.T, registryId string) *mockMetadataReport {
}

func TestServiceNameMappingRemoveFansOutToAllReports(t *testing.T) {
metadata.ClearMetadataReportInstances()
t.Cleanup(metadata.ClearMetadataReportInstances)
serviceNameMappingOnce = sync.Once{}
serviceNameMappingInstance = nil

Expand All @@ -177,6 +179,66 @@ func TestServiceNameMappingRemoveFansOutToAllReports(t *testing.T) {
r2.AssertExpectations(t)
}

func TestServiceNameMappingRemoveCollectsAllErrors(t *testing.T) {
metadata.ClearMetadataReportInstances()
t.Cleanup(metadata.ClearMetadataReportInstances)
serviceNameMappingOnce = sync.Once{}
serviceNameMappingInstance = nil

r1 := initMockWithId(t, "reg-c")
r2 := initMockWithId(t, "reg-d")

ins := GetNameMappingInstance()
serviceUrl := common.NewURLWithOptions(
common.WithInterface("org.example.BarService"),
common.WithParamsValue(constant.ApplicationKey, "bar-app"),
)

err1 := errors.New("r1 failure")
err2 := errors.New("r2 failure")

// both reports fail
r1.On("RemoveServiceAppMappingListener").Return(err1).Once()
r2.On("RemoveServiceAppMappingListener").Return(err2).Once()

err := ins.Remove(serviceUrl)
require.Error(t, err)
// both individual errors must be present in the returned error
require.ErrorIs(t, err, err1)
require.ErrorIs(t, err, err2)
r1.AssertExpectations(t)
r2.AssertExpectations(t)
}

func TestServiceNameMappingRemoveContinuesAfterPartialFailure(t *testing.T) {
metadata.ClearMetadataReportInstances()
t.Cleanup(metadata.ClearMetadataReportInstances)
serviceNameMappingOnce = sync.Once{}
serviceNameMappingInstance = nil

r1 := initMockWithId(t, "reg-e")
r2 := initMockWithId(t, "reg-f")

ins := GetNameMappingInstance()
serviceUrl := common.NewURLWithOptions(
common.WithInterface("org.example.BazService"),
common.WithParamsValue(constant.ApplicationKey, "baz-app"),
)

removeErr := errors.New("r1 partial failure")

// r1 fails, r2 succeeds — the loop must not short-circuit
r1.On("RemoveServiceAppMappingListener").Return(removeErr).Once()
r2.On("RemoveServiceAppMappingListener").Return(nil).Once()

err := ins.Remove(serviceUrl)
// the joined error only contains r1's error; the call should error
require.ErrorIs(t, err, removeErr)
// both reports must have been called despite r1's failure
r1.AssertExpectations(t)
r2.AssertExpectations(t)
}

type listener struct {
}

Expand Down