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

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

问题描述

我的理解是,Zookeeper通常用于解决跟踪哪个节点在分布式系统中扮演特定角色的问题(例如,数据库或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的答案都称为领导人选举程序,其简要操作如下:

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

当进程在由ZK管理的群集中启动时,群集进入选举状态。如果存在领导者,则存在已建立的层级,并且仅对现有领导者进行验证。如果没有领导者(例如主服务器已关闭),则ZK会强制znodes使用序列标志来寻找新的领导者。每个节点都与其对等方对话,并发送一条消息,其中包含该节点的标识符(sid)和它执行的最新事务(zxid)。这些消息称为投票。节点收到投票后,可以忽略投票,也可以根据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天全站免登陆