2012-04-24 11:22:23 -07:00
|
|
|
// Sanity test for removing documents with adjacent index keys. SERVER-2008
|
2011-03-24 23:42:56 -07:00
|
|
|
|
2012-04-24 11:37:32 -07:00
|
|
|
t = db.jstests_removec;
|
2011-03-24 23:42:56 -07:00
|
|
|
t.drop();
|
2016-03-09 12:17:50 -05:00
|
|
|
t.ensureIndex({a: 1});
|
2011-03-24 23:42:56 -07:00
|
|
|
|
2012-04-24 11:22:23 -07:00
|
|
|
/** @return an array containing a sequence of numbers from i to i + 10. */
|
2016-03-09 12:17:50 -05:00
|
|
|
function runStartingWith(i) {
|
2011-03-24 23:42:56 -07:00
|
|
|
ret = [];
|
2016-03-09 12:17:50 -05:00
|
|
|
for (j = 0; j < 11; ++j) {
|
|
|
|
|
ret.push(i + j);
|
2011-03-24 23:42:56 -07:00
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 11:22:23 -07:00
|
|
|
// Insert some documents with adjacent index keys.
|
2016-03-09 12:17:50 -05:00
|
|
|
for (i = 0; i < 1100; i += 11) {
|
|
|
|
|
t.save({a: runStartingWith(i)});
|
2011-03-24 23:42:56 -07:00
|
|
|
}
|
|
|
|
|
|
2012-04-24 11:22:23 -07:00
|
|
|
// Remove and then reinsert random documents in the background.
|
2016-03-09 12:17:50 -05:00
|
|
|
s = startParallelShell('t = db.jstests_removec;' +
|
2015-12-31 10:20:46 -05:00
|
|
|
'Random.setRandomSeed();' +
|
2012-04-24 11:22:23 -07:00
|
|
|
'for( j = 0; j < 1000; ++j ) {' +
|
|
|
|
|
' o = t.findOne( { a:Random.randInt( 1100 ) } );' +
|
|
|
|
|
' t.remove( { _id:o._id } );' +
|
|
|
|
|
' t.insert( o );' +
|
2016-03-09 12:17:50 -05:00
|
|
|
'}');
|
2011-03-24 23:42:56 -07:00
|
|
|
|
2014-02-14 13:41:31 -05:00
|
|
|
// Find operations are error free. Note that the cursor throws if it detects the $err
|
|
|
|
|
// field in the returned document.
|
2016-03-09 12:17:50 -05:00
|
|
|
for (i = 0; i < 200; ++i) {
|
|
|
|
|
t.find({a: {$gte: 0}}).hint({a: 1}).itcount();
|
2011-03-24 23:42:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s();
|
2012-04-24 11:37:32 -07:00
|
|
|
|
|
|
|
|
t.drop();
|