Details
Description
The KeepMutationsNode query solution node is added to the incorrect place in the query solution tree for "split limited sort" plans (which are generated when a sort and a positive ntoreturn are specified). As a consequence, if the documents to be returned are concurrently updated, the KeepMutationsStage can inject these documents into the result stream out of order.
Affects versions released since 2.5.5.
Reproduce with the following:
db.foo.drop();
|
for (var i = 0; i < 6; ++i) { |
db.foo.insert({a: 1, b: i, c: 1});
|
}
|
assert.commandWorked(db.adminCommand({setParameter: 1, internalQueryExecYieldIterations: 1}));
|
db.foo.ensureIndex({a: 1});
|
startParallelShell("for (;;) { db.foo.update({}, {$inc: {c: 1}}, {multi: true}); }"); |
for (;;) { |
var results = db.foo.find({a: 1}).sort({b: 1}).batchSize(2).toArray(); |
var resultsSorted = results.concat().sort(function(lhs, rhs) { return lhs.b - rhs.b; }); |
assert.eq(results, resultsSorted);
|
}
|
Output generated:
assert: [[
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe04948f"),
|
"a" : 1,
|
"b" : 0,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049490"),
|
"a" : 1,
|
"b" : 1,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe04948f"),
|
"a" : 1,
|
"b" : 0,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049490"),
|
"a" : 1,
|
"b" : 1,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049491"),
|
"a" : 1,
|
"b" : 2,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049492"),
|
"a" : 1,
|
"b" : 3,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049493"),
|
"a" : 1,
|
"b" : 4,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049494"),
|
"a" : 1,
|
"b" : 5,
|
"c" : 3
|
}
|
]] != [[
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe04948f"),
|
"a" : 1,
|
"b" : 0,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe04948f"),
|
"a" : 1,
|
"b" : 0,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049490"),
|
"a" : 1,
|
"b" : 1,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049490"),
|
"a" : 1,
|
"b" : 1,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049491"),
|
"a" : 1,
|
"b" : 2,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049492"),
|
"a" : 1,
|
"b" : 3,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049493"),
|
"a" : 1,
|
"b" : 4,
|
"c" : 3
|
},
|
{
|
"_id" : ObjectId("55d2789ecce4f5bfbe049494"),
|
"a" : 1,
|
"b" : 5,
|
"c" : 3
|
}
|
]] are not equal : undefined
|
Attachments
Issue Links
- related to
-
SERVER-17011 Cursor can return objects out of order if updated during query ("legacy" readMode only)
-
- Closed
-