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 ×

感興趣的可以掃描關注微信公衆號,會分享一些技術總結以及大廠的面試經驗。

公衆號:說說互聯網的那些事

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