Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ef8cee4
feat(metadata): add internal RWMutex for MetadataInfo and fix json se…
jieguo-coder Jun 3, 2026
605d0b2
feat(metadata): add lock protection for global registry and instances…
jieguo-coder Jun 3, 2026
abf50a7
feat(metadata): fix concurrency safety in listener callbacks and exte…
jieguo-coder Jun 3, 2026
8bc0aaa
style: format import blocks using dubbo-go imports-formatter
jieguo-coder Jun 3, 2026
ea83f92
style: format metadata.go and report_instance.go to pass CI
jieguo-coder Jun 3, 2026
0048c16
fix(metadata): resolve data races pointed out in code review
jieguo-coder Jun 4, 2026
e65f694
test: fix failing tests and improve unit test coverage
jieguo-coder Jun 4, 2026
a7bad03
test: fix testifylint error by avoiding require in goroutines
jieguo-coder Jun 4, 2026
3cf2c5a
fix(metadata): deep copy ServiceInfo to prevent write-on-read data ra…
jieguo-coder Jun 7, 2026
9bf63a0
chore: trigger CI re-run for codecov gpg issue
jieguo-coder Jun 7, 2026
21cedcc
chore: resolve merge conflicts with develop and fix code formatting
jieguo-coder Jun 7, 2026
1bd679e
refactor(metadata): implement no-lock helper to fix data race and avo…
jieguo-coder Jun 11, 2026
c77d53a
chore: resolve merge conflict with #3369, integrating deterministic f…
jieguo-coder Jun 11, 2026
f8d3248
test: fix compilation error in instance changed listener tests by add…
jieguo-coder Jun 11, 2026
d3f571d
fix(metadata): add RLock around global map lookup in RemoveService an…
jieguo-coder Jun 13, 2026
3bf11e4
chore: resolve merge conflicts with #3370, keeping DeepCopy for concu…
jieguo-coder Jun 13, 2026
11cc932
chore: resolve test file conflict by keeping both listener and cache …
jieguo-coder Jun 13, 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
feat(metadata): add internal RWMutex for MetadataInfo and fix json se…
…rialization (#3353)

Add sync.RWMutex to MetadataInfo struct with json:"-" / hessian:"-"
tags to skip serialization. All mutating methods (AddService, RemoveService,
AddSubscribeURL, RemoveSubscribeURL) acquire the write lock, and read
methods (GetExportedServiceURLs, GetSubscribedURLs, GetServices) acquire
the read lock. The new GetServices method returns a snapshot copy.

Signed-off-by: jieguo-coder <1193249232@qq.com>
  • Loading branch information
jieguo-coder committed Jun 3, 2026
commit ef8cee49c3377dc8716aa6f845d2e4d226a82a55
32 changes: 32 additions & 0 deletions metadata/info/metadata_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/url"
"strconv"
"strings"
"sync"
)

import (
Expand Down Expand Up @@ -63,6 +64,7 @@ type MetadataInfo struct {
Services map[string]*ServiceInfo `json:"services,omitempty" hessian:"services"`
exportedServiceURLs map[string][]*common.URL `hessian:"-"` // server exported service urls
subscribedServiceURLs map[string][]*common.URL `hessian:"-"` // client subscribed service urls
mu sync.RWMutex `json:"-" hessian:"-"`
}

func NewAppMetadataInfo(app string) *MetadataInfo {
Expand Down Expand Up @@ -95,6 +97,9 @@ func (info *MetadataInfo) JavaClassName() string {

// AddService add provider service info to MetadataInfo
func (info *MetadataInfo) AddService(url *common.URL) {
info.mu.Lock()
defer info.mu.Unlock()

service := NewServiceInfoWithURL(url)
info.Services[service.GetMatchKey()] = service
addUrl(info.exportedServiceURLs, url)
Expand Down Expand Up @@ -131,22 +136,34 @@ func deleteItem(slice []*common.URL, index int) []*common.URL {
}

func (info *MetadataInfo) RemoveService(url *common.URL) {
info.mu.Lock()
defer info.mu.Unlock()

service := NewServiceInfoWithURL(url)
delete(info.Services, service.GetMatchKey())
removeUrl(info.exportedServiceURLs, url)
}

// AddSubscribeURL client subscribe a service url
func (info *MetadataInfo) AddSubscribeURL(url *common.URL) {
info.mu.Lock()
defer info.mu.Unlock()

addUrl(info.subscribedServiceURLs, url)
}

// RemoveSubscribeURL client unsubscribe a service url
func (info *MetadataInfo) RemoveSubscribeURL(url *common.URL) {
info.mu.Lock()
defer info.mu.Unlock()

removeUrl(info.subscribedServiceURLs, url)
}

func (info *MetadataInfo) GetExportedServiceURLs() []*common.URL {
info.mu.RLock()
defer info.mu.RUnlock()

res := make([]*common.URL, 0)
for _, urls := range info.exportedServiceURLs {
res = append(res, urls...)
Expand All @@ -155,13 +172,28 @@ func (info *MetadataInfo) GetExportedServiceURLs() []*common.URL {
}

func (info *MetadataInfo) GetSubscribedURLs() []*common.URL {
info.mu.RLock()
defer info.mu.RUnlock()

res := make([]*common.URL, 0)
for _, urls := range info.subscribedServiceURLs {
res = append(res, urls...)
}
return res
}

// GetServices returns a copy of the Services map for safe iteration by external callers.
func (info *MetadataInfo) GetServices() map[string]*ServiceInfo {
info.mu.RLock()
defer info.mu.RUnlock()

cp := make(map[string]*ServiceInfo, len(info.Services))
for k, v := range info.Services {
cp[k] = v
}
return cp
}

// ServiceInfo the information of service
type ServiceInfo struct {
Name string `json:"name,omitempty" hessian:"name"`
Expand Down