Write Majority and Secondary Read Preference on Mongo

119 views
Skip to first unread message

D

unread,
Aug 4, 2016, 3:38:02 AM8/4/16
to mongodb-user

Let's say I am having one Primary (A) & two secondary (B, C). If I am doing write using write majority. Can some one please explain my below doubts:-

  1. Let's say a write was done using majority and it updated the data in A & B and the write did not yet propagate to C. At this time if a read comes for the same data using secondary or secondary preferred will the query be served from B which is having the latest data or mongo cannot gurantee this and the read may return a stale data from C.
  2. Let's say a write was done using majority again and let's say the write was done on A and then a write is on progress in one of the secondary B. If a read comes at that time will the read be blocked or it will serve a stale data from C?
  3. Let's say I have taken out the secondary C and the same case is in progress as we mentioned in the above case. Will the read from secondary B be blocked till the write is complete on B or the read will not be blocked and a stale data will be served from B?

Environment

  • Mongo Version - 3.0.9 
  • Storage Engine - MMAPv1

Pooja Gupta

unread,
Aug 12, 2016, 1:29:45 AM8/12/16
to mongodb-user

Hi D,

  1. Let’s say a write was done using majority and it updated the data in A & B and the write did not yet propagate to C. At this time if a read comes for the same data using secondary or secondary preferred will the query be served from B which is having the latest data or mongo cannot gurantee this and the read may return a stale data from C.

The reads in the above scenario can be received by any of the secondaries, B or C. In case non- primary read preferences are specified, there is a chance of stale reads because with the asynchronous replication, data in secondary may not reflect the most recent write operations.
However, In 3.2, this can be mitigated by Read Concern ‘majority’ setting .

  1. Let’s say a write was done using majority again and let’s say the write was done on A and then a write is on progress in one of the secondary B. If a read comes at that time will the read be blocked or it will serve a stale data from C?
  • If readConcern is Primary, it will perform the read from A.
  • If readConcern is Secondary, it will perform the read from either B or C:
    • if reading from B, then it will block until the write is finished.
    • if reading from C, then it will return stale data.

You can also refer to Multithreaded Replication Page for more information on secondary read behaviour with replication.

  1. Let’s say I have taken out the secondary C and the same case is in progress as we mentioned in the above case. Will the read from secondary B be blocked till the write is complete on B or the read will not be blocked and a stale data will be served from B?

Taking node C offline does not alter the behaviour of node B for secondary reads.

In general, using secondary reads in a replica set must be done with careful planning, since it could interfere with the main purpose of a replica set, which is high availability.

For more information, please see:

Regards,
Pooja

Debraj Manna

unread,
Aug 12, 2016, 6:08:51 AM8/12/16
to mongod...@googlegroups.com
Thanks Pooja for the explanation.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to a topic in the Google Groups "mongodb-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-user/q_ap33UTDS8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-user+unsubscribe@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/97b772ac-3e11-48c4-9e6b-bf8b49214deb%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages