The Journey of 100DaysofCode aka 100DaysofMongoDB (@Aasawari_24)

Day09 as #100DaysofMongoDB as #100daysofcode

Starting the discussion for Concurrency control in Replication

In Day07 we discussed about having mutual exclusive lock on the transaction in order to maintain the atomicity of the transactions. There is yet another lock known as Parallel Batch Writer Mode lock which helps in maintaining the concurrency of the operations while a secondary is applying oplog entries.
The lastApplied is a timestamp value set when the secondary has completed the batch of writing to the oplog.
Since secondary node of the replica set writes the oplog in batched, the Parallel Batch Writer Mode lock is acquired and released when the complete batch is written in the entry.

There is yet another lock whose purpose is to maintain the concurrency among the transactions, known as, Replication State Transition Lock which is acquired when the nodes are in transition state.
It is acquired in exclusive mode for the following replication state transitions: PRIMARY to SECONDARY (step down), SECONDARY to PRIMARY (step up), SECONDARY to ROLLBACK (rollback), ROLLBACK to SECONDARY , and SECONDARY to RECOVERING.

Note: The locks must be acquired before the global lock is acquired.
The order recommended is:
Acquire Parallel Batch Writer Mode lock prior to Replication State Transition Lock in shared and exclusive mode respectively. Keep the global lock to be acquired later.

Let me know if you have questions related to the same.

Thanks
Aasawari

Share on twitter: https://twitter.com/Aasawari_24

3 Likes