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

route call optimize #1244

Merged
merged 5 commits into from
Jun 25, 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
15 changes: 5 additions & 10 deletions cluster/directory/base_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

import (
"github.com/apache/dubbo-go/cluster/router"
"github.com/apache/dubbo-go/cluster/router/chain"
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
Expand All @@ -44,15 +43,11 @@ type BaseDirectory struct {
}

// NewBaseDirectory Create BaseDirectory with URL
func NewBaseDirectory(url *common.URL) (dir BaseDirectory) {
dir = BaseDirectory{
url: url,
destroyed: atomic.NewBool(false),
routerChain: &chain.RouterChain{},
func NewBaseDirectory(url *common.URL) BaseDirectory {
return BaseDirectory{
url: url,
destroyed: atomic.NewBool(false),
}
// start to listen notify
go dir.routerChain.Loop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why will you delete this code? if you delete this code , router will not effect no longer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为baseDirectory在new的时候不需要创建routerChain,因为我没有创建任何路由策略,所不需要loop

return
}

// RouterChain Return router chain in directory
Expand All @@ -79,7 +74,7 @@ func (dir *BaseDirectory) GetDirectoryUrl() *common.URL {

// AddRouters Convert url to routers and add them into dir.routerChain
func (dir *BaseDirectory) AddRouters(urls []*common.URL) {
if len(urls) == 0 {
if len(urls) == 0 || dir.routerChain == nil {
return
}

Expand Down
1 change: 0 additions & 1 deletion cluster/directory/static_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func NewStaticDirectory(invokers []protocol.Invoker) *staticDirectory {
invokers: invokers,
}

dir.routerChain.SetInvokers(invokers)
return dir
}

Expand Down
5 changes: 4 additions & 1 deletion registry/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ func (dir *RegistryDirectory) setNewInvokers() {
dir.invokersLock.Lock()
defer dir.invokersLock.Unlock()
dir.cacheInvokers = newInvokers
dir.RouterChain().SetInvokers(newInvokers)
routerChain := dir.RouterChain()
if routerChain != nil {
routerChain.SetInvokers(newInvokers)
}
}

// cacheInvokerByEvent caches invokers from the service event
Expand Down