-
Notifications
You must be signed in to change notification settings - Fork 933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix:#1143 Feature/reduce etcd registry conn; wait group modify #1297
Changes from all commits
8ec8fd5
1721de0
cbbbd8d
a3e1e13
7979c1b
9684690
dc9f978
dc66fe4
fd54619
64fbfbd
e5941ad
84c2602
cd567b0
a6adc3b
c702599
c79d3c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ func newZkRegistry(url *common.URL) (registry.Registry, error) { | |
return nil, err | ||
} | ||
|
||
r.WaitGroup().Add(1) //zk client start successful, then wg +1 | ||
r.WaitGroup().Add(1) | ||
go zookeeper.HandleClientRestart(r) | ||
|
||
r.listener = zookeeper.NewZkEventListener(r.client) | ||
|
@@ -108,7 +108,6 @@ func newMockZkRegistry(url *common.URL, opts ...gxzookeeper.Option) (*zk.TestClu | |
if err != nil { | ||
return nil, nil, err | ||
} | ||
r.WaitGroup().Add(1) // zk client start successful, then wg +1 | ||
go zookeeper.HandleClientRestart(r) | ||
r.InitListeners() | ||
return c, r, nil | ||
|
@@ -314,3 +313,8 @@ func (r *zkRegistry) getCloseListener(conf *common.URL) (*RegistryConfigurationL | |
|
||
return zkListener, nil | ||
} | ||
|
||
func (r *zkRegistry) handleClientRestart() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AsyncHandleClientRestart |
||
r.WaitGroup().Add(1) | ||
go zookeeper.HandleClientRestart(r) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,19 +18,16 @@ | |
package etcdv3 | ||
|
||
import ( | ||
getty "github.com/apache/dubbo-getty" | ||
"sync" | ||
"time" | ||
) | ||
|
||
import ( | ||
gxetcd "github.com/dubbogo/gost/database/kv/etcd/v3" | ||
perrors "github.com/pkg/errors" | ||
) | ||
|
||
import ( | ||
"dubbo.apache.org/dubbo-go/v3/common" | ||
"dubbo.apache.org/dubbo-go/v3/common/constant" | ||
"dubbo.apache.org/dubbo-go/v3/common/logger" | ||
) | ||
|
||
|
@@ -45,56 +42,18 @@ type clientFacade interface { | |
} | ||
|
||
// HandleClientRestart keeps the connection between client and server | ||
// This method should be used only once. You can use handleClientRestart() in package registry. | ||
func HandleClientRestart(r clientFacade) { | ||
var ( | ||
err error | ||
failTimes int | ||
) | ||
|
||
defer r.WaitGroup().Done() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. r.WaitGroup()的done,wait和add使用散落在各处,remoting作为基础组件,是否可能有同学直接调用 HandleClientRestart ,然后函数结束出现 negative 的问题? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 有可能,用once限制一下HandleClientRestart的调用次数是否可以呢;该方法在init包被引入的时候调用,只调用一次。 |
||
LOOP: | ||
for { | ||
select { | ||
case <-r.Client().GetCtx().Done(): | ||
r.RestartCallBack() | ||
// re-register all services | ||
time.Sleep(10 * time.Microsecond) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为什么这里要Sleep? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 代码实现参照zk对于连接过多的优化,做了类似的实现。 |
||
case <-r.Done(): | ||
logger.Warnf("(ETCDV3ProviderRegistry)reconnectETCDV3 goroutine exit now...") | ||
break LOOP | ||
// re-register all services | ||
case <-r.Client().Done(): | ||
r.ClientLock().Lock() | ||
clientName := gxetcd.RegistryETCDV3Client | ||
timeout, _ := time.ParseDuration(r.GetURL().GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT)) | ||
endpoints := r.Client().GetEndPoints() | ||
r.Client().Close() | ||
r.SetClient(nil) | ||
r.ClientLock().Unlock() | ||
|
||
// try to connect to etcd, | ||
failTimes = 0 | ||
for { | ||
after := getty.GetTimeWheel().After(timeSecondDuration(failTimes * gxetcd.ConnDelay)) | ||
select { | ||
case <-r.Done(): | ||
logger.Warnf("(ETCDV3ProviderRegistry)reconnectETCDRegistry goroutine exit now...") | ||
break LOOP | ||
case <-after: // avoid connect frequent | ||
} | ||
err = ValidateClient( | ||
r, | ||
gxetcd.WithName(clientName), | ||
gxetcd.WithEndpoints(endpoints...), | ||
gxetcd.WithTimeout(timeout), | ||
gxetcd.WithHeartbeat(1), | ||
) | ||
logger.Infof("ETCDV3ProviderRegistry.validateETCDV3Client(etcd Addr{%s}) = error{%#v}", | ||
endpoints, perrors.WithStack(err)) | ||
if err == nil && r.RestartCallBack() { | ||
break | ||
} | ||
failTimes++ | ||
if gxetcd.MaxFailTimes <= failTimes { | ||
failTimes = gxetcd.MaxFailTimes | ||
} | ||
} | ||
return | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AsyncHandleClientRestart