Files
mongo/jstests/repl/repl13.js

58 lines
1.9 KiB
JavaScript
Raw Normal View History

2012-01-25 20:55:25 -08:00
// Test update modifier uassert during initial sync. SERVER-4781
2012-04-24 13:36:16 -07:00
function debug( x ) {
2012-04-24 17:29:29 -07:00
if ( debuggingEnabled = false ) {
2012-04-24 13:36:16 -07:00
printjson( x );
}
}
2012-01-25 20:55:25 -08:00
rt = new ReplTest( "repl13tests" );
m = rt.start( true );
mc = m.getDB( 'd' )[ 'c' ];
2012-04-24 13:36:16 -07:00
// Insert some documents with a:{} fields.
var bulk = mc.initializeUnorderedBulkOp();
for(var i = 0; i < 100000; ++i) {
bulk.insert({ _id: i, a: {}});
2012-01-25 20:55:25 -08:00
}
assert.writeOK(bulk.execute());
2012-01-25 20:55:25 -08:00
s = rt.start( false );
sc = s.getDB( 'd' )[ 'c' ];
2012-04-24 13:36:16 -07:00
// Wait for the initial clone to begin.
assert.soon( function() { debug( sc.count() ); return sc.count() > 0; } );
2012-01-25 20:55:25 -08:00
2012-04-24 13:36:16 -07:00
// Update documents that will be cloned last with the intent that an updated version will be cloned.
// This may cause an assertion when an update that was successfully applied to the original version
// of a document is replayed against an updated version of the same document.
bulk = mc.initializeUnorderedBulkOp();
2012-01-25 20:55:25 -08:00
for( i = 99999; i >= 90000; --i ) {
// If the document is cloned as {a:1}, the {$set:{'a.b':1}} modifier will uassert.
bulk.find({ _id: i }).update({ $set: { 'a.b': 1 }});
bulk.find({ _id: i }).update({ $set: { a: 1 }});
2012-01-25 20:55:25 -08:00
}
assert.writeOK(bulk.execute());
2012-01-25 20:55:25 -08:00
2012-04-24 13:36:16 -07:00
// The initial sync completes and subsequent writes succeed, in spite of any assertions that occur
// when the update operations above are replicated.
mc.save( {} );
assert.eq( 100001 , mc.count() );
2012-01-25 20:55:25 -08:00
assert.soon( function() { return sc.count() == 100001; } );
2012-04-24 13:36:16 -07:00
mc.save( {} );
assert.eq( 100002 , mc.count() );
2012-04-24 13:36:16 -07:00
assert.soon( function() { return sc.count() == 100002; } );
debug( sc.findOne( {_id:99999} ) );
debug( sc.findOne( {_id:90000} ) );
2012-01-25 20:55:25 -08:00
2012-04-24 13:36:16 -07:00
assert.eq( 1, sc.findOne( {_id:99999} ).a );
assert.eq( 1, sc.findOne( {_id:90000} ).a );
m_hash = m.getDB( "d" ).runCommand( "dbhash" );
s_hash = s.getDB( "d" ).runCommand( "dbhash" );
assert.eq( m_hash.collections.c , s_hash.collections.c , "sad " + tojson( m_hash ) + " " + tojson( s_hash ) );