[SERVER-57678] Dropping timeseries view and creating Collection on same namespace may be replicated out-of-order Created: 14/Jun/21  Updated: 29/Oct/23  Resolved: 16/Jun/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.0.0-rc3, 5.1.0-rc0

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:
Backports
Depends
Related
Backwards Compatibility: Fully Compatible
Backport Requested:
v5.0
Sprint: Execution Team 2021-06-28
Participants:
Linked BF Score: 150

 Description   

When dropping a Timeseries collection we hold a MODE_X lock on the bucket collection but just a MODE_IX lock on the view namespace.

_abortIndexBuildsAndDrop called here is holding a MODE_X lock on the bucket Collection:
https://github.com/mongodb/mongo/blob/fd808e64b2a34bedfeeef012c2ef9314bec08e8f/src/mongo/db/catalog/drop_collection.cpp#L330

But the View is just holding a MODE_IX lock
https://github.com/mongodb/mongo/blob/fd808e64b2a34bedfeeef012c2ef9314bec08e8f/src/mongo/db/catalog/drop_collection.cpp#L91

If there is a create Collection happening concurrently (also MODE_IX) with dropping the view the operations may be written to the oplog out-of-order because create Collection reserves the oplog time before creating the Collection: https://github.com/mongodb/mongo/blob/fd808e64b2a34bedfeeef012c2ef9314bec08e8f/src/mongo/db/catalog/database_impl.cpp#L679-L692

When this is then applied on a secondary the Collection creation fails with an invariant because there already exist a timeseries view on the namespace.

A proposed solution is to hold a MODE_X lock on the view namespace when dropping timeseries collections.



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 17/Jun/21 ]

Author:

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

Message: SERVER-57678 Take MODE_X collection lock when dropping timeseries view.

This is to prevent a concurrent create collection on the same namespace that will reserve an OpTime before the drop.

(cherry picked from commit a616859a60e6cbb40ab0b7ddbeed06e726bd40bc)
Branch: v5.0
https://github.com/mongodb/mongo/commit/fb5549f1ab3975b832ee64834317890d0ce61b94

Comment by Githook User [ 16/Jun/21 ]

Author:

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

Message: SERVER-57678 Take MODE_X collection lock when dropping timeseries view.

This is to prevent a concurrent create collection on the same namespace that will reserve an OpTime before the drop.
Branch: master
https://github.com/mongodb/mongo/commit/a616859a60e6cbb40ab0b7ddbeed06e726bd40bc

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