Order writes to replication oplog under document-level locking

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Major - P3
    • 2.8.0-rc0
    • 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
      

            Assignee:
            Eliot Horowitz (Inactive)
            Reporter:
            Kaloian Manassiev
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: