Zookeeper watcher参照表

Watcher 设置是开发中最常见的,需要搞清楚watcher的一些基本特征,对于exists、getdata、getchild对于节点的不同操 作会收到不同的 watcher信息。对父节点的变更以及孙节点的变更都不会触发watcher,而对watcher本身节点以及子节点的变更会触发 watcher,具体参照下表。

注: watcher state = 2 表示删除事件;watcher state = 3表示节点数据变更;watcher state =4表示子节点事件;watcher state = -1表示 session事件。 watcher type = -112表示session失效;watcher type = 1表示session建立中;watcher type = = 3表示 session建立成功。×表示否,√表示是。

操作 方法 触发watcher watcher state watcher type watcher path
Create当前节点 getdata × × × ×
getchildren 4 3
exists × × × ×
set当前节点 getdata 3 3
getchildren × × × ×
exists 3 3
delete当前节点 getdata 2 3
getchildren 2 3
exists 2 3
create子节点 getdata × × × ×
getchildren 4 3
exists × × × ×
set子节点 getdata × × × ×
getchildren × × × ×
exists × × × ×
delete子节点 getdata × × × ×
getchildren 4 2
exists × × × ×
恢复连接 getdata -1 1 ×
getchildren -1 1 ×
exists -1 1 ×
恢复连接session未超时 getdata -1 -112 ×
getchildren -1 -112 ×
exists -1 -112 ×
恢复连接session超时 getdata -1 3 ×
getchildren -1 3 ×
exists -1 3 ×

感兴趣的可以扫描关注微信公众号,会分享一些技术总结以及大厂的面试经验。

公众号:说说互联网的那些事

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章