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
b04224bb
Commit
b04224bb
authored
4 years ago
by
watermelo
Browse files
Options
Downloads
Patches
Plain Diff
Fix: fix tag router rule copy
parent
e3610678
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cluster/router/tag/router_rule.go
+9
-9
9 additions, 9 deletions
cluster/router/tag/router_rule.go
cluster/router/tag/tag_router.go
+4
-7
4 additions, 7 deletions
cluster/router/tag/tag_router.go
with
13 additions
and
16 deletions
cluster/router/tag/router_rule.go
+
9
−
9
View file @
b04224bb
...
...
@@ -41,8 +41,8 @@ import (
type
RouterRule
struct
{
router
.
BaseRouterRule
`yaml:",inline"`
Tags
[]
Tag
a
ddressToTagNames
map
[
string
][]
string
t
agNameToAddresses
map
[
string
][]
string
A
ddressToTagNames
map
[
string
][]
string
T
agNameToAddresses
map
[
string
][]
string
}
func
getRule
(
rawRule
string
)
(
*
RouterRule
,
error
)
{
...
...
@@ -58,13 +58,13 @@ func getRule(rawRule string) (*RouterRule, error) {
// parseTags use for flattening tags data to @addressToTagNames and @tagNameToAddresses
func
(
t
*
RouterRule
)
parseTags
()
{
t
.
a
ddressToTagNames
=
make
(
map
[
string
][]
string
,
2
*
len
(
t
.
Tags
))
t
.
t
agNameToAddresses
=
make
(
map
[
string
][]
string
,
len
(
t
.
Tags
))
t
.
A
ddressToTagNames
=
make
(
map
[
string
][]
string
,
2
*
len
(
t
.
Tags
))
t
.
T
agNameToAddresses
=
make
(
map
[
string
][]
string
,
len
(
t
.
Tags
))
for
_
,
tag
:=
range
t
.
Tags
{
for
_
,
address
:=
range
tag
.
Addresses
{
t
.
a
ddressToTagNames
[
address
]
=
append
(
t
.
a
ddressToTagNames
[
address
],
tag
.
Name
)
t
.
A
ddressToTagNames
[
address
]
=
append
(
t
.
A
ddressToTagNames
[
address
],
tag
.
Name
)
}
t
.
t
agNameToAddresses
[
tag
.
Name
]
=
tag
.
Addresses
t
.
T
agNameToAddresses
[
tag
.
Name
]
=
tag
.
Addresses
}
}
...
...
@@ -85,15 +85,15 @@ func (t *RouterRule) getTagNames() []string {
}
func
(
t
*
RouterRule
)
hasTag
(
tag
string
)
bool
{
return
len
(
t
.
t
agNameToAddresses
[
tag
])
>
0
return
len
(
t
.
T
agNameToAddresses
[
tag
])
>
0
}
func
(
t
*
RouterRule
)
getAddressToTagNames
()
map
[
string
][]
string
{
return
t
.
a
ddressToTagNames
return
t
.
A
ddressToTagNames
}
func
(
t
*
RouterRule
)
getTagNameToAddresses
()
map
[
string
][]
string
{
return
t
.
t
agNameToAddresses
return
t
.
T
agNameToAddresses
}
func
(
t
*
RouterRule
)
getTags
()
[]
Tag
{
...
...
This diff is collapsed.
Click to expand it.
cluster/router/tag/tag_router.go
+
4
−
7
View file @
b04224bb
...
...
@@ -24,6 +24,7 @@ import (
import
(
gxnet
"github.com/dubbogo/gost/net"
"github.com/jinzhu/copier"
perrors
"github.com/pkg/errors"
)
...
...
@@ -63,11 +64,6 @@ func (c *tagRouter) isEnabled() bool {
return
c
.
enabled
}
func
(
c
*
tagRouter
)
tagRouterRuleCopy
()
RouterRule
{
routerRule
:=
*
c
.
tagRouterRule
return
routerRule
}
// Route gets a list of invoker
func
(
c
*
tagRouter
)
Route
(
invokers
[]
protocol
.
Invoker
,
url
*
common
.
URL
,
invocation
protocol
.
Invocation
)
[]
protocol
.
Invoker
{
var
(
...
...
@@ -85,7 +81,8 @@ func (c *tagRouter) Route(invokers []protocol.Invoker, url *common.URL, invocati
}
// since the rule can be changed by config center, we should copy one to use.
tagRouterRuleCopy
:=
c
.
tagRouterRuleCopy
()
tagRouterRuleCopy
:=
new
(
RouterRule
)
_
=
copier
.
Copy
(
tagRouterRuleCopy
,
c
.
tagRouterRule
)
tag
,
ok
:=
invocation
.
Attachments
()[
constant
.
Tagkey
]
if
!
ok
{
tag
=
url
.
GetParam
(
constant
.
Tagkey
,
""
)
...
...
@@ -93,7 +90,7 @@ func (c *tagRouter) Route(invokers []protocol.Invoker, url *common.URL, invocati
// if we are requesting for a Provider with a specific tag
if
len
(
tag
)
>
0
{
return
filterInvokersWithTag
(
invokers
,
url
,
invocation
,
tagRouterRuleCopy
,
tag
)
return
filterInvokersWithTag
(
invokers
,
url
,
invocation
,
*
tagRouterRuleCopy
,
tag
)
}
// return all addresses in dynamic tag group.
...
...
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