Automatic failover of MongoDB replica set

Source: Internet
Author: User
Tags install mongodb
The election plays a very important role in the operation of the replica set. During the election, there is no master node in the replica set, and the client's reading request is unacceptable.

The election plays a very important role in the operation of the replica set. During the election, there is no master node in the replica set, and the client's reading request is unacceptable.

Introduction to the high availability of a replica set

The replica set achieves high availability through automatic failover. When the master node fails, the slave node can be elected as the master node, and this process is automatically performed in most cases, manual intervention is not required. In some cases, data rollback is required for automatic failover.

Deployment of replica sets (number of replica set members, physical factors, such as the geographic location of bandwidth replica set members) may affect the efficiency of automatic failover. To improve the efficiency of automatic failover, we should put most members of the replica set into a core data center for management, and put several slave nodes in the replica set. When the master node fails, this ensures that available slave nodes are available and can also be used to isolate communication among most replica integrators due to network faults.

Automatic failover involves two main processes: Election and rollback.

The election plays a very important role in the replica set operation. When the election requires a call fee, the replica set does not have a master node during the election process ,, the client's read requests cannot be accepted, so MongoDB tries its best to avoid election.

Election: when the master node is unavailable; when the replica set is initialized

Ii. Factors affecting elections

1. Heartbeats)

Heartbeat: The replica set sends a heartbeat request packet every two seconds (the packet is sent to ping the other side). If no response is received from the other side within 10 seconds, I think it has a fault.

2. Priority comparison

The priority of Members will affect the election process. Members will give priority to their votes to the members with higher priority.

Members with zero priority will not be elected as the primary database because they will not be voted and will not be elected.

As long as the current master database has the highest priority and the content of the operation log entries within 10 seconds is up-to-date, no election will be conducted.

If a member with a higher priority enters the current primary and its operations are performed, the election set with a higher priority node provides an opportunity to become the master database.

3. Operation Time: The operation time refers to the log entry time when a Member executes the operation log for the last time. If a member is up-to-date (most recent) than other operations, it may be elected as the master database.

4. Connectivity: a Member in the replica set can become the master node only when it is connected to the majority of Members. Otherwise, it will be automatically downgraded to the slave node.

For example, for a replica set with three members, each member can vote. If only two of them can be connected, the replica set can be elected once. If two of the nodes become unavailable and the remaining node is a slave node, it is still a slave node because it cannot be connected to other members. In the same way, if the node is the master node, it will be automatically downgraded to the slave node because it cannot be connected to other Members and loses the qualification to become the master node. in this way, the replica set becomes read-only.

5. Network partition: Because of network partitions, if a master node is unavailable and the other slave nodes cannot communicate with the majority, the replica set cannot be elected. So try to put most of the replica set members in one data center, and put a small part in another.

For more details, please continue to read the highlights on the next page:

MongoDB details: click here
MongoDB: click here

Recommended reading:

Java-based self-growth field in MongoDB

CentOS compilation and installation of MongoDB

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

How to create a new database and set in MongoDB

MongoDB beginners must read (both concepts and practices)

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.