Twitter Storm中Topology的状态

状态转换如下,Topology 的持久化状态包括: active, inactive, killed, rebalancing 四个状态。

代码上看到每种状态都可以转换成一些持久化 ( 写入到 zk 中的状态 ) 或者中间状态。

  1. (defn state-transitions [nimbus storm-id status]
  2. {:active {:monitor (reassign-transition nimbus storm-id)
  3. :inactivate :inactive
  4. :activate nil
  5. :rebalance (rebalance-transition nimbus storm-id status)
  6. :kill (kill-transition nimbus storm-id)
  7. }
  8. :inactive {:monitor (reassign-transition nimbus storm-id)
  9. :activate :active
  10. :inactivate nil
  11. :rebalance (rebalance-transition nimbus storm-id status)
  12. :kill (kill-transition nimbus storm-id)
  13. }
  14. :killed {:startup (fn [] (delay-event nimbus
  15. storm-id
  16. (:kill-time-secs status)
  17. :remove))
  18. :kill (kill-transition nimbus storm-id)
  19. :remove (fn []
  20. (log-message "Killing topology: " storm-id)
  21. (.remove-storm! (:storm-cluster-state nimbus)
  22. storm-id)
  23. nil)
  24. }
  25. :rebalancing {:startup (fn [] (delay-event nimbus
  26. storm-id
  27. (:delay-secs status)
  28. :do-rebalance))
  29. :kill (kill-transition nimbus storm-id)
  30. :do-rebalance (fn []
  31. (do-rebalance nimbus storm-id status)
  32. (:old-status status))
  33. }})

1. active

active 状态的时候可以转换成 monitor, inactivate, activate, rebalance, kill 。

(1) monitor: 转换成 monitor 实际上是执行了 reassign-transition 操作:

  1. (defn reassign-transition [nimbus storm-id]
  2. (fn []
  3. (reassign-topology nimbus storm-id)
  4. nil
  5. ))

可以看出,实际上是为这个 topology 重新分配任务,返回值为 nil , 说明在 zk 中不会更改 topology 的持久化状态。

(2)inactivate: 返回值是 inactive, 状态转换的时候会将 zk 中 topology 的状态转换成 inactive 。

(3)activate: nil 说明什么操作都不做

(4)rebalance: 实际上是调用了 rebalance-transition 函数,从代码可以看出,会将状态改成 rebalancing, 然后再转换成 do-rebalance 。 do-rebalance 其实也是重新分配任务,具体看4 。

  1. (defn rebalance-transition [nimbus storm-id status]
  2. (fn [time num-workers executor-overrides]
  3. (let [delay (if time
  4. time
  5. (get (read-storm-conf (:conf nimbus) storm-id)
  6. TOPOLOGY-MESSAGE-TIMEOUT-SECS))]
  7. (delay-event nimbus
  8. storm-id
  9. delay
  10. :do-rebalance)
  11. {:type :rebalancing
  12. :delay-secs delay
  13. :old-status status
  14. :num-workers num-workers
  15. :executor-overrides executor-overrides
  16. })))

(5)kill: 实际上执行的是 kill-transition 方法,将 topology 的状态先改为 killed, 然后经过 kill-time 的时间,将topology remove, 详见3

  1. (defn kill-transition [nimbus storm-id]
  2. (fn [kill-time]
  3. (let [delay (if kill-time
  4. kill-time
  5. (get (read-storm-conf (:conf nimbus) storm-id)
  6. TOPOLOGY-MESSAGE-TIMEOUT-SECS))]
  7. (delay-event nimbus
  8. storm-id
  9. delay
  10. :remove)
  11. {:type :killed
  12. :kill-time-secs delay})
  13. ))

2. inactvie

(1) monitor: 与1中相同

(2) activate: 返回值是 active, 状态转换的时候会将 zk 中 topology 的状态转换成 active 。

(3) inactivate: nil 说明什么操作都不做

(4) rebalance: 与1中相同

3. killed

(1) startup:将状态转换成remove

(2) kill:  与1中相同

(3) remove:   实际上是调用了 remove-storm!函数, 清楚topology在zk上的相关目录。

  1. (remove-storm! [this storm-id]
  2. (delete-node cluster-state (storm-task-root storm-id))
  3. (delete-node cluster-state (assignment-path storm-id))
  4. (remove-storm-base! this storm-id))

