Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
305aa06b
Commit
305aa06b
authored
5 years ago
by
邹毅贤
Browse files
Options
Downloads
Patches
Plain Diff
fix router init bug
parent
09d77773
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cluster/directory/base_directory.go
+16
-0
16 additions, 0 deletions
cluster/directory/base_directory.go
cluster/router/chain/chain.go
+2
-2
2 additions, 2 deletions
cluster/router/chain/chain.go
registry/directory/directory.go
+1
-17
1 addition, 17 deletions
registry/directory/directory.go
with
19 additions
and
19 deletions
cluster/directory/base_directory.go
+
16
−
0
View file @
305aa06b
...
...
@@ -23,6 +23,7 @@ import (
import
(
"github.com/dubbogo/gost/container/set"
perrors
"github.com/pkg/errors"
"go.uber.org/atomic"
)
...
...
@@ -33,6 +34,7 @@ import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/common/extension"
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/protocol"
)
var
routerURLSet
=
gxset
.
NewSet
()
...
...
@@ -131,3 +133,17 @@ func GetRouterURLSet() *gxset.HashSet {
func
AddRouterURLSet
(
url
*
common
.
URL
)
{
routerURLSet
.
Add
(
url
)
}
// BuildRouterChain build router chain by invokers
func
(
dir
*
staticDirectory
)
BuildRouterChain
(
invokers
[]
protocol
.
Invoker
)
error
{
if
len
(
invokers
)
==
0
{
return
perrors
.
Errorf
(
"invokers == null"
)
}
url
:=
invokers
[
0
]
.
GetUrl
()
routerChain
,
e
:=
chain
.
NewRouterChain
(
&
url
)
if
e
!=
nil
{
return
e
}
dir
.
SetRouterChain
(
routerChain
)
return
nil
}
This diff is collapsed.
Click to expand it.
cluster/router/chain/chain.go
+
2
−
2
View file @
305aa06b
...
...
@@ -49,7 +49,7 @@ type RouterChain struct {
}
// Route Loop routers in RouterChain and call Route method to determine the target invokers list.
func
(
c
RouterChain
)
Route
(
invoker
[]
protocol
.
Invoker
,
url
*
common
.
URL
,
invocation
protocol
.
Invocation
)
[]
protocol
.
Invoker
{
func
(
c
*
RouterChain
)
Route
(
invoker
[]
protocol
.
Invoker
,
url
*
common
.
URL
,
invocation
protocol
.
Invocation
)
[]
protocol
.
Invoker
{
finalInvokers
:=
invoker
l
:=
len
(
c
.
routers
)
rs
:=
make
([]
router
.
Router
,
l
,
int
(
math
.
Ceil
(
float64
(
l
)
*
1.2
)))
...
...
@@ -67,7 +67,7 @@ func (c RouterChain) Route(invoker []protocol.Invoker, url *common.URL, invocati
// New a array add builtinRouters which is not sorted in RouterChain and routers
// Sort the array
// Replace router array in RouterChain
func
(
c
RouterChain
)
AddRouters
(
routers
[]
router
.
Router
)
{
func
(
c
*
RouterChain
)
AddRouters
(
routers
[]
router
.
Router
)
{
newRouters
:=
make
([]
router
.
Router
,
0
,
len
(
c
.
builtinRouters
)
+
len
(
routers
))
newRouters
=
append
(
newRouters
,
c
.
builtinRouters
...
)
newRouters
=
append
(
newRouters
,
routers
...
)
...
...
This diff is collapsed.
Click to expand it.
registry/directory/directory.go
+
1
−
17
View file @
305aa06b
...
...
@@ -29,7 +29,6 @@ import (
import
(
"github.com/apache/dubbo-go/cluster/directory"
"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"
...
...
@@ -178,34 +177,19 @@ func (dir *registryDirectory) toGroupInvokers() []protocol.Invoker {
//len is 1 it means no group setting ,so do not need cluster again
for
_
,
invokers
:=
range
groupInvokersMap
{
groupInvokersList
=
invokers
dir
.
buildRouterChain
(
invokers
)
}
}
else
{
for
_
,
invokers
:=
range
groupInvokersMap
{
staticDir
:=
directory
.
NewStaticDirectory
(
invokers
)
cluster
:=
extension
.
GetCluster
(
dir
.
GetUrl
()
.
SubURL
.
GetParam
(
constant
.
CLUSTER_KEY
,
constant
.
DEFAULT_CLUSTER
))
staticDir
.
BuildRouterChain
(
invokers
)
groupInvokersList
=
append
(
groupInvokersList
,
cluster
.
Join
(
staticDir
))
dir
.
buildRouterChain
(
invokers
)
}
}
return
groupInvokersList
}
func
(
dir
*
registryDirectory
)
buildRouterChain
(
invokers
[]
protocol
.
Invoker
)
error
{
if
len
(
invokers
)
==
0
{
return
perrors
.
Errorf
(
"invokers == null"
)
}
url
:=
invokers
[
0
]
.
GetUrl
()
routerChain
,
e
:=
chain
.
NewRouterChain
(
&
url
)
if
e
!=
nil
{
return
e
}
dir
.
SetRouterChain
(
routerChain
)
return
nil
}
func
(
dir
*
registryDirectory
)
uncacheInvoker
(
url
*
common
.
URL
)
{
logger
.
Debugf
(
"service will be deleted in cache invokers: invokers key is %s!"
,
url
.
Key
())
dir
.
cacheInvokersMap
.
Delete
(
url
.
Key
())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment