storm操作zookeeper的主要函数都定义在命名空间backtype.storm.cluster中(即cluster.clj文件中)。 backtype.storm.cluster定义了两个重要protocol:ClusterState和StormClusterState。clojure中的protocol可以看成java中的接口,封装了一组方法。ClusterState协议中封装了一组与zookeeper进行交互的基础函数,如获取子节点函数,获取子节点数据函数等,ClusterState协议定义如下:

关于storm操作zookeeper的详细分析请参见博客:storm操作zookeeper源码分析-cluster.clj

Zookeeper的操作
(defprotocol ClusterState
 (set-ephemeral-node [this path data])
 (delete-node [this path])
 (create-sequential [this path data])
 ;; if node does not exist, create persistent with this data
 (set-data [this path data])
 (get-data [this path watch?])
 (get-version [this path watch?])
 (get-data-with-version [this path watch?])
 (get-children [this path watch?])
 (mkdirs [this path])
 (close [this])
 (register [this callback])
 (unregister [this id]))
Storm使用Zookeeper的操作
(defprotocol StormClusterState
 (assignments [this callback])
 (assignment-info [this storm-id callback])
 (assignment-info-with-version [this storm-id callback])
 (assignment-version [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 node port error])
 (errors [this storm-id task-id])
 (disconnect [this]))
Storm中在Zookeeper中存储的目录
(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))

从上面来看,在Zookeeper中主要是有如下的五个子目录:

  1. /assignments -> 任务分配信息
  2. /storms -> 正在运行的topology的ID
  3. /supervisors -> 所有的Supervisors的心跳信息
  4. /workerbeats -> 所有的Worker的心跳
  5. /errors -> 产生的出错信息
结构图
/-{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上的目录结构的更多相关文章

  1. Twitter Storm源代码分析之ZooKeeper中的目录结构

    徐明明博客:Twitter Storm源代码分析之ZooKeeper中的目录结构 我们知道Twitter Storm的所有的状态信息都是保存在Zookeeper里面,nimbus通过在zookeepe ...

  2. Storm 在ZK 上的目录图

    这是Zk 的可视化工具 看到的Storm 目录结构 ,这时候没有提交任何的任务给这个集群, 其实这时候我只是启动了 nimbus 还没有启动Supervisors  ,所有你 看懂的Superviso ...

  3. mac上生成目录结构

    brew又叫Homebrew,是Mac OSX上的软件包管理工具,能在Mac中方便的安装软件或者卸载软件. 一.安装brew ruby -e "$(curl -fsSL https://ra ...

  4. windows上jmeter目录结构功能

    1.bin :存储了jmeter的可执行程序,如启动 2.lib:存储了jmeter的整合的功能(如.jar文件程序) 3.启动jmeter:双击bin\apachejmeter.jar jmeter ...

  5. 在浏览器中浏览git上项目目录结构

    效果如下,参考:https://gitee.com/oschina/GitCodeTree

  6. Twitter Storm源代码分析之Nimbus/Supervisor本地目录结构

    storm集群里面工作机器分为两种一种是nimbus, 一种是supervisor, 他们通过zookeeper来进行交互,nimbus通过zookeeper来发布一些指令,supervisor去读z ...

  7. 使用递归方法实现,向FTP服务器上传整个目录结构、从FTP服务器下载整个目录到本地的功能

    我最近由于在做一个关于FTP文件上传和下载的功能时候,发现Apache FTP jar包没有提供对整个目录结构的上传和下载功能,只能非目录类型的文件进行上传和下载操作,后来我查阅很多网上的实现方法,再 ...

  8. Eclipse中一个Maven工程的目录结构

    在之前的javaSE开发中,没有很关注Eclipse工程目录下的环境,总是看见一个src就点进去新建一个包再写一个class.以后的日子中也没有机会注意到一个工程到底是怎么组织的这种问题,跟不要说自己 ...

  9. Maven学习-目录结构

    在前一篇文章中,我们介绍了什么是Maven,以及如何用Maven来构建我们的项目.不了解Maven的童鞋,可以看这里Maven学习-入门.在这篇文章中,我们将学习Maven的项目的目录结构相关的内容. ...

随机推荐

  1. POJ 3070 矩阵mob

    . 矩阵高速幂想法与快速幂相同 #include<iostream> #include<cstdio> #include<cstring> #define MOD ...

  2. Linux查看端口占用进程

    Linux查看端口占用进程 netstat -anlp|grep 8081 tcp /java 此处3195为进程ID

  3. 2015 ETSI NFV用例指南

    译者简介:忍忍鱼,曾经从SDNLAB获取了很多知识,现在努力为SDNLAB贡献自己的力量.爱学习,求进步!SDNLAB,么么哒! ETSI NFV ISG已经确定了9个潜在的NFV用例.本章节简单介绍 ...

  4. linux学习-环境变量与文件查找

  5. 记录quick cocos2d-x3.2升级至cocos2d-x3.8

    目前为止,quickcocos2d-x没有3.8版本,想用3.8又想用quick,所以只能自己升级了,自己先记录下,防止忘记. cocos2d-x3.8里面有quick framework,而simu ...

  6. Angular Js 控制器

    在Angularjs中用ng-controller指令定义了应用程序中的控制器:例如: <div ng-app="myApp" ng-controller="myC ...

  7. java:stack栈: Stack 类表示后进先出(LIFO)的对象堆栈

    //Stack 类表示后进先出(LIFO)的对象堆栈 //它提供了通常的 push 和 pop 操作,以及取栈顶点的 peek 方法.测试堆栈是否为空的 empty 方法.在堆栈中查找项并确定到栈顶距 ...

  8. cin.get(),cin.getline(),getline(),gets(),getchar()

    1.cin.get() (1).cin.get()-------提取单个字符,可以提取回车.空格 a=cin.get(); (2) 同(1)---------------提取单个字符,可以提取回车.空 ...

  9. while( c= getchar(c) &&c!='\n')为什么错误

    运算顺序有关,详见 运算符优先级 代码1: #include<iostream> using namespace std; int main() { char c; int m=0; wh ...

  10. javaScript-基础篇(一)

    1.如何插入JS 使用<script>标签在HTML网页中插入JavaScript代码.注意, <script>标签要成对出现,并把JavaScript代码写在<scri ...