[SERVER-40854] Hybrid index builds should reposition cursors to the beginning of the side table after yielding Created: 26/Apr/19  Updated: 29/Oct/23  Resolved: 03/May/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 4.1.11

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

Issue Links:
Depends
Related
related to SERVER-40894 Remove unused setGhostCommitTimestamp... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Storage NYC 2019-05-06
Participants:
Linked BF Score: 64

 Description   

During the first drain phase of hybrid index builds, operations are applied in batches from the side table record store into the index. At the end of each batch (1000 operations by default), the side table cursor is saved and restored. This restore may reposition on new records, but not necessarily the newest records. This can cause batch applications after yield to apply causal operations out of order.

For example, imagine two writer threads, A and B, writing into the side table and an index build thread. In this example, thread A inserts then deletes the key {a: 1}. Thread B inserts an unrelated key.

writer A writer B index builder
start_transaction    
RID 1: insert key {a: 1}    
  start_transaction  
  RID 2: insert key {b: 1}  
  commit_transaction  
    Apply side write for RID 2 in a single batch. Save cursor. Commit.
RID 3: delete key {a: 1}    
commit_transaction    
    Reposition cursor on RID 3. Apply side write for RID 3 in a single batch. Save cursor. Commit
    Reposition cursor on RID 1. Apply side write for RID 1 in a single batch. Commit

In this scenario, it is possible to insert the key {a: 1} into the index even after it has been deleted.

The fix for this bug should be to reposition cursors at the beginning of the record store after every yield to guarantee all causally related records are applied in order.



 Comments   
Comment by Githook User [ 03/May/19 ]

Author:

{'email': 'benety@mongodb.com', 'name': 'Benety Goh', 'username': 'benety'}

Message: SERVER-40854 do not delete side table records while we are still have an active record store cursor

Re-enables failing StorageInterfaceImplTest test cases.
Branch: master
https://github.com/mongodb/mongo/commit/087a8d4c6577ad3929487df84dca7a3561da168c

Comment by Benety Goh [ 03/May/19 ]

Re-opening to fix index build interceptor

Comment by Githook User [ 03/May/19 ]

Author:

{'email': 'benety@mongodb.com', 'name': 'Benety Goh', 'username': 'benety'}

Message: SERVER-40854 temporarily disable failing StorageInterfaceImplTest test cases
Branch: master
https://github.com/mongodb/mongo/commit/edcf522c5436f6b564afd18b7d184764741a03a5

Comment by Githook User [ 02/May/19 ]

Author:

{'name': 'Louis Williams', 'username': 'louiswilliams', 'email': 'louis.williams@mongodb.com'}

Message: SERVER-40854 Hybrid index builds should reposition cursors to the beginning of the side table after yielding

This also adds tunable parameters 'maxIndexBuildDrainBatchSize' and
'maxIndexBuildDrainMemoryUsageMegabytes' which control resource usage
during the hyrid index build drain phase.
Branch: master
https://github.com/mongodb/mongo/commit/0ed60576b3a80d3fe233a6a387d976791bb80cea

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