[SERVER-63328] Relax checks for write lock to support spilling to temp WT record store on secondaries Created: 05/Feb/22  Updated: 29/Oct/23  Resolved: 17/Feb/22

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

Type: Bug Priority: Major - P3
Reporter: Ian Boros Assignee: Eric Cox (Inactive)
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.2
Sprint: QE 2022-02-21
Participants:
Case:

 Description   

Repro:

(function() {
    "use strict";
 
    const replTest = new ReplSetTest({
        nodes: 3,
    });
 
    replTest.startSet();
    replTest.initiate();
 
    let primary = replTest.getPrimary();
    const insertColl = primary.getDB("test").foo;
    for (let i = 0; i < 500; ++i) {
        insertColl.insert({a: i, string: "test test test"});
    }
 
    let secondary = replTest.getSecondary();
    secondary.adminCommand({setParameter: 1, internalQuerySlotBasedExecutionHashAggApproxMemoryUseInBytesBeforeSpill: 1});
 
    let readColl = secondary.getDB("test").foo;
 
    const pipeline = [{$group: {_id: '$a', s: {$addToSet: '$string'}, p: {$push: '$a'}}}];
    
    let res = readColl.aggregate(pipeline, {allowDiskUse: true,
                                            readConcern: {level: "majority"},
                                            writeConcern:{"w": "majority"}
                                           }).toArray();
 
    // Never reached.
    replTest.stopSet();
})();

In the SBE HashAgg stage, we take a global IX lock before spilling to disk.

This will cause the wasGlobalLockTakenForWrite() function to return true at the end of command processing, and we will end up calling waitForWriteConcern here, even if the operation only wrote to a local temporary RecordStore for spilling.

As Max H as pointed out, the SpillableCache used in window functions likely suffers the same issue, since it also takes an IX lock here.

The user facing impact of this is that $group queries which spill, when run on secondaries with a writeConcern stronger than w:1 are broken.



 Comments   
Comment by Githook User [ 17/Feb/22 ]

Author:

{'name': 'Eric Cox', 'email': 'eric.cox@mongodb.com', 'username': 'ericox'}

Message: SERVER-63328 Relax checks for write lock to support spilling to temp WT record store on secondaries

(cherry picked from commit 69f2f33c4c9edcceb013e16e6b6d737a20b481b3)
Branch: v5.2
https://github.com/mongodb/mongo/commit/51388df36fed035ccee7733b82ca46c390612b14

Comment by Githook User [ 16/Feb/22 ]

Author:

{'name': 'Eric Cox', 'email': 'eric.cox@mongodb.com', 'username': 'ericox'}

Message: SERVER-63328 Relax checks for write lock to support spilling to temp WT record store on secondaries
Branch: master
https://github.com/mongodb/mongo/commit/69f2f33c4c9edcceb013e16e6b6d737a20b481b3

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