2
votes

MongoDB docs about concurrency state that the DB is 'write greedy'. That is something I understand. However it does not tell about what locks do to secondaries in a replica set.

Taking my use-case which would get about 40 writes per 100 queries wherein I am not in need of having the most recent document at all times. A lag of 5-10 seconds is okay with me which is how much the secondaries in a replica set would be behind the master. Now if the write lock locks down master as well as the replicas, then I am locked out of reads on secondaries as well.

I wanted to know if writers will lock read operations on secondaries as well.

2
The write lock will only lock down the primary, not secondaries, the secondaries will lock when they replicate from the oplog sometime later, this should ease the concurrent writes and reads as you said by reading from the secondary at the same timeSammaye

2 Answers

2
votes

Into a replica set SECONDARY servers are not affected by the write lock on MASTERS. You can see the status of your servers by using mongotop or montostat.

1
votes

The locks are per mongod instance. That means that the read/write locks are locking operations only on the primary. The secondaries are reading oplog from primary and replicating actions from the primary.

You can read much more details on their manual about concurrency.