[SERVER-74202] Update balancer to use client local Prng for thread-safe shuffling Created: 21/Feb/23  Updated: 29/Oct/23  Resolved: 17/Apr/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.0.0-rc0, 7.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Pol Pinol Assignee: Pol Pinol
Resolution: Fixed Votes: 0
Labels: sharding-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Related
related to SERVER-70129 std::random_device should be created ... Closed
Assigned Teams:
Sharding EMEA
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.0
Sprint: Sharding EMEA 2023-04-17
Participants:
Linked BF Score: 0

 Description   

As part of introducing the defragmentation policy, we introduced new threads in the balancer. These different threads are using the same random_device to shuffle different vectors, causing data races.

Currently, we are using std::random_device in:

We instead need to use the Client local Prng when using std::shuffle as:

Client * client = ...;
std::shuffle(begin, end, client->getPrng().urbg());

With this implementation, we will not worry about thread-safety because the RNG is thread-local.



 Comments   
Comment by Githook User [ 19/Apr/23 ]

Author:

{'name': 'Pol Pinol Castuera', 'email': 'pol.pinol@mongodb.com', 'username': 'PolPinol'}

Message: SERVER-74202 Update balancer to use client local Prng for thread-safe shuffling

(cherry picked from commit 6a90a4d95b2f3c1f2619d332dd9d73fb39fe6167)
Branch: v7.0
https://github.com/mongodb/mongo/commit/69eb1ea37aee4c18edc7324a8f42992fc1f21eb1

Comment by Githook User [ 17/Apr/23 ]

Author:

{'name': 'Pol Pinol Castuera', 'email': 'pol.pinol@mongodb.com', 'username': 'PolPinol'}

Message: SERVER-74202 Update balancer to use client local Prng for thread-safe shuffling
Branch: master
https://github.com/mongodb/mongo/commit/6a90a4d95b2f3c1f2619d332dd9d73fb39fe6167

Generated at Thu Feb 08 06:26:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.