Skip to content
Snippets Groups Projects
Commit 267281aa authored by 邹毅贤's avatar 邹毅贤
Browse files

fix review comments

parent df9cd804
No related branches found
No related tags found
No related merge requests found
......@@ -138,9 +138,9 @@ func (r *BaseRegistry) Register(conf common.URL) error {
)
role, _ := strconv.Atoi(r.URL.GetParam(constant.ROLE_KEY, ""))
// Check if the service has been registered
r.cltLock.RLock()
r.cltLock.Lock()
_, ok = r.services[conf.Key()]
r.cltLock.RUnlock()
r.cltLock.Unlock()
if ok {
return perrors.Errorf("Path{%s} has been registered", conf.Key())
}
......@@ -158,27 +158,28 @@ func (r *BaseRegistry) Register(conf common.URL) error {
return nil
}
// UnRegister
// UnRegister implement interface registry to unregister
func (r *BaseRegistry) UnRegister(conf common.URL) error {
var (
ok bool
err error
oldURL common.URL
)
func() {
r.cltLock.RLock()
defer r.cltLock.RUnlock()
oldURL, ok = r.services[conf.Key()]
}()
func() {
r.cltLock.RLock()
r.cltLock.Lock()
defer r.cltLock.Unlock()
oldURL, ok = r.services[conf.Key()]
if !ok {
err = perrors.Errorf("Path{%s} has not registered", conf.Key())
}
delete(r.services, conf.Key())
}()
if !ok {
return perrors.Errorf("Path{%s} has not registered", conf.Key())
if err != nil {
return err
}
err = r.unregister(conf)
......
......@@ -150,14 +150,14 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
for {
if !nr.IsAvailable() {
logger.Warnf("event listener game over.")
return
return perrors.New("nacosRegistry is not available.")
}
listener, err := nr.subscribe(url)
if err != nil {
if !nr.IsAvailable() {
logger.Warnf("event listener game over.")
return
return err
}
logger.Warnf("getListener() = err:%v", perrors.WithStack(err))
time.Sleep(time.Duration(RegistryConnDelay) * time.Second)
......@@ -169,7 +169,7 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
if err != nil {
logger.Warnf("Selector.watch() = error{%v}", perrors.WithStack(err))
listener.Close()
return
return err
}
logger.Infof("update begin, service event: %v", serviceEvent.String())
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment