1
// Test killop applied to m/r operations and child ops of m/r operations.
3
t = db.jstests_mr_killop;
5
t2 = db.jstests_mr_killop_out;
12
/** @return op code for map reduce op created by spawned shell, or that op's child */
13
function op( childLoop ) {
14
p = db.currentOp().inprog;
18
// Identify a map/reduce or where distinct operation by its collection, whether or not
19
// it is currently active.
21
if ( ( o.active || o.waitingForLock ) &&
24
o.query.query.$where &&
25
o.query.distinct == "jstests_mr_killop" ) {
30
if ( ( o.active || o.waitingForLock ) &&
33
o.query.mapreduce == "jstests_mr_killop" ) {
42
* Run one map reduce with the specified parameters in a parallel shell, kill the
43
* map reduce op or its child op with killOp, and wait for the map reduce op to
45
* @param childLoop - if true, a distinct $where op is killed rather than the map reduce op.
46
* This is necessay for a child distinct $where of a map reduce op because child
47
* ops currently mask parent ops in currentOp.
49
function testOne( map, reduce, finalize, scope, childLoop, wait ) {
52
// Ensure we have 2 documents for the reduce to run
58
mapreduce:"jstests_mr_killop",
59
out:"jstests_mr_killop_out",
64
spec[ "finalize" ] = finalize;
67
spec[ "scope" ] = scope;
70
// Windows shell strips all double quotes from command line, so use
72
stringifiedSpec = tojson( spec ).toString().replace( /\n/g, ' ' ).replace( /\"/g, "\'" );
74
// The assert below won't be caught by this test script, but it will cause error messages
76
s = startParallelShell( "assert.commandWorked( db.runCommand( " + stringifiedSpec + " ) );" );
83
assert.soon( function() { o = op( childLoop ); return o != -1 } );
86
debug( "did kill : " + tojson( res ) );
88
// When the map reduce op is killed, the spawned shell will exit
90
debug( "parallel shell completed" );
92
assert.eq( -1, op( childLoop ) );
95
/** Test using wait and non wait modes */
96
function test( map, reduce, finalize, scope, childLoop ) {
97
testOne( map, reduce, finalize, scope, childLoop, false );
98
testOne( map, reduce, finalize, scope, childLoop, true );
101
/** Test looping in map and reduce functions */
102
function runMRTests( loop, childLoop ) {
103
test( loop, function( k, v ) { return v[ 0 ]; }, null, null, childLoop );
104
test( function() { emit( this.a, 1 ); }, loop, null, null, childLoop );
105
test( function() { loop(); }, function( k, v ) { return v[ 0 ] },
106
null, { loop: loop }, childLoop );
109
/** Test looping in finalize function */
110
function runFinalizeTests( loop, childLoop ) {
111
test( function() { emit( this.a, 1 ); }, function( k, v ) { return v[ 0 ] },
112
loop, null, childLoop );
113
test( function() { emit( this.a, 1 ); }, function( k, v ) { return v[ 0 ] },
114
function( a, b ) { loop() }, { loop: loop }, childLoop );
117
var loop = function() {
122
runMRTests( loop, false );
123
runFinalizeTests( loop, false );