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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
load( "jstests/libs/slow_weekly_util.js" )
testServer = new SlowWeeklyMongod( "update_yield1" )
db = testServer.getDB( "test" );
t = db.update_yield1;
t.drop()
N = 10000;
i = 0;
while ( true ){
function fill(){
for ( ; i<N; i++ ){
t.insert( { _id : i , n : 1 } )
}
}
function timeUpdate(){
return Date.timeFunc(
function(){
t.update( {} , { $inc : { n : 1 } } , false , true );
var r = db.getLastErrorObj();
}
);
}
fill();
timeUpdate();
timeUpdate();
time = timeUpdate();
print( N + "\t" + time );
if ( time > 8000 )
break;
N *= 2;
}
// --- test 1
join = startParallelShell( "db.update_yield1.update( {} , { $inc : { n : 1 } } , false , true ); db.getLastError()" );
assert.soon(
function(){
return db.currentOp().inprog.length > 0;
} , "never doing update"
);
num = 0;
start = new Date();
while ( ( (new Date()).getTime() - start ) < ( time * 2 ) ){
var me = Date.timeFunc( function(){ t.findOne(); } );
if (me > 50) print("time: " + me);
if ( num++ == 0 ){
var x = db.currentOp()
assert.eq( 1 , x.inprog.length , "nothing in prog" );
}
assert.gt( time / 3 , me );
}
join();
var x = db.currentOp()
assert.eq( 0 , x.inprog.length , "weird 2" );
// --- test 2
join = startParallelShell( "db.update_yield1.update( { $atomic : true } , { $inc : { n : 1 } } , false , true ); db.getLastError()" );
sleep(1000); // wait for shell startup ops to finish
var x = db.currentOp();
printjson(x);
assert.eq(1, x.inprog.length, "never doing update 2");
assert.eq("update", x.inprog[0].op);
while ( 1 ) {
t.findOne(); // should wait for update to finish
var x = db.currentOp()
if ( x.inprog.length == 0 )
break;
assert( x.inprog.length == 1 && x.inprog[0].op == "update" , tojson( x ) );
assert( x.inprog[0].numYields == 0 , tojson( x ) );
sleep( 100 );
}
join();
testServer.stop();
|