[SERVER-40264] Change MigrationChunkCloner to be a shared pointer to synchronize object lifetime across threads Created: 21/Mar/19  Updated: 29/Oct/23  Resolved: 25/Mar/19

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 4.1.9
Fix Version/s: 4.1.10

Type: Task Priority: Major - P3
Reporter: Blake Oler Assignee: Blake Oler
Resolution: Fixed Votes: 0
Labels: sharding-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Sprint: Sharding 2019-04-08
Participants:
Linked BF Score: 11

 Description   

Background

Recently, the CollectionShardingState (CSS) and CollectionShardingRuntime (CSR) received a new synchronization module – the CollectionShardingRuntimeLock (CSRLock). The CSRLock is a ResourceLock meant to be used as a fancier std::mutex. It was built in order to protect lifetime access to pointers and internal structures placed upon the CSS/CSR. Users of the CSS/CSR's internal structures would take the CSRLock when accessing corresponding pointers. The CSRLock would stay in scope until these pointers do not need to be used any longer.

Problem

The CSRLock was built with a key assumption that is shared with std::mutex – we are never to do I/O or network calls while we are inside the locking mechanism.

In the MigrationChunkCloner, a CSR sub-structure, we perform I/O operations. If we are doing this under the CSRLock, this can cause locking issues with other parts of the database system. The linked BF is an example of such an issue.

Solution

We'd still like to protect the lifetime of the MigrationChunkCloner, but do not want to perform I/O operations under the lock. Accordingly, we will change the MigrationChunkCloner from a raw pointer to a shared pointer. This will prevent the object from going out of scope while references to the object exist. Since shared pointers are not thread safe, we will still use the CSRLock to safeguard the creation of additional references.



 Comments   
Comment by Githook User [ 25/Mar/19 ]

Author:

{'name': 'Blake Oler', 'username': 'BlakeIsBlake', 'email': 'blake.oler@mongodb.com'}

Message: SERVER-40264 Change MigrationChunkCloner to be a shared pointer to synchronize object lifetime across threads
Branch: master
https://github.com/mongodb/mongo/commit/1bcdfab7d16c899689f1f74f04c66ebb23a80ef5

Generated at Thu Feb 08 04:54:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.