[SERVER-72351] Sidewrites can lead to CSI corruption Created: 21/Dec/22  Updated: 29/Oct/23  Resolved: 05/Jan/23

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

Type: Bug Priority: Major - P3
Reporter: Colin Stolley Assignee: Justin Seyster
Resolution: Fixed Votes: 0
Labels: pm2646-m4
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QE 2023-01-09
Participants:

 Description   

We have a different code path for handling writes while a column index is being created, and it's called a side-write. Unfortunately, there's a bug and it can break CSI consistency. Here is the reproduction on master:

 

coll = db.coll;
coll.insert({foo:1});
db.adminCommand({configureFailPoint: 'hangAfterStartingIndexBuild', mode: 'alwaysOn'});
coll.createIndex({"$**": "columnstore"});

With that console hanging, do this:

coll = db.coll;
coll.insert({cow: 1, pig: 2});
coll.update({cow:1}, {cow: 2});
db.adminCommand({configureFailPoint: 'hangAfterStartingIndexBuild', mode: 'off'});

Now run:

MongoDB Enterprise > coll.find({cow:2}, {cow:1});
{ "_id" : ObjectId("63a37e9ed5c25556348142f3"), "cow" : 2 }
MongoDB Enterprise > coll.find({cow:2}, {cow:1}).hint({"$**": "columnstore"});
MongoDB Enterprise >

 

It appears that the delete portion of the update access method is removing keys it shouldn't. See: https://github.com/10gen/mongo/blob/ebbb36a531d6a137d817c4f833050da3964411dd/src/mongo/db/index/columns_access_method.cpp#L378-L389

columnKeys appears to be picking up entries from both the delete and the update diffActions, and so when we run the delete for `pig` above, cow gets wiped out with it. I think you could move columnKeys https://github.com/10gen/mongo/blob/ebbb36a531d6a137d817c4f833050da3964411dd/src/mongo/db/index/columns_access_method.cpp#L371 into the lambda scope to prevent this from happening, but I haven't thought it through.



 Comments   
Comment by Githook User [ 05/Jan/23 ]

Author:

{'name': 'Justin Seyster', 'email': 'justin.seyster@mongodb.com', 'username': 'jseyster'}

Message: SERVER-72351 Fix incorrect generation of side writes for update operations
Branch: master
https://github.com/mongodb/mongo/commit/1b25fdd03663d50f7fe4f1f1c94f6e0ee3c2dc73

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