[SERVER-63585] Fastcount gets out of sync when a delete rollbacks and another transaction deletes the same rows Created: 11/Feb/22  Updated: 29/Oct/23  Resolved: 15/Feb/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.3.0, 4.4.18, 5.0.14

Type: Bug Priority: Major - P3
Reporter: Daniel Gomez Ferro Assignee: Daniel Gomez Ferro
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Related
related to SERVER-74103 Increase storage log verbosity in opl... Closed
is related to SERVER-60337 Investigate incorrect fast count in r... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.0, v4.4, v4.2
Sprint: Execution Team 2022-02-21
Participants:
Linked BF Score: 13

 Description   

In the WiredTigerRecordStore we keep track of the number of records we hold. When a transaction rollbacks we patch up the metadata so that eventually it stays in sync with the real number of rows, even though it can get out of sync if there's a crash.

To fix up issues after a crash, we clamp the value to a positive integer however this can cause problems if there are rollbacks:

  • Thread 1 deletes the last row, sets numRecords = 0
  • Thread 1 rollbacks, it rollbacks the WT transaction but hasn't fixed up the metadata yet
  • Thread 2 deletes the last row, numRecords is 0 so it clamps numRecords to 0 and commits.
  • Thread 1 fixes up the metadata by increasing numRecords by the same amount it reduced, numRecords = 1

We should allow negative values of numRecords so that the metadata patching process works correctly.



 Comments   
Comment by Githook User [ 31/Oct/22 ]

Author:

{'name': 'Daniel Gómez Ferro', 'email': 'daniel.gomezferro@mongodb.com', 'username': 'dgomezferro'}

Message: SERVER-63585 Allow negative values in WTRecordStore::numRecords
Branch: v4.4
https://github.com/mongodb/mongo/commit/4884b778c88166a36bf10112f0c6b504db2d6ed7

Comment by Githook User [ 31/Oct/22 ]

Author:

{'name': 'Daniel Gómez Ferro', 'email': 'daniel.gomezferro@mongodb.com', 'username': 'dgomezferro'}

Message: SERVER-63585 Allow negative values in WTRecordStore::numRecords
Branch: v5.0
https://github.com/mongodb/mongo/commit/a58c20209f4b63c4032a4df6caa8df19bd58c22c

Comment by Daniel Gottlieb (Inactive) [ 12/Oct/22 ]

I've requested a backport as I came across a manifestation of this on a recent 5.0 patch run that resulted in some folks thinking they might have broke something.

Comment by Githook User [ 15/Feb/22 ]

Author:

{'name': 'Daniel Gómez Ferro', 'email': 'daniel.gomezferro@mongodb.com', 'username': 'dgomezferro'}

Message: SERVER-63585 Allow negative values in WTRecordStore::numRecords
Branch: master
https://github.com/mongodb/mongo/commit/bbdf42ae03fdab670dbee8d5a154156aae5342a9

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