File: mr_drop.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (38 lines) | stat: -rw-r--r-- 1,395 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Drop a collection while a map/reduce job is running against it.  SERVER-6757

t = db.jstests_mr_drop;
t.drop();

Random.setRandomSeed();

// Set sleep times for different stages of the map/reduce job.  The collection drop will occur
// during different stages of map/reduce depending on these sleep values.
mapSleep = Random.randInt( 4 );
reduceSleep = Random.randInt( 4 );
finalizeSleep = Random.randInt( 4 );

// Insert some documents.
for( i = 0; i < 1000; ++i ) {
    t.save( { key:parseInt( i / 2 ),
              mapSleep:mapSleep,
              reduceSleep:reduceSleep,
              finalizeSleep:finalizeSleep } );
}
db.getLastError();

// Schedule a collection drop one second in the future.
s = startParallelShell( "sleep( 1000 ); db.jstests_mr_drop.drop();" );

// Run the map/reduce job.  Check for command failure internally.  The job succeeds even if the
// source collection is dropped in progress.
t.mapReduce( function() { sleep( this.mapSleep ); emit( this.key, this ); },
             function( key, vals ) { sleep( vals[ 0 ].reduceSleep ); return vals[ 0 ]; },
             { finalize:function( key, value ) { sleep( value.finalizeSleep ); return value; },
               out:'jstests_mr_drop_out' }
           );

// Wait for the parallel shell to finish.
s();

// Ensure the server is still alive.  Under SERVER-6757 the server can crash.
assert( !db.getLastError() );