mclaassen
mclaassen

Reputation: 5138

Cannot read from last remaining node in replica set

I have a 3 node MongoDB (2.6.3) replica set and am testing various failure scenarios.

It was my understanding that if a majority of the replica nodes are not available then the replica set becomes read only. But what I am experiencing is if I shut down my 2 secondary nodes, the last remaining node (which was previously primary) becomes a secondary and I cannot even read from it.

From the docs:

Users may configure read preference on a per-connection basis to prefer that the read operations return on the secondary members. If clients configure the read preference to permit secondary reads, read operations can return from secondary members that have not replicated more recent updates or operations. When reading from a secondary, a query may return data that reflects a previous state.

It sounds like I can configure my client to allow reads from secondaries, but since it was the primary node that I left up, it should be up to date with all of the data. Does MongoDB make the last node secondary even if it is fully caught up with data?

Upvotes: 2

Views: 1010

Answers (1)

Ori Dar
Ori Dar

Reputation: 19020

As you've noted, once you've shut down the two secondaries, your primary steps down and becomes a secondary (it's a normal scenario once a primary looses connection to the majority of members).

The default read preference of a replica set is to read from primary, but since your former primary is not even primary anymore, as you have encountered , "I cannot even read from it."

You can change read-preference on a driver/database/collection and even operation basis.

since it was the primary node that I left up, it should be up to date with all of the data. Does MongoDB make the last node secondary even if it is fully caught up with data?

As said, the primary becomes secondary as it steps down, nothing to do with the fact that it's up to date or not. It wouldn't read even because of the default read preference, if you will change your driver preference to secondary , nearest or so, you'll be able to continue reading even if a single node (former primary) remains.

Upvotes: 3

Related Questions