在MongoDB中投票 [英] Voting in MongoDB

查看:143
本文介绍了在MongoDB中投票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

建议设置一个奇数.我的疑问是,随着人们从奇数集下降,我们有了偶数集.当成员数一一下降时,成员数在偶数和奇数之间波动.我们始终不会出现奇数成员的情况.有人可以解释一下MongoDB投票的工作原理吗?

An odd number set is recommended. My doubt is as one goes down from an odd set, we have an even number set. The number of members fluctuate between even and odd when they go down one by one. We always don’t have odd member scenario. Can some one explain how MongoDB voting works?

推荐答案

投票由多数投票成员完成.

The voting is done by a majority of voting members.

想象一个具有三个(投票)成员的副本集. 假设节点A是主要的,而节点B + C是次要的. 节点A发生故障,因此节点B + C进行了选举.他们仍然占多数(三分之二).选举首先由优先级决定.如果两个节点B& C具有相同的优先级,则关于失败的主(oplog)最新的优先级获胜.假设它是节点B.

Imagine a Replica Set with three (voting) members. Let's say that Node A is primary, and nodes B+C are secondaries. Node A goes down, so nodes B+C go to election. They still do form a majority (two out of three). The election is first decided by priority. If both Nodes B & C have the same priority, then the one who is most up to date in respect to the failed primary (oplog) wins. Let's say it's Node B.

一旦节点A恢复活动,就不会有新的选举.节点B仍然是主节点,而C + A现在是辅助节点.

Once node A comes back alive, there is no new election. Node B remains the master, and C+A are now secondaries.

另一方面,如果两个节点出现故障,您将没有多数,因此副本集将无法再接受更新(应用写入),直到两个发生故障的服务器中至少有一个处于活动状态(并已连接)仍然是单个幸存节点).

On the other hand, if two nodes go down you don't have a majority, so the replica set can't accept updates (apply writes) any more until at least one of the two failing servers becomes alive (and connected by the single surviving node) again.

现在想象一个具有四个(投票)成员的副本集. 假设节点A是主要的,而节点B + C + D是次要的. 节点A发生故障,因此节点B + C + D进入选举.他们当然占多数(四分之三)

Imagine now a Replica Set with four (voting) members. Let's say that Node A is primary, and nodes B+C+D are secondaries. Node A goes down, so nodes B+C+D go to election. They of course form majority (three out of four)

但是,如果两个节点出现故障,您将没有多数(四分之二),因此副本集再次处于只读模式.

However, if two nodes go down you don't have a majority (two out of four), so the replica set is again at read only mode.

所以这就是为什么建议使用奇数的原因;如果您在3个成员副本集中失去一个成员,就与在4个成员副本集中失去一个成员一样:您仍然获得法定多数,并且可以选择新的主要成员(RS仍可以通过以下方式选择新的主成员:多数).另一方面,如果您将3个成员副本集或4个成员副本集(或n个成员副本集的n/2个成员)中的两个成员放开,那么影响是相同的:无法投票选举新的领导者通过选举.

So that's why an odd number is recommended; If you loose a single member in a 3 members replica set, it's the same as loosing a single member in a 4 members replica set: you still gain quorum majority and a new primary can be elected (the RS can still elect a new master by majority). On the other hand, if you loose two members in a 3 members replica set or a 4 members replica set (or n/2 members of n-members replica set) - again - the impact is the same: No new leader can be voted by election.

因此,总而言之,在副本集中只有偶数个成员不会带来冗余.

So, to make a long story short, there is no redundancy gain by having an even number of members in a replica set.

有关更多的请参阅选举内部资料

这篇关于在MongoDB中投票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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