Zookeeper 如何管理其他集群中的节点角色? [英] How does Zookeeper manage node roles in other clusters?

查看:29
本文介绍了Zookeeper 如何管理其他集群中的节点角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的理解是Zookeeper经常用来解决分布式系统中跟踪哪个节点扮演特定角色"的问题(例如DB中的主节点或MapReduce中的主节点)集群等).

My understanding is that Zookeeper is often used to solve the problem of "keeping track of which node plays a particular role" in a distributed system (e.g. master node in a DB or in a MapReduce cluster, etc).

为简单起见,假设我们有一个包含一个主节点和多个副本的数据库,并且数据库中的当前主节点出现故障.在这种情况下,原则上,可以使副本节点之一成为新的主节点.此时我的理解是:

For simplicity, say we have a DB with one master and multiple replicas and the current master node in the DB goes down. In this scenario, one would, in principle, make one of the replica nodes a new master node. At this point my understanding is:

应用服务器可能不知道我们有一个新的主节点,所以他们知道将写入发送到哪里,除非我们在应用服务器上有一些自定义逻辑来检测/纠正这个问题.

The application servers may not know that we have a new master node, so they would not know where to send writes unless we have some custom logic on the app server itself to detect / correct this problem.

Zookeeper 会以某种方式检测此故障,并更新相应主密钥的值.此外,应用服务器可以(可选?)在 Zookeeper 中注册钩子,因此 Zookeeper 可以通知他们这个失败,以便应用服务器可以更新(例如在内存中),哪个 DB 节点是新的主节点.

Zookeeper would somehow detect this failure, and update the value for the corresponding master key. Moreover, application servers can (optionally?) register hooks in Zookeeper, so Zookeeper can notify them of this failure, so that the app servers can update (e.g. in memory), which DB node is the new master.

我的问题是:

  1. Zookeper 如何知道要成为主节点的节点?Zookeper 是否应对此选择负责?
  2. 这些信息如何传播到需要与 Zookeeper 交互的节点?例如.如果其中一个 Zookeeper 节点出现故障,应用服务器如何知道在这种情况下要命中哪个 Zookeeper 节点?Zookeeper 的管理方式是否与竞争解决方案不同,例如etcd?
  1. How does Zookeper know what node to make master? Is Zookeper responsible for this choice?
  2. How is this information propagated to nodes that need to interact with Zookeeper? E.g. If one of the Zookeeper nodes go down, how would the application servers know which Zookeeper node to hit in this scenario? Does Zookeeper manage this differently from competing solutions like e.g. etcd?

推荐答案

1. 和 2. 的答案称为leader选举过程,其工作原理如下:

The answer to both 1. and 2. is called leader election process and briefly works in the following way:

当一个进程在 ZK 管理的集群中启动时,集群进入 election 状态.如果存在领导者,则存在已建立的层次结构,并且仅验证现有领导者.如果没有leader(比如master宕机了),ZK强制znodes使用序列标志来寻找新的leader.每个节点与其对等方对话并发送包含节点标识符 (sid) 和它最近执行的事务 (zxid) 的消息.这些消息称为votes.当一个节点收到投票时,它可以忽略它或根据 zxid 保留它.如果 zxid 较新,则保留投票,如果比它所拥有的旧,则将其丢弃.如果 zxids 出现平局,则 sid 最高的投票获胜!所以会有一段时间所有节点都将拥有相同的投票,这将通过 sid 定义新的领导者.所以这就是 ZK 选举新领导节点的方式!

When a process starts in a cluster managed by ZK, the cluster enters an election state. If there is a leader then there exists an established hierarcy and the existing leader is just verified. If there is no leader (say master is down), ZK forces the znodes to use sequence flags to look for a new leader. Each node talks to its peers and sends a message containing the node's identifier (sid) and the most recent transaction it executed (zxid). These messages are called votes. When a node receives a vote it can either neglect it or keep it depending the zxid. If zxid is newer it keeps the vote if older than what it has it discards it. If there is a tie in zxids then the vote with the highest sid wins! So there will come a time when all nodes will have the same vote which will define the new leader by the sid. So this is how ZK elects a new leader node!

这篇关于Zookeeper 如何管理其他集群中的节点角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