zk 作为注册服务,异常端开,zk节点信息没有清理 (#1758)

pull/1762/head
kwame 3 years ago committed by GitHub
parent cd4aa7f412
commit 8bb55663d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      contrib/registry/zookeeper/register.go

@ -75,18 +75,18 @@ func (r *Registry) Register(ctx context.Context, service *registry.ServiceInstan
data []byte
err error
)
if err = r.ensureName(r.opts.rootPath, []byte("")); err != nil {
if err = r.ensureName(r.opts.rootPath, []byte(""), 0); err != nil {
return err
}
serviceNamePath := path.Join(r.opts.rootPath, service.Name)
if err = r.ensureName(serviceNamePath, []byte("")); err != nil {
if err = r.ensureName(serviceNamePath, []byte(""), 0); err != nil {
return err
}
if data, err = json.Marshal(service); err != nil {
return err
}
servicePath := path.Join(serviceNamePath, service.ID)
if err = r.ensureName(servicePath, data); err != nil {
if err = r.ensureName(servicePath, data, zk.FlagEphemeral); err != nil {
return err
}
return nil
@ -176,13 +176,13 @@ func (r *Registry) resolve(ss *serviceSet) {
}
// ensureName ensure node exists, if not exist, create and set data
func (r *Registry) ensureName(path string, data []byte) error {
func (r *Registry) ensureName(path string, data []byte, flags int32) error {
exists, _, err := r.conn.Exists(path)
if err != nil {
return err
}
if !exists {
_, err := r.conn.Create(path, data, 0, zk.WorldACL(zk.PermAll))
_, err := r.conn.Create(path, data, flags, zk.WorldACL(zk.PermAll))
if err != nil {
return err
}

Loading…
Cancel
Save