[SERVER-53535] Rename with dropTarget must be done atomically in the catalog to prevent a lock free reader to observe intermediate invalid state Created: 29/Dec/20  Updated: 29/Oct/23  Resolved: 06/Jan/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Task Priority: Major - P3
Reporter: Henrik Edin Assignee: Henrik Edin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
Related
is related to SERVER-53697 Directory per DB broken when enableMa... Closed
Backwards Compatibility: Fully Compatible
Sprint: Execution Team 2021-01-11
Participants:
Linked BF Score: 50

 Description   

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.



 Comments   
Comment by Githook User [ 06/Jan/21 ]

Author:

{'name': 'Henrik Edin', 'email': 'henrik.edin@mongodb.com', 'username': 'henrikedin'}

Message: SERVER-53535 Rename collection with dropTarget=true is written atomically into the catalog.

Collection drops are now implemented with correct isolation where the catalog is only updated after a successful commit so a lock free reader may not observe intermediate invalid state.
Branch: master
https://github.com/mongodb/mongo/commit/351af2efd3a0ddcdfc284350ff81d98fedd0a001

Generated at Thu Feb 08 05:31:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.