Skip to content

Commit

Permalink
Merge pull request #720 from watermelo/Fix/tagRouterCopy
Browse files Browse the repository at this point in the history
Fix: fix tag router rule copy
  • Loading branch information
pantianying authored Aug 20, 2020
2 parents 5a135e6 + b04224b commit 8a7a104
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 46 deletions.
18 changes: 9 additions & 9 deletions cluster/router/tag/router_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (
type RouterRule struct {
router.BaseRouterRule `yaml:",inline"`
Tags []Tag
addressToTagNames map[string][]string
tagNameToAddresses map[string][]string
AddressToTagNames map[string][]string
TagNameToAddresses map[string][]string
}

func getRule(rawRule string) (*RouterRule, error) {
Expand All @@ -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.addressToTagNames = make(map[string][]string, 2*len(t.Tags))
t.tagNameToAddresses = make(map[string][]string, len(t.Tags))
t.AddressToTagNames = make(map[string][]string, 2*len(t.Tags))
t.TagNameToAddresses = make(map[string][]string, len(t.Tags))
for _, tag := range t.Tags {
for _, address := range tag.Addresses {
t.addressToTagNames[address] = append(t.addressToTagNames[address], tag.Name)
t.AddressToTagNames[address] = append(t.AddressToTagNames[address], tag.Name)
}
t.tagNameToAddresses[tag.Name] = tag.Addresses
t.TagNameToAddresses[tag.Name] = tag.Addresses
}
}

Expand All @@ -85,15 +85,15 @@ func (t *RouterRule) getTagNames() []string {
}

func (t *RouterRule) hasTag(tag string) bool {
return len(t.tagNameToAddresses[tag]) > 0
return len(t.TagNameToAddresses[tag]) > 0
}

func (t *RouterRule) getAddressToTagNames() map[string][]string {
return t.addressToTagNames
return t.AddressToTagNames
}

func (t *RouterRule) getTagNameToAddresses() map[string][]string {
return t.tagNameToAddresses
return t.TagNameToAddresses
}

func (t *RouterRule) getTags() []Tag {
Expand Down
11 changes: 4 additions & 7 deletions cluster/router/tag/tag_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

import (
gxnet "github.com/dubbogo/gost/net"
"github.com/jinzhu/copier"
perrors "github.com/pkg/errors"
)

Expand Down Expand Up @@ -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 (
Expand All @@ -85,15 +81,16 @@ 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, "")
}

// 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.
Expand Down
2 changes: 1 addition & 1 deletion common/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

import (
"github.com/dubbogo/getty"
"github.com/apache/dubbo-getty"
perrors "github.com/pkg/errors"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand Down
2 changes: 1 addition & 1 deletion config/ssl_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package config

import (
"github.com/dubbogo/getty"
"github.com/apache/dubbo-getty"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion config_center/nacos/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"time"
)
import (
"github.com/dubbogo/getty"
"github.com/apache/dubbo-getty"
perrors "github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ require (
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/Workiva/go-datastructures v1.0.50
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5
github.com/apache/dubbo-getty v1.3.10
github.com/apache/dubbo-go-hessian2 v1.6.2
github.com/coreos/bbolt v1.3.3 // indirect
github.com/coreos/etcd v3.3.13+incompatible
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect
github.com/creasty/defaults v1.3.0
github.com/docker/go-connections v0.4.0 // indirect
github.com/dubbogo/getty v1.3.9
github.com/dubbogo/go-zookeeper v1.0.1
github.com/dubbogo/gost v1.9.1
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
Expand Down
16 changes: 4 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
cloud.google.com/go v0.39.0 h1:UgQP9na6OTfp4dsAiz/eFpFA1C6tPdH5wiRdi19tuMw=
cloud.google.com/go v0.39.0/go.mod h1:rVLT6fkc8chs9sfPtFc1SBH6em7n+ZoXaG+87tDISts=
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
Expand Down Expand Up @@ -72,8 +70,8 @@ github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 h1:zOVTBdCKFd9JbCKz9/nt+FovbjPFmb7mUnp8nH9fQBA=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18/go.mod h1:v8ESoHo4SyHmuB4b1tJqDHxfTGEciD+yhvOU/5s1Rfk=
github.com/apache/dubbo-go-hessian2 v1.6.1 h1:mFKeCZzaCkk4mMOyP+LQ85GHbRyqKT7858KS21JQYA4=
github.com/apache/dubbo-go-hessian2 v1.6.1/go.mod h1:7rEw9guWABQa6Aqb8HeZcsYPHsOS7XT1qtJvkmI6c5w=
github.com/apache/dubbo-getty v1.3.10 h1:ys5mwjPdxG/KwkPjS6EI0RzQtU6p6FCPoKpaFEzpAL0=
github.com/apache/dubbo-getty v1.3.10/go.mod h1:x6rraK01BL5C7jUM2fPl5KMkAxLVIx54ZB8/XEOik9Y=
github.com/apache/dubbo-go-hessian2 v1.6.2 h1:i7F5GjVaUatLQz1x9vUmmSIFj49L8J6rVICdF6xw4qw=
github.com/apache/dubbo-go-hessian2 v1.6.2/go.mod h1:7rEw9guWABQa6Aqb8HeZcsYPHsOS7XT1qtJvkmI6c5w=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA=
Expand Down Expand Up @@ -148,8 +146,6 @@ github.com/docker/go-connections v0.3.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5Xh
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
github.com/dubbogo/getty v1.3.9 h1:Ip/4Yl7GyDzt3ddZhjXN1Vmxvo9y/hdtoJ4yFc7czLk=
github.com/dubbogo/getty v1.3.9/go.mod h1:JIN5lNZznGnBuoYjlEe/yjNmq7eSjKaawHdnBAdtiEo=
github.com/dubbogo/go-zookeeper v1.0.1 h1:irLzvOsDOTNsN8Sv9tvYYxVu6DCQfLtziZQtUHmZgz8=
github.com/dubbogo/go-zookeeper v1.0.1/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c=
github.com/dubbogo/gost v1.9.0 h1:UT+dWwvLyJiDotxJERO75jB3Yxgsdy10KztR5ycxRAk=
Expand Down Expand Up @@ -588,8 +584,7 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945 h1:N8Bg45zpk/UcpNGnfJt2y/3lRWASHNTUET8owPYCgYI=
github.com/smartystreets/goconvey v0.0.0-20190710185942-9d28bd7c0945/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/softlayer/softlayer-go v0.0.0-20180806151055-260589d94c7d h1:bVQRCxQvfjNUeRqaY/uT0tFuvuFY0ulgnczuR684Xic=
github.com/softlayer/softlayer-go v0.0.0-20180806151055-260589d94c7d/go.mod h1:Cw4GTlQccdRGSEf6KiMju767x0NEHE0YIVPJSaXjlsw=
Expand Down Expand Up @@ -645,8 +640,6 @@ github.com/vmware/govmomi v0.18.0/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59b
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/zouyx/agollo v0.0.0-20191114083447-dde9fc9f35b8 h1:k8TV7Gz7cpWpOw/dz71fx8cCZdWoPuckHJ/wkJl+meg=
github.com/zouyx/agollo v0.0.0-20191114083447-dde9fc9f35b8/go.mod h1:S1cAa98KMFv4Sa8SbJ6ZtvOmf0VlgH0QJ1gXI0lBfBY=
github.com/zouyx/agollo/v3 v3.4.4 h1:5G7QNw3fw74Ns8SfnHNhjndV2mlz5Fg8bB7q84ydFYI=
github.com/zouyx/agollo/v3 v3.4.4/go.mod h1:ag0XmE1r4iAgPd6PUnU9TJ0DMEjM1VKX1HUNqQJ2ywU=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
Expand Down Expand Up @@ -798,10 +791,10 @@ golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc h1:NCy3Ohtk6Iny5V/reW2Ktypo4zIpWBdRJ1uFMjBxdg8=
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.5.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0 h1:9sdfJOzWlkqPltHAuzT2Cp+yrBeY1KRVYgms8soxMwM=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
Expand All @@ -821,7 +814,6 @@ google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107/go.mod h1:VzzqZJRn
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190508193815-b515fa19cec8/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64 h1:iKtrH9Y8mcbADOP0YFaEMth7OfuHY9xHOwNj4znpM1A=
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
Expand Down
4 changes: 2 additions & 2 deletions protocol/dubbo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
)

import (
"github.com/apache/dubbo-getty"
hessian "github.com/apache/dubbo-go-hessian2"
"github.com/dubbogo/getty"
gxsync "github.com/dubbogo/gost/sync"
perrors "github.com/pkg/errors"
"go.uber.org/atomic"
Expand Down Expand Up @@ -193,7 +193,7 @@ type Response struct {
atta map[string]string
}

// nolint
// NewResponse creates a new Response.
func NewResponse(reply interface{}, atta map[string]string) *Response {
return &Response{
reply: reply,
Expand Down
2 changes: 1 addition & 1 deletion protocol/dubbo/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
)

import (
"github.com/apache/dubbo-getty"
"github.com/apache/dubbo-go-hessian2"
"github.com/dubbogo/getty"
"github.com/opentracing/opentracing-go"
perrors "github.com/pkg/errors"
)
Expand Down
2 changes: 1 addition & 1 deletion protocol/dubbo/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

import (
"github.com/dubbogo/getty"
"github.com/apache/dubbo-getty"
perrors "github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion protocol/dubbo/readwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
)

import (
"github.com/apache/dubbo-getty"
"github.com/apache/dubbo-go-hessian2"
"github.com/dubbogo/getty"
perrors "github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion protocol/dubbo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

import (
"github.com/dubbogo/getty"
"github.com/apache/dubbo-getty"
"github.com/dubbogo/gost/sync"
"gopkg.in/yaml.v2"
)
Expand Down
2 changes: 1 addition & 1 deletion registry/etcdv3/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
)

import (
"github.com/apache/dubbo-getty"
"github.com/coreos/etcd/embed"
"github.com/dubbogo/getty"
"github.com/stretchr/testify/suite"
)

Expand Down
2 changes: 1 addition & 1 deletion registry/kubernetes/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

import (
"github.com/dubbogo/getty"
"github.com/apache/dubbo-getty"
"github.com/dubbogo/gost/net"
perrors "github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
Expand Down
4 changes: 2 additions & 2 deletions registry/nacos/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (nl *nacosListener) Callback(services []model.SubscribeService, err error)
instance := generateInstance(services[i])
newInstanceMap[host] = instance
if old, ok := nl.instanceMap[host]; !ok {
// instance is not exist in cache, add it to cache
// instance does not exist in cache, add it to cache
addInstances = append(addInstances, instance)
} else {
// instance is not different from cache, update it to cache
Expand All @@ -144,7 +144,7 @@ func (nl *nacosListener) Callback(services []model.SubscribeService, err error)

for host, inst := range nl.instanceMap {
if _, ok := newInstanceMap[host]; !ok {
// cache instance is not exist in new instance list, remove it from cache
// cache instance does not exist in new instance list, remove it from cache
delInstances = append(delInstances, inst)
}
}
Expand Down
2 changes: 1 addition & 1 deletion remoting/etcdv3/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

import (
"github.com/dubbogo/getty"
"github.com/apache/dubbo-getty"
perrors "github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion remoting/zookeeper/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sync"
)
import (
"github.com/dubbogo/getty"
"github.com/apache/dubbo-getty"
perrors "github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion remoting/zookeeper/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

import (
"github.com/dubbogo/getty"
"github.com/apache/dubbo-getty"
"github.com/dubbogo/go-zookeeper/zk"
perrors "github.com/pkg/errors"
)
Expand Down
2 changes: 1 addition & 1 deletion test/integrate/dubbo/go-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func main() {
select {
case <-stopC:
// wait getty send resp to consumer
time.Sleep(3*time.Second)
time.Sleep(3 * time.Second)
return
case <-time.After(time.Minute):
panic("provider already running 1 min, but can't be call by consumer")
Expand Down

0 comments on commit 8a7a104

Please sign in to comment.