There is an important concept in the replica set in MongoDB: most
Because the replica set has only one node that is readable and writable, the other nodes are readable only, and the selection of the master node is determined by the majority, and can continue as the primary node only if support is obtained.
(1) Most of the confirmation formula for this number: M=int ((N/2) +1)
* Most of the numbers are equal to greater than m, but less than or equal to n;n as the total number of servers in the replica set
(2) Once the majority is unavailable in a replica set, the entire replica set is unavailable and N/2 nodes fail for n is even, the entire replica set is invalidated;
Main node election mechanism:
(1) When the backup node is not connected to the primary node, it will contact other replica set members to elect itself as the primary node;
(2) The other members will do several checks first:
A. Is it connected to the master node itself?
B. Is the data for the backup node that you want to be elected as the primary node up to date?
C. Are there any other higher priority members that can be elected as the primary node?
(3) As long as a "majority" member voted against the vote, the election is rejected; only the candidate receives the "majority" member's affirmative vote, it becomes the main node.
This article is from the "Margin with Wish" blog, please be sure to keep this source http://281816327.blog.51cto.com/907015/1615019
MongoDB Learning Note 34 MongoDB replica set design principles