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

lock optimize : change to rwlock

parent db059d3d
No related branches found
No related tags found
No related merge requests found
......@@ -158,7 +158,6 @@ func (r *zkRegistry) DoRegister(root string, node string) error {
func (r *zkRegistry) DoUnregister(root string, node string) error {
r.cltLock.Lock()
defer r.cltLock.Unlock()
if !r.ZkClient().ZkConnValid() {
return perrors.Errorf("zk client is not valid.")
}
......
......@@ -278,7 +278,7 @@ LOOP:
break LOOP
case (int)(zk.EventNodeDataChanged), (int)(zk.EventNodeChildrenChanged):
logger.Infof("zkClient{%s} get zk node changed event{path:%s}", z.name, event.Path)
z.Lock()
z.RLock()
for p, a := range z.eventRegistry {
if strings.HasPrefix(p, event.Path) {
logger.Infof("send event{state:zk.EventNodeDataChange, Path:%s} notify event to path{%s} related listener",
......@@ -288,7 +288,7 @@ LOOP:
}
}
}
z.Unlock()
z.RUnlock()
case (int)(zk.StateConnecting), (int)(zk.StateConnected), (int)(zk.StateHasSession):
if state == (int)(zk.StateHasSession) {
continue
......@@ -371,11 +371,11 @@ func (z *ZookeeperClient) ZkConnValid() bool {
}
valid := true
z.Lock()
z.RLock()
if z.Conn == nil {
valid = false
}
z.Unlock()
z.RUnlock()
return valid
}
......
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