MongoDB (a member of the replica set)

Recommended for you: Get network issues from WhatsUp Gold. Not end users.


A MongoDB replica set.

MongoDB replication mechanism is mainly divided into two types:
Master-Slave (master-slave replication) this is not recommended
Replica Set (replication set) the new function of MongoDB development in version 1.6, the official recommended



MongoDB replica set than the previous Master-Slave architecture is powerful, support on multiple machines by asynchronous replication mode to realize data redundant database, greatly degrade the risk of single point of failure, automatically switch and can realize fault. By default, the multi machine at the same time by only one table for read and write operations, which provides strong data consistency, data consistent between each DB.

MongoDB replica set member is composed of a set of mongod process instance, in fact Replica Set structure like in a cluster, it might be considered a cluster, as it does with cluster to achieve the effect is the same: if one node fails, the node immediately to take over without stopping operation.


Two Replica Set members


Members of the MongoDB replication set includes: a main node, the node and the node three categories, the following one one detail.



1 the master node(Primary)

The master node is responsible for all write requests, the master node is the replica set only one can accept the write operation request, the master node will all write operations to the oplog log records, from the node can copy the oplog log, these operations applied to their own node.
By default, the client will all read requests sent to the master node, but also can be configured to read data from the nodes have the ability.
A replica set can only have one master node, if it is not available (or endowment not enough time) when, through the election algorithm from the node to select one as the main node of the new.

2 from the node(Secondaries)


By copying the master node data from nodes (by reading operation log files) l to maintain data consistency. In addition, through some configuration (for example does not let it have the right to vote, the priority is set to zero) from the nodes can also make it have some special effects. Mainly has the following several common when the configuration:

2.1. priority is set to 0 (Priority 0): from a node priority is set to zero, lost the right to be elected, the node will not be able to become a master node.


Note: the a.Priority0 node, although not the right to be elected, but have the right to vote, to vote in elections, and it will also keep a master node data, can accept a read operation.
B.Priority0 nodes in multi data center deployment is very useful, can be the master and slave nodes into the main data center, priority0 into another, it can increase the data when safety.


In addition to C., Priority0 can be used as a substitute member, when the replication set member when not available, can be replaced quickly, also can the hardware is relatively poor machine settings for Priority0.


The members of the 2.2.Hidden: Hidden members are not visible to clients, and therefore do not provide a read request, the from node a backup data.


Note: a data a.Hidden members will also keep the master node to the client, but it is not seen, (db.isMaster) does not display the Hideen members. The Hidden member is also a member of the Priority0, only have the right to vote.
B.Hidden and other members of the node link is a one-way communication, send other node cannot request to the Hidden member, because of Hidden to other nodes is not visible, then the members of the Hidden network communication pressure is relatively small, we can use it to do the report or backup. If you want to do backup, we should ensure that the network bandwidth between Hidden nodes and a main node, as far as possible to reduce the replication lag time, try to keep the consistency of the data between the height.

The 2.3 historical snapshot delay (Delayed): members of the class from the nodes are not the master node and data retention time on a consistent, save it now before the data, has quite a history snapshot.

A. delay members reflects the master node to an earlier state, for example we set a delay of one hour to members of the Delayed, the current is 9:52, then a Delayed member only recorded before 8:52 data. Because the Delayed member record data lag, when we are in the process of upgrading the operating system or some wrong words, you can use the Delayed member to operate the rollback data recorded.
The b.Delayed member is Priority0 and hidden. which also has the right to vote.
C.Delayed members to "lag" approach to operating from the master node synchronization log data, so when the lag time we set the Delayed member should not be too high, because the operation log is updated (a Capped Collection), if set delay time is too long, the operation log recording early operation may be updated, but not set too small, if too small words lost Delayed members exist when the meaning (should be greater than the system maintenance or upgrade the window time).


In the following 5 members replica set example, a master node and 4 slave nodes have a copy of the data, one of the members is set to 3600 seconds delay (one hour), note that a Delayed is also a member of Priority0 and Hidden members.


Like this we can set up a Delayed member:



"_id" : <null> ,
"host" : <hostname:port> ,
"priority" : 0,
"slaveDelay" : <seconds> ,
"hidden" : true

}



Note: 1 each from the nodes have a master copy of the data, they through the master node (or from the node, as long as the new words from the node operation log than their operation log recording operation) operation log recording information, asynchronous completed write operations.

3 arbitration node (arbiter) arbitrator may become a member of replica set, it will not store data, its main role is to vote. For example, when the replica set has an even number of members, you can add an arbiter.

Note: only when the replication set number of nodes can vote for even when we can add an arbiter. As shown below, a replica set originally had four members, this time we can add an arbitrator, mediator does not store data.






Note: a replica set can have a maximum of 12 members, each at the same time there can be only 7 members can vote, such restrictions in order to reduce the cost and improve the efficiency of the voting time, fault switching.





Three summary


Using the replica set is transparent to the user. The client can also be configured to "read reference" gets data from the slave node, but the data may not be updated, because the operating data may be the master node is not synchronized to the slave nodes, this phenomenon is called "eventual consistency", if allowed to read data from the node, MongoDB cannot guarantee strong the consistency of the data "".






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Asa at December 08, 2013 - 11:50 PM