[SERVER-70944] Make accessing hashes stored in FieldPath thread-safe Created: 28/Oct/22  Updated: 29/Oct/23  Resolved: 02/Nov/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.2.0-rc0

Type: Bug Priority: Major - P3
Reporter: Irina Yatsenko (Inactive) Assignee: Irina Yatsenko (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QE 2022-10-31, QE 2022-11-14
Participants:
Linked BF Score: 23

 Description   

TSAN found a data race accessing lazily computed FieldPath::_fieldHash (see BF-26622) during updates that might share collection validators.



 Comments   
Comment by Githook User [ 02/Nov/22 ]

Author:

{'name': 'Irina Yatsenko', 'email': 'irina.yatsenko@mongodb.com', 'username': 'IrinaYatsenko'}

Message: SERVER-70944 precompute field hashes for ExpressionFieldPath
Branch: master
https://github.com/mongodb/mongo/commit/188f24f0d61b62b9b0601f5b890b4820d7570719

Comment by Irina Yatsenko (Inactive) [ 28/Oct/22 ]

From https://evergreen.mongodb.com/lobster/build/0757e0fda7d613ecfb1170091b7b1cde/test/171d4eff24b557aef966b73f019c5c29#bookmarks=0%2C1299%2C2698&l=1

 

T40 (conn7)

Executed first and installed a validator for the collection with something like:

db.runCommand({collMod: "ff", validator: {$expr: {$gt: ["$stars", 0]}}})

(the actual command in the test has a more complicated expression)

 

abridged stack:

mongo::FieldPath::FieldPath

mongo::ExpressionFieldPath::ExpressionFieldPath

mongo::ExpressionFieldPath::parse

mongo::ExprMatchExpression::ExprMatchExpression

mongo::MatchExpressionParser::parse

mongo::CollectionImpl::parseValidator

mongo::processCollModCommand

 

After the validator is installed into the collection, it's shared across client connections, so updates from different threads access the same FieldPath object when checking the schema.

T69 (conn 35) / T67 (conn33)

UpdateStage::doWork -> … -> ExpressionFieldPath::evaluatePath - accesses the hash and might lazily compute it, thus creating the race between readers/writers

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