about云开发-活到老 学到老

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 974|回复: 3

zookeeper 关于“Leader Election”为什么看不到 /election 目录

[复制链接]

3

主题

2

听众

0

收听

注册会员

Rank: 2

积分
144
发表于 2018-4-10 16:29:34 | 显示全部楼层 |阅读模式
zookeeper官方文档说选举时,会创建 /electio ,然后选序号最小的最为leader。
这段文档基本没看明白。

https://zookeeper.apache.org/doc/current/recipes.html(Leader Election在这个页面最下面)




Leader Election
A simple way of doing leader election with ZooKeeper is to use the SEQUENCE|EPHEMERAL flags when creating znodes that represent "proposals" of clients. The idea is to have a znode, say "/election", such that each znode creates a child znode "/election/n_" with both flags SEQUENCE|EPHEMERAL. With the sequence flag, ZooKeeper automatically appends a sequence number that is greater that any one previously appended to a child of "/election". The process that created the znode with the smallest appended sequence number is the leader.
That's not all, though. It is important to watch for failures of the leader, so that a new client arises as the new leader in the case the current leader fails. A trivial solution is to have all application processes watching upon the current smallest znode, and checking if they are the new leader when the smallest znode goes away (note that the smallest znode will go away if the leader fails because the node is ephemeral). But this causes a herd effect: upon of failure of the current leader, all other processes receive a notification, and execute getChildren on "/election" to obtain the current list of children of "/election". If the number of clients is large, it causes a spike on the number of operations that ZooKeeper servers have to process. To avoid the herd effect, it is sufficient to watch for the next znode down on the sequence of znodes. If a client receives a notification that the znode it is watching is gone, then it becomes the new leader in the case that there is no smaller znode. Note that this avoids the herd effect by not having all clients watching the same znode.
Here's the pseudo code:
Let ELECTION be a path of choice of the application. To volunteer to be a leader:
  • Create znode z with path "ELECTION/n_" with both SEQUENCE and EPHEMERAL flags;
  • Let C be the children of "ELECTION", and i be the sequence number of z;
  • Watch for changes on "ELECTION/n_j", where j is the largest sequence number such that j < i and n_j is a znode in C;

Upon receiving a notification of znode deletion:
  • Let C be the new set of children of ELECTION;
  • If z is the smallest node in C, then execute leader procedure;
  • Otherwise, watch for changes on "ELECTION/n_j", where j is the largest sequence number such that j < i and n_j is a znode in C;

Note that the znode having no preceding znode on the list of children does not imply that the creator of this znode is aware that it is the current leader. Applications may consider creating a separate znode to acknowledge that the leader has executed the leader procedure.


官方文档

官方文档

zookeeper目录

zookeeper目录


3

主题

2

听众

0

收听

注册会员

Rank: 2

积分
144
 楼主| 发表于 2018-4-12 19:10:09 | 显示全部楼层
我知道了。

这里说的选举,是说我们的程序如果用zk来做选举的方法。这段文字的第一句话说了。“A simple way of doing leader election with ZooKeeper ”。而不是说,zk自己在选举时,会用这个方法。

76

主题

35

听众

20

收听

高级会员

Rank: 4

积分
3163

最佳新人活跃会员热心会员

发表于 2018-4-10 21:05:35 | 显示全部楼层
这不是什么问题。
查看下子目录,里面还有的目录的。你看到的应该是第一层目录。
推荐参考
http://www.aboutyun.com/home.php ... do=blog&id=3537

点评

谢谢,不过您的回答未能解决我的疑惑。  发表于 2018-4-11 17:41
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /4 下一条

QQ|小黑屋|about云开发-学问论坛|社区-大数据云技术学习分享平台 ( 京ICP备12023829号

GMT+8, 2018-7-19 12:17 , Processed in 0.547855 second(s), 39 queries , Gzip On.

Powered by Discuz! X3.2 Licensed

快速回复 返回顶部 返回列表