Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Why is the number of Zookeeper cluster nodes odd?

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces why the number of Zookeeper cluster nodes is odd, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.

Why is the number of Zookeeper cluster nodes odd? In our work, the number of nodes in the Zookeeper cluster is odd. As for why there is an odd number, they may all know that it is to meet the needs of the election, but they do not know the detailed reasons. This article mainly describes the reasons and principles in order to avoid being Pass during the interview process.

First of all, we need to clarify the rules of zookeeper election: leader election, which requires the number of available nodes > the total number of nodes / 2. Note that it is >, not ≥.

Note: why do the rules require the number of available nodes > the total number of nodes in the cluster / 2? If there is no such restriction, when brain cracks occur in the cluster, multiple sub-clusters may serve at the same time (that is, each group of the sub-cluster elects its own leader), which is chaotic for the whole zookeeper cluster. In other words, if the election is conducted in accordance with the above rules, even if brain cracks occur, there can only be one sub-cluster that can provide services (there will be at most one sub-cluster that can satisfy the number of nodes > the number of summary points / 2). So limit the number of available nodes > the total number of nodes in the cluster / 2.

The adoption of odd nodes is mainly due to two considerations:

1. Prevent clusters caused by brain fissure from becoming unavailable.

First of all, what is a brain fissure? The brain fissure of the cluster usually occurs when the communication between the nodes is unreachable, the cluster will be divided into different small clusters, and the small clusters each choose their own master nodes, resulting in the case of multiple master nodes in the original cluster, which is called brain fissure.

The following example shows why odd nodes are used to prevent services caused by brain fissure from becoming unavailable:

(1) if the zookeeper cluster has 5 nodes, the brain fissure occurs and the brain fissure is divided into two small clusters An and B:

(a) A: 1 node, B: 4 node

(B) A: 2 nodes, B: 3 nodes

You can see that in the above two cases, there will always be a small cluster in An and B that satisfies the number of available nodes > the total number of nodes / 2. So the zookeeper cluster can still elect leader and still provide services, but some nodes have failed.

(2) if the zookeeper cluster has 4 nodes, the brain fissure also occurs, and the brain fissure is divided into two small clusters An and B:

(a) 1 node for Avatar and 3 nodes for BRV

(B) 2 nodes for Avatar and 2 nodes for BRV

It can be seen that situation (a) meets the electoral conditions, the same as the example in (1). But the situation (b) is different, because both An and B are two nodes, and neither of them meets the election condition of the number of available nodes > the total number of nodes / 2, so zookeeper cannot provide services at all.

Combining the above two examples, we can see that when the number of nodes is odd, the zookeeper cluster can always provide services (even if some nodes are lost); if the number of nodes is even, there is the possibility that the zookeeper cluster cannot be used (when the brain is split into two equal sub-clusters).

In a production environment, if the zookeeper cluster cannot provide services, it will be fatal, so the number of nodes in the zookeeper cluster is generally odd.

2. Odd-numbered stations save more resources when the fault tolerance is the same.

Leader election requires the number of available nodes > the total number of nodes / 2. Note that it is >, not ≥.

Here are two examples:

(1) if there are 3 nodes in zookeeper cluster 1, and there are at least 2 nodes in order for zookeeper to provide services normally (i.e. leader election is successful), at least 2 nodes are normal. In other words, a three-node zookeeper cluster allows one node to go down.

(2) if there are 4 nodes in zookeeper cluster 2, that is, if zookeeper wants to provide services normally (i.e. leader election is successful), at least 3 nodes are required to be normal. In other words, a four-node zookeeper cluster also allows one node to go down.

Then the problem arises: both Cluster 1 and Cluster 2 have fault tolerance to allow one node to go down, but Cluster 2 has one more node than Cluster 1. In the case of the same fault tolerance, it is better for the zookeeper cluster to maintain an odd number of nodes in order to save resources.

As to why the odd number of Zookeeper cluster nodes is shared here, I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report