[SERVER-60420] The slow 'shardCollection' path performs heavy work under the critical section Created: 04/Oct/21  Updated: 29/Oct/23  Resolved: 15/Oct/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 5.0.3, 5.1.0-rc0
Fix Version/s: 5.2.0, 5.0.4, 5.1.0-rc1

Type: Bug Priority: Major - P3
Reporter: Kaloian Manassiev Assignee: Marcos José Grillo Ramirez
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Duplicate
is duplicated by SERVER-60609 Sharding collection with UnoptimizedS... Closed
Problem/Incident
Backwards Compatibility: Fully Compatible
Backport Requested:
v5.1, v5.0
Sprint: Sharding EMEA 2021-10-18
Participants:

 Description   

As part of the "Robust DDL" changes (PM-1965), the amount of work which shardCollection does under the critical section has increased from 4.4 to 5.0 and this leads to writes being blocked for longer time than necessary:

For more context, if a collection is being sharded and we discover that that collection is empty (has zero documents), we hold the critical section for the entire duration (index creation, chunks creation, etc.) in order to ensure that no writes come in case we are creating chunks on shards other than the primary.

However, if we discover that the collection has documents, we can only create chunks locally and therefore we can allow writes to proceed because they will always be searching on the primary shard.

As part of this ticket we should do the absolutely minimum amount of work under the critical section, as part of the optimised path.



 Comments   
Comment by Githook User [ 18/Oct/21 ]

Author:

{'name': 'Marcos José Grillo Ramirez', 'email': 'marcos.grillo@mongodb.com', 'username': 'm4nti5'}

Message: SERVER-60420 Release the critical section early in the shard collection slow path

(cherry picked from commit e7c0fc2c3eac5d5fd35b29fcc7d1d5d52946c293)
Branch: v5.0
https://github.com/mongodb/mongo/commit/827838d784cf439d84cdb3b467fe812be9cf034c

Comment by Githook User [ 18/Oct/21 ]

Author:

{'name': 'Marcos José Grillo Ramirez', 'email': 'marcos.grillo@mongodb.com', 'username': 'm4nti5'}

Message: SERVER-60420 Release the critical section early in the shard collection slow path

(cherry picked from commit e7c0fc2c3eac5d5fd35b29fcc7d1d5d52946c293)
Branch: v5.1
https://github.com/mongodb/mongo/commit/0c95864a269d7a66223eafe07906f8c87dacc1b7

Comment by Githook User [ 15/Oct/21 ]

Author:

{'name': 'Marcos José Grillo Ramirez', 'email': 'marcos.grillo@mongodb.com', 'username': 'm4nti5'}

Message: SERVER-60420 Release the critical section early in the shard collection slow path
Branch: master
https://github.com/mongodb/mongo/commit/e7c0fc2c3eac5d5fd35b29fcc7d1d5d52946c293

Comment by Marcos José Grillo Ramirez [ 13/Oct/21 ]

The sharded index creation library verifies if the collection is empty before starting the creation, and this verification did not change in 5.0, so, the index creation cannot happen inside of the critical section in the slow path, however, we do create chunks now under the critical section, as reported in SERVER-60609, I'll close SERVER-60609 as a duplicate of this ticket, because in the description of this ticket we already specify that we'll minimize the amount of work done in the critical section.

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