Storm的所有的狀態信息都保存在Zookeeper里面,nimbus通過在zookeeper上面寫狀態信息來分配任務:
使得nimbus可以監控整個storm集群的狀態,從而可以重啟一些掛掉的task。 ZooKeeper使得整個storm集群十分的健壯-—任何一臺工作機器掛掉都沒有關系,只要重啟然后從zookeeper上面重新獲取狀態信息就可以了。那Storm在zookeeper里面存儲了哪些狀態呢?在James Xu的文章中有所涉及,但是該文章講述的已經過時了。本文主要介紹Storm在ZooKeeper中保存的數據目錄結構,源代碼主要是:backtype.storm.cluster。
關于storm操作zookeeper的詳細分析請參見:源碼閱讀之storm操作zookeeper-cluster.clj
Zookeeper的操作
1
2
3
4
5
6
7
8
9
10
11
12
|
(defprotocol ClusterState (set-ephemeral-node [ this path data]) (delete-node [ this path]) (create-sequential [ this path data]) (set-data [ this path data]) ;; if node does not exist, create persistent with this data (get-data [ this path watch?]) (get-children [ this path watch?]) (mkdirs [ this path]) (close [ this ]) (register [ this callback]) (unregister [ this id]) ) |
Storm使用Zookeeper的操作
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
(defprotocol StormClusterState (assignments [ this callback]) (assignment-info [ this storm-id callback]) (active-storms [ this ]) (storm-base [ this storm-id callback]) (get-worker-heartbeat [ this storm-id node port]) (executor-beats [ this storm-id executor->node+port]) (supervisors [ this callback]) (supervisor-info [ this supervisor-id]) ;; returns nil if doesn't exist (setup-heartbeats! [ this storm-id]) (teardown-heartbeats! [ this storm-id]) (teardown-topology-errors! [ this storm-id]) (heartbeat-storms [ this ]) (error-topologies [ this ]) (worker-heartbeat! [ this storm-id node port info]) (remove-worker-heartbeat! [ this storm-id node port]) (supervisor-heartbeat! [ this supervisor-id info]) (activate-storm! [ this storm-id storm-base]) (update-storm! [ this storm-id new -elems]) (remove-storm-base! [ this storm-id]) (set-assignment! [ this storm-id info]) (remove-storm! [ this storm-id]) (report-error [ this storm-id task-id error]) (errors [ this storm-id task-id]) (disconnect [ this ]) ) |
Storm中在Zookeeper中存儲的目錄
1
2
3
4
5
6
7
8
9
10
11
12
|
(def ASSIGNMENTS-ROOT "assignments" ) (def CODE-ROOT "code" ) (def STORMS-ROOT "storms" ) (def SUPERVISORS-ROOT "supervisors" ) (def WORKERBEATS-ROOT "workerbeats" ) (def ERRORS-ROOT "errors" ) (def ASSIGNMENTS-SUBTREE (str "/" ASSIGNMENTS-ROOT)) (def STORMS-SUBTREE (str "/" STORMS-ROOT)) (def SUPERVISORS-SUBTREE (str "/" SUPERVISORS-ROOT)) (def WORKERBEATS-SUBTREE (str "/" WORKERBEATS-ROOT)) (def ERRORS-SUBTREE (str "/" ERRORS-ROOT)) |
1./assignments -> 任務分配信息
2./storms -> 正在運行的topology的ID
3./supervisors -> 所有的Supervisors的心跳信息
4./workerbeats -> 所有的Worker的心跳
5./errors -> 產生的出錯信息
結構圖
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/-{storm-zk-root} -- storm在zookeeper上的根目錄(默認為/storm) | |-/assignments -- topology的任務分配信息 | | | |-/{topology-id} -- 這個目錄保存的是每個topology的assignments信息包括:對應的nimbus上 | -- 的代碼目錄,所有task的啟動時間,每個task與機器、端口的映射。操作為 | -- (assignments)來獲取所有assignments的值;以及(assignment-info storm-id) | -- 來得到給定的storm-id對應的AssignmentInfo信息 | -- 在AssignmentInfo中存儲的內容有: | -- :executor->node+port :executor->start-time-secs :node->host | -- 具體定義在common.clj中的 | -- (defrecord Assignment[master-code-dir node->host executor->node+port executor->start-time-secs]) | |-/storms -- 這個目錄保存所有正在運行的topology的id | | | | | |-/{topology-id} -- 這個文件保存這個topology的一些信息,包括topology的名字,topology開始運行 | -- 的時間以及這個topology的狀態。操作(active-storms),獲得當前路徑活躍的下 | -- topology數據。保存的內容參考類StormBase;(storm-base storm-id)得到給定的 | -- storm-id下的StormBase數據,具體定義在common.clj中的 | -- (defrecord StormBase [storm-name launch-time-secs status num-workers component->executors]) | |-/supervisors -- 這個目錄保存所有的supervisor的心跳信息 | | | | | |-/{supervisor-id} -- 這個文件保存supervisor的心跳信息包括:心跳時間,主機名,這個supervisor上 | -- worker的端口號,運行時間(具體看SupervisorInfo類)。操作(supervisors)得到 | -- 所有的supervisors節點;(supervisor-info supervisor-id)得到給定的 | -- supervisor-id對應的SupervisorInfo信息;具體定義在common.clj中的 | | -- (defrecord SupervisorInfo [time-secs hostname assignment-id used-ports meta scheduler-meta uptime-secs]) | |-/workerbeats -- 所有worker的心跳 | | | |-/{topology-id} -- 這個目錄保存這個topology的所有的worker的心跳信息 | | | |-/{supervisorId-port} -- worker的心跳信息,包括心跳的時間,worker運行時間以及一些統計信息 | | -- 操作(heartbeat-storms)得到所有有心跳數據的topology, | -- (get-worker-heartbeat storm-id node port)得到具體一個topology下 | -- 的某個worker(node:port)的心跳狀況, | -- (executor-beats storm-id executor->node+port)得到一個executor的心跳狀況 | |-/errors -- 所有產生的error信息 | |-/{topology-id} -- 這個目錄保存這個topology下面的錯誤信息。操作(error-topologies)得到出錯 | -- 的topology;(errors storm-id component-id)得到 | -- 給定的storm-id component-id下的出錯信息 |-/{component-id} |
總結
以上就是本文關于淺談Storm在zookeeper上的目錄結構的全部內容,如有不足之處,歡迎留言指出,希望對大家有所幫助。感謝朋友們對本站的支持!
原文鏈接:https://segmentfault.com/a/1190000000653595