Database Reference
In-Depth Information
What Is a Secondary?
A secondary member is a data-carrying nonprimary member, which can (barring a few exceptions) theoretically
become a primary. It is a node, which can be read from and which replicates its data from the primary of its set in
as close to real-time as possible. By default, if you directly connect to a secondary without any read preference, you
cannot perform read operations. This is done to reinforce that with any read to a nonprimary, if there is a delay
in replication, you may be reading from older data. You can use the command rs.slaveOk() to set the current
connection you are on to read from secondaries. Or, if you are using a driver, you can set a read preference, as we will
discuss later in this chapter.
The concept of a primary is and should be ephemeral. That is, ideally you should have no “fixed” concept of
which node is primary. In a replica set, all of the secondaries are writing the same data as the primary in order to keep
up with replication. Therefore, if the secondaries are substantially less capable, they may not be able to cope in the event
they are promoted to primary.
Note
What Is an Arbiter?
An arbiter is a non-data-bearing node that is used to provide an additional vote to help maintain a majority for
replica set elections. It does not cast a deciding vote or direct which node is the primary, but participates and can be
a member of a quorum to decide a primary. Arbiters are best used to help avoid the “split brain” problem described
earlier. Consider the diagram shown in Figure 11-2 . With the addition of an arbiter to Site A, we can always have one
side that can create a majority. This means in the event of the network break, we don't wind up with two primaries!
We can add further redundancy by having an arbiter in a third Site C. This way, if Site A goes down we can still form
a majority from the nodes in Sites B and C. Using a third site like this we can always continue in the event we lose
connectivity to any one site.
Figure 11-2. Split Brain Problem Solved
 
 
Search WWH ::




Custom Search