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 data []byte
err error 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 return err
} }
serviceNamePath := path.Join(r.opts.rootPath, service.Name) 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 return err
} }
if data, err = json.Marshal(service); err != nil { if data, err = json.Marshal(service); err != nil {
return err return err
} }
servicePath := path.Join(serviceNamePath, service.ID) 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 err
} }
return nil return nil
@ -176,13 +176,13 @@ func (r *Registry) resolve(ss *serviceSet) {
} }
// ensureName ensure node exists, if not exist, create and set data // 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) exists, _, err := r.conn.Exists(path)
if err != nil { if err != nil {
return err return err
} }
if !exists { 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 { if err != nil {
return err return err
} }

Loading…
Cancel
Save