Rename with dropTarget must be done atomically in the catalog to prevent a lock free reader to observe intermediate invalid state

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Fixed
    • Priority: Major - P3
    • 4.9.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • Execution Team 2021-01-11
    • 50
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Rename with dropTarget=true is performed in two phases with each phase is writing to the catalog while holding a MODE_X lock for the collection.

      https://github.com/mongodb/mongo/blob/72565dc7c6909fd6f96f5625a9d28c64efed8c9e/src/mongo/db/catalog/rename_collection.cpp#L267-L273

      As holding a MODE_X lock does not prevent a lock free reader it may observe the collection as dropped as this is written to the in-memory catalog separately from the rename: 

      https://github.com/mongodb/mongo/blob/72565dc7c6909fd6f96f5625a9d28c64efed8c9e/src/mongo/db/catalog/database_impl.cpp#L517-L522

      This whole operation must be performed atomically in a single catalog write as MODE_X lock mode cannot be used to prevent readers anymore.

            Assignee:
            Henrik Edin
            Reporter:
            Henrik Edin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: