[SERVER-16469] findAndModify with sort exceeds internal sort memory limit, silently fails Created: 09/Dec/14  Updated: 18/Dec/14  Resolved: 09/Dec/14

Status: Closed
Project: Core Server
Component/s: Concurrency
Affects Version/s: None
Fix Version/s: 2.8.0-rc3

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: J Rassi
Resolution: Done Votes: 0
Labels: 28qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-15715 find_and_modify appears to be taking ... Closed
is related to SERVER-16063 Rewrite findAndModify Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Start up a mongod (with mmapv1 or wiredtiger) and run the following script:

function insert() {
    // Use 32-bit integer for representing 'length' property
    var doc = { tid: 0, length: new NumberInt(2 * 1024 * 1024 /* 2MB */) };
    doc.field = new Array(doc.length + 1).join('x');
 
    var res = db.foo.insert(doc);
    assert.writeOK(res);
    assert.eq(1, res.nInserted);
}
 
function findAndModify() {
    var res = db.runCommand({
        findandmodify: db.foo.getName(),
        query: { tid: 0 },
        sort: { length: 1 }, // NOTE: this seems necessary for the repro
        update: { $mul: { length: 1 } },
        new: true
    });
    assert.commandWorked(res);
 
    var doc = res.value;
    assert(doc !== null, 'query spec should have matched a document');
}
 
db.foo.drop();
while (true) {
    insert();
    findAndModify();
}

Participants:

 Description   

When performing insert operations between findAndModify commands, a findAndModify will eventually fail to find a document to update, even though the query predicate remains the same. This failure only seems to occur when a sort specification is supplied.


git version
a6788ec72a9dabb38bd92a8ab653e32034e9e02e



 Comments   
Comment by J Rassi [ 09/Dec/14 ]

max.hirschhorn@10gen.com (and company): great find.

Comment by Githook User [ 09/Dec/14 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-16469 findAndModify runImpl(): set limit of -1 on query

This allows findAndModify operations that include a sort to take
advantage of the top-K sort logic in the query engine. This reduces
the memory footprint of the operation from O(N) to O(1), where N is
the number of documents matching the query predicate.
Branch: master
https://github.com/mongodb/mongo/commit/604fc8c629b4cd90a3fbd84e53eb4c892878a318

Comment by Githook User [ 09/Dec/14 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-16469 findAndModify runImpl(): improve error reporting

Previously, findAndModify ignored errors encountered in calls to
PlanExecutor::getNext() when searching for the document to modify.
Now, errors are bubbled up to the user.
Branch: master
https://github.com/mongodb/mongo/commit/efe368fa7a6b4c1ca6077fdb2560a33dfdc82337

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