Skip to content
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

Rft : Optimize lock for zookeeper registry #578

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions registry/zookeeper/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,15 @@ 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() {
client := r.client
zouyx marked this conversation as resolved.
Show resolved Hide resolved
if client == nil {
return perrors.New("zk Client is null, can not process registerTempZookeeperNode ")
}

if !client.ZkConnValid() {
return perrors.Errorf("zk client is not valid.")
}
return r.ZkClient().Delete(path.Join(root, node))
return client.Delete(path.Join(root, node))
}

func (r *zkRegistry) DoSubscribe(conf *common.URL) (registry.Listener, error) {
Expand Down Expand Up @@ -252,9 +255,7 @@ func (r *zkRegistry) getListener(conf *common.URL) (*RegistryConfigurationListen

zkListener = NewRegistryConfigurationListener(r.client, r, conf)
if r.listener == nil {
r.cltLock.Lock()
zouyx marked this conversation as resolved.
Show resolved Hide resolved
client := r.client
r.cltLock.Unlock()
if client == nil {
return nil, perrors.New("zk connection broken")
}
Expand Down
6 changes: 0 additions & 6 deletions remoting/zookeeper/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,7 @@ func (z *ZookeeperClient) CreateWithValue(basePath string, value []byte) error {
for _, str := range strings.Split(basePath, "/")[1:] {
tmpPath = path.Join(tmpPath, "/", str)
err = errNilZkClientConn
z.Lock()
conn := z.Conn
zouyx marked this conversation as resolved.
Show resolved Hide resolved
z.Unlock()
if conn != nil {
_, err = conn.Create(tmpPath, value, 0, zk.WorldACL(zk.PermAll))
}
Expand All @@ -446,9 +444,7 @@ func (z *ZookeeperClient) Delete(basePath string) error {
)

err = errNilZkClientConn
z.Lock()
conn := z.Conn
zouyx marked this conversation as resolved.
Show resolved Hide resolved
z.Unlock()
if conn != nil {
err = conn.Delete(basePath, -1)
}
Expand All @@ -468,9 +464,7 @@ func (z *ZookeeperClient) RegisterTemp(basePath string, node string) (string, er
err = errNilZkClientConn
data = []byte("")
zkPath = path.Join(basePath) + "/" + node
z.Lock()
conn := z.Conn
zouyx marked this conversation as resolved.
Show resolved Hide resolved
z.Unlock()
if conn != nil {
tmpPath, err = conn.Create(zkPath, data, zk.FlagEphemeral, zk.WorldACL(zk.PermAll))
}
Expand Down