-
Type:
Improvement
-
Resolution: Done
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: Replication, Storage
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
With the current state of replication, writes to the oplog need to be ordered. This was guaranteed through the database lock in 2.6, but now with document-level locking this is no longer true, so we need to have something, which serializes writers, but doesn't block readers.
One option is to add a 'REPL' lock resource. Might be able to do this with a simple boost mutex as well if we can prove that there cannot be deadlocks. Here is the sequence of an updater to a given database A:
Lock (A, IX) Lock (A.Collection, IX) ... Do write using document-level locking, under the storage engine's transaction. Locks will be held till the end of the operation. Lock (REPL, X) Lock (LocalDB, IX) Lock (LocalDB.Collection, IX) ... Do write under the same storage engine transaction Unlock (REPL) // This is a performance optimisation to release the lock early Unlock All other locks
The oplog reader will look like this (it will skip locking the REPL resource):
Lock (LocalDB, IS) Lock (LocalDB.Collection, IS) ... Locate the last unreplicated location Unlock All