From 1e25fefd5176ca6e6b983ccd23cab7627e66b229 Mon Sep 17 00:00:00 2001 From: PangXing Date: Mon, 20 Feb 2023 17:12:22 +0800 Subject: [PATCH] =?UTF-8?q?seata=E9=87=8D=E6=9E=84=E9=9C=80=E5=8D=87?= =?UTF-8?q?=E7=BA=A7go.uuid=E4=B8=8Ego-zookeeper=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 6 ++-- go.sum | 12 ++++---- registry/dubbo/common/url.go | 6 ++-- registry/dubbo/remoting/zookeeper/client.go | 31 ++++++++++----------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index 2290165..5509030 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( github.com/dubbogo/getty v1.3.4 - github.com/dubbogo/go-zookeeper v1.0.3 + github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5 github.com/dubbogo/gost v1.11.16 github.com/go-playground/validator/v10 v10.2.0 github.com/golang/protobuf v1.5.0 @@ -12,7 +12,7 @@ require ( github.com/jinzhu/copier v0.3.2 github.com/magiconair/properties v1.8.1 github.com/pkg/errors v0.9.1 - github.com/satori/go.uuid v1.2.0 + github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b github.com/stretchr/testify v1.7.0 github.com/ugorji/go/codec v1.1.7 github.com/valyala/fasthttp v1.40.0 @@ -48,5 +48,5 @@ require ( go.uber.org/multierr v1.5.0 // indirect google.golang.org/protobuf v1.26.0-rc.1 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect - gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 3fcd78e..b78c332 100644 --- a/go.sum +++ b/go.sum @@ -82,8 +82,9 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dubbogo/getty v1.3.4 h1:5TvH213pnSIKYzY7IK8TT/r6yr5uPTB/U6YNLT+GsU0= github.com/dubbogo/getty v1.3.4/go.mod h1:36f+gH/ekaqcDWKbxNBQk9b9HXcGtaI6YHxp4YTntX8= -github.com/dubbogo/go-zookeeper v1.0.3 h1:UkuY+rBsxdT7Bs63QAzp9z7XqQ53W1j8E5rwl83me8g= github.com/dubbogo/go-zookeeper v1.0.3/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c= +github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5 h1:XoR8SSVziXe698dt4uZYDfsmHpKLemqAgFyndQsq5Kw= +github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c= github.com/dubbogo/gost v1.5.2/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8= github.com/dubbogo/gost v1.11.16 h1:fvOw8aKQ0BuUYuD+MaXAYFvT7tg2l7WAS5SL5gZJpFs= github.com/dubbogo/gost v1.11.16/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI= @@ -383,8 +384,8 @@ github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6po github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM= +github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/shirou/gopsutil v3.20.11+incompatible h1:LJr4ZQK4mPpIV5gOa4jCOKOGb4ty4DZO54I4FGqIpto= github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= @@ -717,8 +718,9 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -726,8 +728,6 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -mosn.io/api v1.2.3 h1:H6NkiqgXnq6GsbAg2rmd9i3Fz5Husw2Vme3LBRHUovU= -mosn.io/api v1.2.3/go.mod h1:mJX2oRJkrXjLN6hY1Wwrlxj0F+RqEPOMhbf2WhZO+VY= mosn.io/api v1.3.0 h1:QhsrbkvYnpvvrC151S0N09TdU2jDODygLVK3Y58ubgg= mosn.io/api v1.3.0/go.mod h1:mJX2oRJkrXjLN6hY1Wwrlxj0F+RqEPOMhbf2WhZO+VY= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/registry/dubbo/common/url.go b/registry/dubbo/common/url.go index 9f84ccf..cee6859 100644 --- a/registry/dubbo/common/url.go +++ b/registry/dubbo/common/url.go @@ -30,9 +30,9 @@ import ( gxset "github.com/dubbogo/gost/container/set" "github.com/jinzhu/copier" - "mosn.io/pkg/registry/dubbo/common/constant" perrors "github.com/pkg/errors" uuid "github.com/satori/go.uuid" + "mosn.io/pkg/registry/dubbo/common/constant" ) ///////////////////////////////// @@ -170,7 +170,9 @@ func WithToken(token string) option { if len(token) > 0 { value := token if strings.ToLower(token) == "true" || strings.ToLower(token) == "default" { - value = uuid.NewV4().String() + if v, err := uuid.NewV4(); err == nil { + value = v.String() + } } url.SetParam(constant.TOKEN_KEY, value) } diff --git a/registry/dubbo/remoting/zookeeper/client.go b/registry/dubbo/remoting/zookeeper/client.go index a838ea2..5b416e8 100644 --- a/registry/dubbo/remoting/zookeeper/client.go +++ b/registry/dubbo/remoting/zookeeper/client.go @@ -25,9 +25,9 @@ import ( "github.com/dubbogo/go-zookeeper/zk" + perrors "github.com/pkg/errors" "mosn.io/pkg/registry/dubbo/common/constant" "mosn.io/pkg/registry/dubbo/common/logger" - perrors "github.com/pkg/errors" ) const ( @@ -78,10 +78,6 @@ func StateToString(state zk.State) string { return "zookeeper has session" case zk.StateUnknown: return "zookeeper unknown state" - case zk.State(zk.EventNodeDeleted): - return "zookeeper node deleted" - case zk.State(zk.EventNodeDataChanged): - return "zookeeper node data changed" default: return state.String() } @@ -264,6 +260,20 @@ func (z *ZookeeperClient) HandleZkEvent(session <-chan zk.Event) { conn.Close() } return + case (int)(zk.StateConnecting), (int)(zk.StateConnected), (int)(zk.StateHasSession): + if state == (int)(zk.StateHasSession) { + continue + } + z.eventRegistryLock.RLock() + if a, ok := z.eventRegistry[event.Path]; ok && 0 < len(a) { + for _, e := range a { + *e <- struct{}{} + } + } + z.eventRegistryLock.RUnlock() + } + + switch (int)(event.Type) { case (int)(zk.EventNodeDataChanged), (int)(zk.EventNodeChildrenChanged): logger.Infof("zkClient{%s} get zk node changed event{path:%s}", z.name, event.Path) z.eventRegistryLock.RLock() @@ -277,17 +287,6 @@ func (z *ZookeeperClient) HandleZkEvent(session <-chan zk.Event) { } } z.eventRegistryLock.RUnlock() - case (int)(zk.StateConnecting), (int)(zk.StateConnected), (int)(zk.StateHasSession): - if state == (int)(zk.StateHasSession) { - continue - } - z.eventRegistryLock.RLock() - if a, ok := z.eventRegistry[event.Path]; ok && 0 < len(a) { - for _, e := range a { - *e <- struct{}{} - } - } - z.eventRegistryLock.RUnlock() } state = (int)(event.State) }