本文介绍了Zookeeper中集成与法定人数之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是动物园管理员的新手.我已经在一台机器上配置了它.但是我在Zookeeper的文档中碰到了合奏"和法定人数"两个词.

I am new to zookeeper. I have configured it on a single machine. But I came across the words "ensemble" and "quorum" in the documentation of zookeeper.

任何人都可以告诉我两者之间的区别吗?

Can anyone please tell me the difference between these?

  • 合奏
  • 法定人数

推荐答案

此答案适用于仍然不确定Ensemble and Quorum的人们. 合奏不过是一组Zookeeper服务器,其中 Quorum 中定义了形成健康合奏的规则.它使用公式Q = 2N+1定义,其中Q定义了形成健康的整体所需的节点数,该整体可以允许N失效节点.在下面的示例中,您将了解此公式.

在开始示例之前,我想定义两件事-
集群:一组连接的节点/服务器(现在将使用node),其中一个节点作为Leader/Master,其余节点作为Followers/Slaves.
健康合奏:在任何给定时间点只有一个活跃的Leader的集群,因此容错.

让我用一个示例进行说明,该示例在定义Ensemble and Quorum时经常使用.

This answer is for those who still have doubt understanding Ensemble and Quorum. Ensemble is nothing but a cluster of Zookeeper servers, where in Quorum defines the rule to form a healthy Ensemble. Which is defined using a formula Q = 2N+1 where Q defines number of nodes required to form a healthy Ensemble which can allow N failure nodes. You will understand about this formula in the following example.

Before I start with an example, I want to define 2 things-
Cluster: Group of connected nodes/servers (now on will use node) with one node as Leader/Master and rest as Followers/Slaves.
Healthy Ensemble: A cluster with only one active Leader at any given point of time, hence fault tolerant.

Let me explain with an example, which is used commonly across while defining Ensemble and Quorum.

  1. 假设您有1个Zookeeper节点.这里不需要担心,因为我们需要一个以上的节点才能形成集群.
  2. 现在占用2个节点.形成集群没有问题,但是形成一个健康的Ensemble是有问题的,因为-说这两个节点之间的连接丢失了,那么两个节点都会认为另一个节点已断开,因此他们都试图充当领导者,这导致不一致,因为他们彼此之间无法交流.这意味着由2个节点组成的集群甚至无法承受单个故障,那么该集群的用途是什么??他们并不是说您不能将2个节点组成一个集群,而是说-与拥有单个节点相同,因为两个节点都不允许出现单个故障.希望这很清楚
  3. 现在占用3个节点.形成簇或健康的集成体没有问题-因为根据上述3 = 2N+1 => N = (3-1)/2 = 1的公式,这可能会导致1次失败.因此,当发生下一个故障(连接故障或节点故障)时,不会选择任何节点作为领导者,因此,集成体将不提供任何写入/更新/删除服务,因此,客户端群集的状态在Zookeeper群集节点之间保持一致.因此,直到有多数节点可用且已连接时,领导者选举才会发生,多数节点为m = (n/2)+1n代表上次选举发生时可用的节点数.因此,在这里,第一次选举发生在3个节点上(因为它是一个3节点集群).然后发生第一个故障,因此剩余的2个节点可以进行选举,因为它们的多数票为m = (3/2)+1 = 2.然后发生第二次失败,现在他们没有多数,因为只有一个节点可供选举,但是所需的多数是m = (2/2)+1 = 2.
  4. 现在占用4个节点.形成群集或运行正常的集成体没有问题,但是拥有4个节点与3个节点相同,因为这两个节点仅允许1个故障.让我们从Quorum公式4 = 2N+1 => N = (4-1)/2 = ⌊1.5⌋ = 1 //floor(1.5)=1
  5. 派生它
  6. 现在占用5个节点.形成簇或健康的集成体没有问题-因为根据上述5 = 2N+1 => N = (5-1)/2 = 2的公式,这可能会导致2次失败.
  7. 现在采用6个节点.形成群集或运行正常的集成体没有问题,但是拥有6个节点与5个节点相同,因为这两个节点仅允许2个故障.让我们从Quorum公式6 = 2N+1 => N = (6-1)/2 = ⌊2.5⌋ = 2
  8. 派生它
  1. Lets say you have 1 zookeeper node. No need to worry here as we need more than 1 node to form a cluster.
  2. Now take 2 nodes. There is no problem forming a cluster but there is problem to form a healthy Ensemble, because - Say the connection between these 2 nodes are lost, then both nodes will think the other node is down, so both of them try to act as Leader, which leads to inconsistency as they can't communicate with each other. Which means cluster of 2 nodes can't even afford even a single failure, so what is the use of this cluster??. They are not saying you can't make a cluster of 2 nodes, all they are saying is - it is same as having single node, as both don't allow even a single failure. Hope this is clear
  3. Now take 3 nodes. There is no problem forming a cluster or healthy Ensemble - as this can allow 1 failure according the formula above 3 = 2N+1 => N = (3-1)/2 = 1. So when the next failure occurs (either connection or node failure), no node will be elected as Leader, hence the Ensemble won't serve any write/update/delete services, hence the states of the client cluster remains consistent across zookeeper cluster nodes. So the Leader election won't happen until there is majority nodes available and connected, where Majority m = (n/2)+1, where n stands for number of nodes available when the previous election happened. So here, 1st election happened with 3 nodes (as its a 3 node cluster). Then there was a 1st failure, so remaining 2 nodes can conduct election, as they have majority m = (3/2)+1 = 2. Then 2nd failure happened, now they don't have majority as there is only one node available for election, but the majority required is m = (2/2)+1 = 2.
  4. Now take 4 nodes. There is no problem forming a cluster or healthy Ensemble, but having 4 nodes is same as 3 nodes, because both allows only 1 failure. Lets derive it from the Quorum formula 4 = 2N+1 => N = (4-1)/2 = ⌊1.5⌋ = 1 //floor(1.5)=1
  5. Now take 5 nodes. There is no problem forming a cluster or healthy Ensemble - as this can allow 2 failure according the formula above 5 = 2N+1 => N = (5-1)/2 = 2.
  6. Now take 6 nodes. There is no problem forming a cluster or healthy Ensemble, but having 6 nodes is same as 5 nodes, because both allows only 2 failure. Lets derive it from the Quorum formula 6 = 2N+1 => N = (6-1)/2 = ⌊2.5⌋ = 2


结论:

  1. 要形成仲裁,我们需要至少3个节点-因为2个节点的群集甚至无法处理单个故障
  2. 最好形成奇数个节点的集合体-因为n个(偶数个)节点倾向于允许出现与n-1个(奇数个)节点相同数量的故障
  3. 拥有更多节点不是很好,因为它们会增加性能延迟.建议的生产群集大小为5-如果一台服务器因维护而停机,它仍然可以处理另一台故障.
  1. To form a Quorum we need atleast 3 nodes - as 2 node cluster can't even handle single failure
  2. Its good to form an Ensemble of odd number of nodes - as n (even number) nodes tends to allow same number of failure as of n-1 (odd number) nodes
  3. Its not good to have more nodes, as they add latency into performance. Suggested Production cluster size is 5 - if one server is down for maintenance, it still can handle one more failure.

这篇关于Zookeeper中集成与法定人数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 01:24