diff --git a/go.mod b/go.mod index caf01f8c0842b134611f3369c10cac7e800149fe..217206796f596c05fa624255b779c6c75b20df3d 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/apache/dubbo-go require ( - github.com/dubbogo/getty v1.1.2-0.20190703052458-5e72c69fddc7 + github.com/dubbogo/getty v1.2.0 github.com/dubbogo/gost v1.1.1 github.com/dubbogo/hessian2 v1.2.0 github.com/magiconair/properties v1.8.1 diff --git a/go.sum b/go.sum index 30d19769894d5eaa346083229374ced1a889af81..41c0365c25c1730abfe214c7660955372640f64d 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,11 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dubbogo/getty v1.1.2-0.20190703052458-5e72c69fddc7 h1:WDzbrHOfdO78mFp3RJgGRM0u2+DEwrVzo58InIdgcX8= -github.com/dubbogo/getty v1.1.2-0.20190703052458-5e72c69fddc7/go.mod h1:DfbsJXdXj6DliCAEgrRbwC7J5rz+2sOPGKKEvlF6OjE= +github.com/dubbogo/getty v1.2.0 h1:LmP/R/yCYp5/ubUTm5Xa7QwE3EnFFSjguJH8DJruJ70= +github.com/dubbogo/getty v1.2.0/go.mod h1:p9Pyk18a+5Aa0GZ546aCzlehEfvEof0jAF0+QQcEPYQ= +github.com/dubbogo/gost v1.0.1-0.20190706005735-65c3ecbba418/go.mod h1:R7wZm1DrmrKGr50mBZVcg6C9ekG8aL5hP+sgWcIDwQg= github.com/dubbogo/gost v1.1.1 h1:JCM7vx5edPIjDA5ovJTuzEEXuw2t7xLyrlgi2mi5jHI= github.com/dubbogo/gost v1.1.1/go.mod h1:R7wZm1DrmrKGr50mBZVcg6C9ekG8aL5hP+sgWcIDwQg= -github.com/dubbogo/gostd v0.0.0-20190625030817-87d8669125b7 h1:Wmt8yQMGkNx4GDUvU4CA+dwIsDwgi+DbP28NZV2ruqQ= -github.com/dubbogo/gostd v0.0.0-20190625030817-87d8669125b7/go.mod h1:lQ7PmKvs6xplvjzEEMKw8XmP20D9raD+wFfzxkKaBd4= github.com/dubbogo/hessian2 v1.2.0 h1:5wFYuMzzRhneUAPbVBVKubIknrEjUM/B76vievYD0Vw= github.com/dubbogo/hessian2 v1.2.0/go.mod h1:7EohF3mE7xmZcj43nP172sapRHOEifcV/jwyHhG4SaY= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= diff --git a/remoting/zookeeper/client.go b/remoting/zookeeper/client.go index ffd98391af0b031ecb3dd110f9fbb63887bd3704..0e3e502115dee3e1ee1f98f070774fe98b009ac7 100644 --- a/remoting/zookeeper/client.go +++ b/remoting/zookeeper/client.go @@ -299,29 +299,26 @@ func (z *ZookeeperClient) UnregisterEvent(zkPath string, event *chan struct{}) { if zkPath == "" { return } - z.Lock() - for { - a, ok := z.eventRegistry[zkPath] - if !ok { - break - } - for i, e := range a { - if e == event { - arr := a - a = append(arr[:i], arr[i+1:]...) - logger.Debugf("zkClient{%s} unregister event{path:%s, event:%p}", z.name, zkPath, event) - } - } - logger.Debugf("after zkClient{%s} unregister event{path:%s, event:%p}, array length %d", - z.name, zkPath, event, len(a)) - if len(a) == 0 { - delete(z.eventRegistry, zkPath) - } else { - z.eventRegistry[zkPath] = a + defer z.Unlock() + infoList, ok := z.eventRegistry[zkPath] + if !ok { + return + } + for i, e := range infoList { + if e == event { + arr := infoList + infoList = append(arr[:i], arr[i+1:]...) + logger.Debugf("zkClient{%s} unregister event{path:%s, event:%p}", z.name, zkPath, event) } } - z.Unlock() + logger.Debugf("after zkClient{%s} unregister event{path:%s, event:%p}, array length %d", + z.name, zkPath, event, len(infoList)) + if len(infoList) == 0 { + delete(z.eventRegistry, zkPath) + } else { + z.eventRegistry[zkPath] = infoList + } } func (z *ZookeeperClient) Done() <-chan struct{} { diff --git a/remoting/zookeeper/facade.go b/remoting/zookeeper/facade.go index 4fd800f87732288527d9387580fe70d0a9cae9d2..4eace5e9d540ac86ca01683963b19ae547c7c732 100644 --- a/remoting/zookeeper/facade.go +++ b/remoting/zookeeper/facade.go @@ -19,9 +19,9 @@ package zookeeper import ( "sync" - "time" ) import ( + "github.com/dubbogo/getty" perrors "github.com/pkg/errors" ) @@ -70,7 +70,7 @@ LOOP: case <-r.GetDone(): logger.Warnf("(ZkProviderRegistry)reconnectZkRegistry goroutine exit now...") break LOOP - case <-time.After(time.Duration(1e9 * failTimes * ConnDelay)): // 闃叉鐤媯閲嶈繛zk + case <-getty.GetTimeWheel().After(timeSecondDuration(failTimes * ConnDelay)): // 闃叉鐤媯閲嶈繛zk } err = ValidateZookeeperClient(r, WithZkName(zkName)) logger.Infof("ZkProviderRegistry.validateZookeeperClient(zkAddr{%s}) = error{%#v}", diff --git a/remoting/zookeeper/listener.go b/remoting/zookeeper/listener.go index 733870052df16b62b292cbe81a534605abcf7bb0..3df87ed4f603956a653cec692031dee94639de16 100644 --- a/remoting/zookeeper/listener.go +++ b/remoting/zookeeper/listener.go @@ -24,6 +24,7 @@ import ( ) import ( + "github.com/dubbogo/getty" perrors "github.com/pkg/errors" "github.com/samuel/go-zookeeper/zk" ) @@ -188,7 +189,7 @@ func (l *ZkEventListener) listenDirEvent(zkPath string, listener remoting.DataLi } l.client.RegisterEvent(zkPath, &event) select { - case <-time.After(timeSecondDuration(failTimes * ConnDelay)): + case <-getty.GetTimeWheel().After(timeSecondDuration(failTimes * ConnDelay)): l.client.UnregisterEvent(zkPath, &event) continue case <-l.client.Done():