1
// Drop a collection while a map/reduce job is running against it. SERVER-6757
3
t = db.jstests_mr_drop;
6
Random.setRandomSeed();
8
// Set sleep times for different stages of the map/reduce job. The collection drop will occur
9
// during different stages of map/reduce depending on these sleep values.
10
mapSleep = Random.randInt( 4 );
11
reduceSleep = Random.randInt( 4 );
12
finalizeSleep = Random.randInt( 4 );
14
// Insert some documents.
15
for( i = 0; i < 1000; ++i ) {
16
t.save( { key:parseInt( i / 2 ),
18
reduceSleep:reduceSleep,
19
finalizeSleep:finalizeSleep } );
23
// Schedule a collection drop one second in the future.
24
s = startParallelShell( "sleep( 1000 ); db.jstests_mr_drop.drop();" );
26
// Run the map/reduce job. Check for command failure internally. The job succeeds even if the
27
// source collection is dropped in progress.
28
t.mapReduce( function() { sleep( this.mapSleep ); emit( this.key, this ); },
29
function( key, vals ) { sleep( vals[ 0 ].reduceSleep ); return vals[ 0 ]; },
30
{ finalize:function( key, value ) { sleep( value.finalizeSleep ); return value; },
31
out:'jstests_mr_drop_out' }
34
// Wait for the parallel shell to finish.
37
// Ensure the server is still alive. Under SERVER-6757 the server can crash.
38
assert( !db.getLastError() );