2012-01-25 20:55:25 -08:00
|
|
|
// Test update modifier uassert during initial sync. SERVER-4781
|
|
|
|
|
|
|
|
|
|
load("jstests/replsets/rslib.js");
|
|
|
|
|
basename = "jstests_initsync4";
|
|
|
|
|
|
|
|
|
|
print("1. Bring up set");
|
|
|
|
|
replTest = new ReplSetTest( {name: basename, nodes: 1} );
|
|
|
|
|
replTest.startSet();
|
|
|
|
|
replTest.initiate();
|
|
|
|
|
|
2015-11-25 11:20:43 -05:00
|
|
|
m = replTest.getPrimary();
|
2012-01-25 20:55:25 -08:00
|
|
|
md = m.getDB("d");
|
|
|
|
|
mc = m.getDB("d")["c"];
|
|
|
|
|
|
|
|
|
|
print("2. Insert some data");
|
2014-03-03 11:27:18 -05:00
|
|
|
N = 5000;
|
|
|
|
|
mc.ensureIndex({x:1});
|
|
|
|
|
var bulk = mc.initializeUnorderedBulkOp();
|
2012-01-25 20:55:25 -08:00
|
|
|
for( i = 0; i < N; ++i ) {
|
2014-03-03 11:27:18 -05:00
|
|
|
bulk.insert({ _id: i, x: i, a: {} });
|
2012-01-25 20:55:25 -08:00
|
|
|
}
|
2014-03-03 11:27:18 -05:00
|
|
|
assert.writeOK(bulk.execute());
|
2012-01-25 20:55:25 -08:00
|
|
|
|
|
|
|
|
print("3. Make sure synced");
|
|
|
|
|
replTest.awaitReplication();
|
|
|
|
|
|
|
|
|
|
print("4. Bring up a new node");
|
|
|
|
|
hostname = getHostName();
|
|
|
|
|
|
2015-03-22 12:08:21 -04:00
|
|
|
s = MongoRunner.runMongod({replSet: basename, oplogSize: 2});
|
2012-01-25 20:55:25 -08:00
|
|
|
|
|
|
|
|
var config = replTest.getReplSetConfig();
|
|
|
|
|
config.version = 2;
|
2015-03-22 12:08:21 -04:00
|
|
|
config.members.push({_id:2, host:hostname+":"+s.port});
|
2012-01-25 20:55:25 -08:00
|
|
|
try {
|
|
|
|
|
m.getDB("admin").runCommand({replSetReconfig:config});
|
|
|
|
|
}
|
|
|
|
|
catch(e) {
|
|
|
|
|
print(e);
|
|
|
|
|
}
|
|
|
|
|
reconnect(s);
|
|
|
|
|
|
|
|
|
|
print("5. Wait for new node to start cloning");
|
|
|
|
|
|
|
|
|
|
s.setSlaveOk();
|
|
|
|
|
sc = s.getDB("d")["c"];
|
|
|
|
|
|
|
|
|
|
wait( function() { printjson( sc.stats() ); return sc.stats().count > 0; } );
|
|
|
|
|
|
|
|
|
|
print("6. Start updating documents on primary");
|
|
|
|
|
for( i = N-1; i >= N-10000; --i ) {
|
|
|
|
|
// If the document is cloned as {a:1}, the {$set:{'a.b':1}} modifier will uassert.
|
|
|
|
|
mc.update( {_id:i}, {$set:{'a.b':1}} );
|
|
|
|
|
mc.update( {_id:i}, {$set:{a:1}} );
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-05 12:24:31 -04:00
|
|
|
for ( i = N; i < N*2; i++ ) {
|
|
|
|
|
mc.insert( { _id : i, x : i } )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert.eq( N*2, mc.count() );
|
|
|
|
|
|
2012-01-25 20:55:25 -08:00
|
|
|
print("7. Wait for new node to become SECONDARY");
|
|
|
|
|
wait(function() {
|
|
|
|
|
var status = s.getDB("admin").runCommand({replSetGetStatus:1});
|
|
|
|
|
printjson(status);
|
|
|
|
|
return status.members &&
|
|
|
|
|
(status.members[1].state == 2);
|
|
|
|
|
});
|
2012-02-05 21:44:04 -08:00
|
|
|
|
2013-04-05 12:24:31 -04:00
|
|
|
print("8. Wait for new node to have all the data")
|
|
|
|
|
wait(function() {
|
|
|
|
|
return sc.count() == mc.count();
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert.eq( mc.getIndexKeys().length,
|
|
|
|
|
sc.getIndexKeys().length );
|
|
|
|
|
|
|
|
|
|
assert.eq( mc.find().sort( { x : 1 } ).itcount(),
|
|
|
|
|
sc.find().sort( { x : 1 } ).itcount() );
|
|
|
|
|
|
|
|
|
|
replTest.stopSet( 15 );
|