October 27, 2015 · by Srinivas · in MongoDB
 

MongoDB replica sets provide a number of features that most MongoDB users are going to want to leverage. Best of all they are relatively easy to setup. However, first timers often hesitate when it comes to the role of arbiters. Knowing whether or not you need an arbiter is dead simple. Understanding why is critical.

You need an arbiter if you have an even number of votes. As an extension to this, at most you should only ever have 1 arbiter. If you aren’t sure how many votes you have, it’s probably the same as the number of servers in the set you have (including slaves, hidden, arbiters).

Elections and Majority

When the primary becomes unavailable, an election is held to pick a new primary server from those servers still available. One of the key points to understand is that a majority is required to elect a new primary. Not just a majority from available servers, but a majority from all of the servers in the set.

For example if you have 3 servers, A(primary), B and C then it’ll always take 2 servers to elect a new primary. If A(p) goes down, then B and C can and will elect a primary. However, if B also goes down, C will not elect itself as primary because it will only get 1/3 of the votes (as opposed to the necessary 2/3).

In other words, a 3 server replica set can tolerate a single failure. A 5 server replica set can tolerate 2 failed servers (3/5 is a majority). A 7 server replica set can survive 3 failed servers (4/7).

Network Splits and Ties

To understand the other key point it helps if we change our perspective from thinking of servers going down, to thinking in terms of network splits. What?

You see, when you think of servers crashing, it’s reasonable to expect any remaining server to be elected – even without a majority. Instead of servers going down, consider what would happen if the servers all remain operational but can’t see each other. Let’s look at an example

Pretend we have 4 servers – representing a [evil] even number of votes: A, B, C and D. AB are in one data center (or availability zone) while CD are in another. Now, the link between the two data-centers dies. What would happen? Each group thinks the other is down and could both elect their own primary. This would cause data conflicts (two servers would be accepting writes).

So let’s introduce an arbiter (E) and with it, an uneven number of votes. Now each servers knows that the set is made up of 5 votes, and thus 3 votes are required to elect a new primary. Whatever group E ends up with (either ABE or CDE) a primary will be elected, and, more importantly, whatever group E doesn’t end up with won’t be able to elect a primary.

What happens if AB, CD and E do a three way split? Then there is no majority and thus no primary and the set will go down (but that’s much better than having 2 primaries).

Separate Servers?

People often wonder whether an arbiter can run on the same box as one of the main mongod processes? Ideally, no. Imagine we have AB and C where B is arbiter running on the same server as A. If that server goes down you’ve lost your majority. In other words, in this set up, if the wrong server goes down you have no redundancy. However, if C goes down, AB can and will remain a primary (and if you think you can just stick a 2nd arbiter on C, then this article has failed you miserably, and I’m very sorry for having wasted your time).

Arbiters don’t store any of the data and is a lightweight process. An Amazon’s EC2 micro instance is more than powerful enough.

Conclusion

The most important thing is to have an uneven number of votes. Knowing this, it should be obvious that you either want 0 arbiters or 1…but never, ever more.

It’s also important to understand that election doesn’t rely on the majority of available servers, but of all servers in the set. A 3-server replica set will not tolerate 2 servers failing. Thinking in terms of network splits in the context of separate data centers helps me visualize this.

