Sunday, 8 January 2017

MongoDB Course M102: MongoDB for DBAs Homework 5.2

I decided to go over M102 Homework 5.2 in more detail as it seems to throw some people. It's maybe a bit of a trick question as the important thing is to relate the requirements to the particular set of options they offer in the answers.

Here is the question as written in May 2016:
You have just been hired at a new company with an existing MongoDB deployment. They are running a single replica set with two members. When you ask why, they explain that this ensures that the data will be durable in the face of the failure of either server. They also explain that should they use a readPreference of "primaryPreferred", that the application can read from the one remaining server during server maintenance.
You are concerned about two things, however. First, a server is brought down for maintenance once a month. When this is done, the replica set primary steps down, and the set cannot accept writes. You would like to ensure availability of writes during server maintenance.
Second, you also want to ensure that all writes can be replicated during server maintenance.
Which of the following options will allow you to ensure that a primary is available during server maintenance, and that any writes it receives will replicate during this time?
Check all that apply.

The parts I've emboldened are actually the only bits we need to consider. Note that there are two requirements in the question.

To allow writes, the remaining members must have a majority to elect a primary. Therefore we need to have three or more members in total to allow writes when one is down for maintenance. So we know we need to add a member to our deployment.

To allow writes to be replicated, there needs to be a data-bearing primary with a data-bearing secondary to replicate to. Therefore, we need to add at least one data-bearing member to our current deployment to satisfy that requirement. This is really the "trick" to the question.

So, let's look at the options they give us:

1. Add an arbiter
2. Add two data bearing members plus one arbiter
3. Increase the priority of the first server from one to two
4. Add another data bearing node
5. Add two arbiters

Options 1, 3, and 5 do not add a data-bearing member, therefore we can ignore them as they do not satisfy the second requirement: they will not allow writes to be replicated during maintenance. Not that it matters, but Option 3 doesn't satisfy the first requirement either.

This leave only Options 2 and 4 that meet the requirements and are the correct answers.

Not that hard really, we just need to remember that arbiters are only useful in elections. The rest is an example where the examiners try to confuse us with too much detail.