Database Reference
In-Depth Information
Replication Fundamentals
As you have seen, a replica set (or replSet) is a way to set up multiple MongoDB instances to contain the same data
for redundancy and other related measures. In addition to knowing this, you should also understand how MongoDB
accomplishes its replication, so you'll know how best to administer your own replica set.
You are already aware of the goals of replication in MongoDB, and if you have read the first edition of this topic
or have been using MongoDB since its early days, you will know that there have been a number of different ways that
one could accomplish replication, including these:
Master/Slave Replication
Master/Master Replication
Replica Pairs
These methods of replication have all been superseded by the concept of the replica set . In MongoDB a replica
set is made up of a primary node and a number of secondary or arbiter nodes. A replica set should be made up of an
odd number of members, meaning a minimum of three. This requirement arises because MongoDB replica sets have
a rule that the primary must be able to see a majority of other nodes in order to allow it to continue being primary.
This rule is enforced to avoid a “split brain” situation, where you have two primaries because of a potential fault in
networking, as illustrated in Figure 11-1 .
Figure 11-1. The Split-brain problem
What Is a Primary?
In replica set terms, a primary is the source of truth at a given moment for your replica set. It is the only node in the set
to which data can be written and from which all other nodes replicate their data. A primary is elected by agreement
of a majority of all voting members, known as a quorum .
Once a primary is elected, all secondaries will use it as the source of truth for their replication, and as such all
writes must be directed to this member.
 
Search WWH ::




Custom Search