[MONGODB]: WHEN ARBITER REQUIRED FOR REPLICA SET的更多相关文章

  1. NoSQL数据库Mongodb副本集架构(Replica Set)高可用部署

    NoSQL数据库Mongodb副本集架构(Replica Set)高可用部署 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. MongoDB 是一个基于分布式文件存储的数据库.由 C ...

  2. Mongodb集群搭建之 Replica Set

    Mongodb集群搭建之 Replica Set Replica Set 中文翻译叫做副本集,不过我并不喜欢把英文翻译成中文,总是感觉怪怪的.其实简单来说就是集群当中包含了多份数据,保证主节点挂掉了, ...

  3. MongoDB的集群模式--Replica Set

    一.Replica Set 集群分为两种架构: 奇数个节点构成Replica Set,所有节点拥有数据集.最小架构: 1个Primary节点,2个Secondary节点 偶数个节点 + 一个仲裁节点 ...

  4. MongoDB高可用架构:Replica Sets+Sharding

    MongoDB的sharding解决了海量存储和动态扩容的问题.但是遇到单点故障就显得无能为力了.MongoDB的副本集可以很好的解决单点故障的问题.所以就有了Sharding+Replica Set ...

  5. MongoDB:搭建三节点 Replica Set 环境

    今天学习了搭建 MongDB 复制环境,实验环境是在虚拟机上同一系统,并搭建三节点 Replica Set,根据文档上的描述,mongodb 复制配置简单,并且能够自动 failover,这些高级特性 ...

  6. 关于MongoDb Replica Set的故障转移集群——实战篇

    如果你还不了解Replica Set的相关理论,请猛戳传送门阅读笔者的上一篇博文. 因为Replica Set已经属于MongoDb的进阶应用,下文中关于MongoDb的基础知识笔者就不再赘述了,请参 ...

  7. Mongodb集群搭建之 Sharding+ Replica Sets集群架构

    1.本例使用1台Linux主机,通过Docker 启动三个容器 IP地址如下: docker run -d -v `pwd`/data/master:/mongodb -p 27017:27017 d ...

  8. MongoDB Replica Set搭建集群

    MongoDB做集群,版本3.2官网推荐的集群方式Replica Set 准备服务器3台 两个standard节点(这两个节点直接可以互切primary secondary). 一个arbiter节点 ...

  9. Configure MongoDB Replica Set

    Table of Contents Introduction Requirements Create Replica Set Add Secondary Members Add an Arbiter ...

随机推荐

  1. [jQuery学习系列一]1-选择器与DOM对象

    前言: 好久没有更新博客了, 最近想复习下 之前学过的JS的相关内容, 也算是自己的一种总结. 知识长时间不用就会忘记, 多学多记多用!! 下面的程序都可以在下面的网站进行在线调试: http://w ...

  2. PowerDesigner建表

    SQL: --建表 --管理人员表 admin --drop table WPADMIN cascade constraints; /*================================ ...

  3. Maven学习总结(九)——使用Nexus搭建Maven私服

    一.搭建nexus私服的目的 为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找一台有外网权限的机器,搭建n ...

  4. 从此爱上iOS Autolayout

    转:从此爱上iOS Autolayout 这篇不是autolayout教程,只是autolayout动员文章和经验之谈,在本文第五节友情链接和推荐中,我将附上足够大家熟练使用autolayout的教程 ...

  5. AD8275 Driver Amplifiers For Analog-To-Digital Converters

    Driver Amplifiers For Analog-To-Digital Converters What amplifiers are used to drive analog-to-digit ...

  6. Xiaomi 手机

  7. Python - 升级所有已安装的第三方包

    我们有时候需要把系统上已经安装的第三方的packages升级到最新版.但是easy_install和pip都没有直接的命令可以使用. 我们可以是用如下命令来查看系统上面哪些包过期了. pip list ...

  8. C#接口的使用场合,接口应用

    当一个项目不断的扩大的时候,会面临的问题是不断的有以下情况: 1.以前编写程序的人离职了,新来的程序员看不懂以前的程序,或者觉得以前的程序部够好,但又不希望删除: 2.当实现第三方接口时,如:读写IC ...

  9. RHEL 6 或者 Oracle Linux 6, 不关机识别新添加的scsi硬盘

    下面看一下在系统不重启的情况,如何让系统认识新的磁盘,并能对其分区与格式化1.在开机状态下新增磁盘2.执行下面的命令 echo "- - -" > /sys/class/sc ...

  10. c++中的##和#的区别

    ##是一个连接符号,用于把参数连在一起 #是“字符串化”的意思.出现在宏定义中的#是把跟在后面的参数转换成一个字符串 #define paster( n ) printf( "token & ...