Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #1214 - go race detect (#1220) #1222

Merged
merged 2 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions cluster/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ import (
// Extension - Directory
type Directory interface {
common.Node

// List candidate invoker list for the current Directory.
// NOTICE: The invoker list returned to the caller may be backed by the same data hold by the current Directory
// implementation for the sake of performance consideration. This requires the caller of List() shouldn't modify
// the return result directly.
List(invocation protocol.Invocation) []protocol.Invoker
}
11 changes: 6 additions & 5 deletions registry/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func init() {
type RegistryDirectory struct {
directory.BaseDirectory
cacheInvokers []protocol.Invoker
listenerLock sync.Mutex
invokersLock sync.RWMutex
serviceType string
registry registry.Registry
cacheInvokersMap *sync.Map // use sync.map
Expand Down Expand Up @@ -230,8 +230,8 @@ func (dir *RegistryDirectory) invokerCacheKey(event *registry.ServiceEvent) stri
// setNewInvokers groups the invokers from the cache first, then set the result to both directory and router chain.
func (dir *RegistryDirectory) setNewInvokers() {
newInvokers := dir.toGroupInvokers()
dir.listenerLock.Lock()
defer dir.listenerLock.Unlock()
dir.invokersLock.Lock()
defer dir.invokersLock.Unlock()
dir.cacheInvokers = newInvokers
dir.RouterChain().SetInvokers(newInvokers)
}
Expand Down Expand Up @@ -386,11 +386,12 @@ func (dir *RegistryDirectory) doCacheInvoker(newUrl *common.URL) (protocol.Invok

// List selected protocol invokers from the directory
func (dir *RegistryDirectory) List(invocation protocol.Invocation) []protocol.Invoker {
invokers := dir.cacheInvokers
routerChain := dir.RouterChain()

if routerChain == nil {
return invokers
dir.invokersLock.RLock()
defer dir.invokersLock.RUnlock()
return dir.cacheInvokers
}
return routerChain.Route(dir.consumerURL, invocation)
}
Expand Down