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. 博客还是搬到csdn吧~

    从csdn转到博客园是因为博客园开放了博客接口,方便发博客,再者博客样式也比较多,排版兼容性也较好. but, 博客园的链接在多个群里进行了宣传,当时大概有2000多的访问量,但是一个月过去了,现在还 ...

  2. Leetcode 263 Ugly Number 数论 类似质因数分解

    Ugly Number的质因数仅为2,3,5 将输入的数分别除以2,3,5直到不能除,看是否为1,为1的是Ugly Number,其他则不是. class Solution { public: boo ...

  3. 今日例子border

    border这个属性在页面上的使用率还是很高,例如我们需要理解的盒模型就需要对border有个 比较深的理解,如果你会盒模型,但对border没有深的理解,那只能说你只是知道盒模型,而 不是懂得盒模型 ...

  4. Java并发包中Lock的实现原理

    1. Lock 的简介及使用 Lock是java 1.5中引入的线程同步工具,它主要用于多线程下共享资源的控制.本质上Lock仅仅是一个接口(位于源码包中的java\util\concurrent\l ...

  5. 在Windows Server 2012的Task Scheduler里面配置自动发送邮件

    最近在一台server上配置了每个周末备份数据库的定时任务,想顺手配置发送备份完成的邮件提醒我去Double Check一下备份结果. 悲剧地发现Send an email功能被新版的server给禁 ...

  6. c#之第一课入门

    这几天看到微软的build大会,感觉微软不甘落后他人,曾经的巨头难道又要重新崛起,不管了,为了以后的饭碗,还是简单学习一些c#吧,有时这种紧张感不错的,现在由于这种紧张感,我已经掌握的java(主要弄 ...

  7. 上海邮政EMS海关清关(个人) 流程

    最近雾埋越来越严重,上个星期买了一个tacx骑行台,不料运气欠佳,被税了.那就去乖乖缴税吧. 拿着EMS的通知单(没有通知单就不要去了),到通知单指定的地址(上海有两处,我的是武定路458号)清关提货 ...

  8. Linux--Ubuntu12.04安装NDK

    前言 本篇博客将介绍如何在Ubuntu12.04下安装Android NDK,在其他版本的Ubuntu下,方法也类似.由于Android NDK不能单独作为Android应用程序来运行,因此,使用An ...

  9. 【LeetCode】273. Integer to English Words

    Integer to English Words Convert a non-negative integer to its english words representation. Given i ...

  10. [知识库分享系列] 三、Web(高性能Web站点建设)

    知识库分享系列: [知识库分享系列] 二..NET(ASP.NET) [知识库分享系列] 一.开篇 分享介绍此知识库之所以为 Web 系列,因为和 .NET 没有完全的关系,其中的技术和实践实用于各种 ...