4. rebalancing

(1) startup:将状态转换成do-rebalance

(2) kill:  与1中相同

(3) do-rebalance:  实际上是重新将任务分配,与初始分配任务不同,它假设所有的任务都是活跃的,所有的端口都不要判断是否需要保留,也就是说所有的任务重新分配,无论某些端口上的任务分配已经满足均衡要求。

Twitter Storm中Topology的状态的更多相关文章

  1. 关于Storm 中Topology的并发度的理解

    来自:https://storm.apache.org/documentation/Understanding-the-parallelism-of-a-Storm-topology.html htt ...

  2. Twitter Storm中Bolt消息传递路径之源码解读

    本文初次发表于storm-cn的google groups中,现以blog的方式再次发表,表明本人徽沪一郎确实读过这些代码,:). Bolt作为task被executor执行,而executor是一个 ...

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

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

  4. 在archlinux上搭建twitter storm cluster

    本文详细描述如何在archlinux上搭建twitter storm cluster,转载请注明出处,谢谢. 有关archlinux基本系统安装,请参照archlinux简明安装指南一文,下面以上述为 ...

  5. twitter storm源码走读之1 -- nimbus启动场景分析

    欢迎转载,转载时请注明作者徽沪一郎及出处,谢谢. 本文详细介绍了twitter storm中的nimbus节点的启动场景,分析nimbus是如何一步步实现定义于storm.thrift中的servic ...

  6. 【转】Twitter Storm: 在生产集群上运行topology

    Twitter Storm: 在生产集群上运行topology 发表于 2011 年 10 月 07 日 由 xumingming 作者: xumingming | 可以转载, 但必须以超链接形式标明 ...

  7. Twitter Storm如何保证消息不丢失

    storm保证从spout发出的每个tuple都会被完全处理.这篇文章介绍storm是怎么做到这个保证的,以及我们使用者怎么做才能充分利用storm的可靠性特点. 一个tuple被”完全处理”是什么意 ...

  8. Twitter Storm:单机环境的安装与配置

    Twitter Storm:单机环境的安装与配置 好久没写博客了,这一段时间一直被导师push着做毕业设计.由于目前的方向偏向于图像识别检索,毕设打算做一个基于分布式计算平台的图像检索系统,查阅相关资 ...

  9. Storm入门(五)Twitter Storm如何保证消息不丢失

    转自:http://xumingming.sinaapp.com/127/twitter-storm如何保证消息不丢失/ storm保证从spout发出的每个tuple都会被完全处理.这篇文章介绍st ...

随机推荐

  1. docker上安装ActiveMQ

    1.查看是否已经存在镜像 docker images 2.搜索镜像 docker search activemq 3.拉取镜像 docker pull webcenter/activemq 4.构建容 ...

  2. 机器学习-一对多(多分类)代码实现(matlab)

    %% Machine Learning Online Class - Exercise 3 | Part 1: One-vs-all % Instructions % ------------ % % ...

  3. 2019-8-31-dotnet-通过-WMI-获取系统启动的服务

    title author date CreateTime categories dotnet 通过 WMI 获取系统启动的服务 lindexi 2019-08-31 16:55:59 +0800 20 ...

  4. MapReduce各个执行阶段

  5. odoo 下 get_object_reference 函数

    get_object_reference是 ir.model.data 模块中下的一个函数 该函数通过调用ir.model.data 模块中另外一个函数 xmlid_lookup 返回结果 def g ...

  6. linux系统添加定时任务

    http://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/crontab.html

  7. arguments的介绍(一)

    arguments 是一个类数组对象.代表传给一个function的参数列表. 1.1 arguments length arguments 是个类数组对象,其包含一个 length 属性,可以用 a ...

  8. System.Web.Mvc.HttpUnauthorizedResult.cs

    ylbtech-System.Web.Mvc.HttpUnauthorizedResult.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neut ...

  9. Cesium官方教程13--Cesium和Webpack

    原文地址:https://cesiumjs.org/tutorials/cesium-and-webpack/ Cesium 和 Webpack Webpack是非常强大非常流行的JavaScript ...

  10. PAT甲级——A1075 PAT Judge

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...