2012-07-10 13:51:19 -04:00
|
|
|
|
|
|
|
|
// test for SERVER-6303 - if documents move backward during an initial sync.
|
|
|
|
|
|
|
|
|
|
var rt = new ReplSetTest( { name : "replset8tests" , nodes: 1 } );
|
|
|
|
|
|
|
|
|
|
var nodes = rt.startSet();
|
|
|
|
|
rt.initiate();
|
2015-11-25 11:20:43 -05:00
|
|
|
var master = rt.getPrimary();
|
2012-07-10 13:51:19 -04:00
|
|
|
var bigstring = "a";
|
|
|
|
|
var md = master.getDB( 'd' );
|
|
|
|
|
var mdc = md[ 'c' ];
|
|
|
|
|
|
|
|
|
|
// prep the data
|
|
|
|
|
|
|
|
|
|
// idea: create x documents of increasing size, then create x documents of size n.
|
|
|
|
|
// delete first x documents. start initial sync (cloner). update all remaining
|
|
|
|
|
// documents to be increasing size.
|
|
|
|
|
// this should result in the updates moving the docs backwards.
|
|
|
|
|
|
2014-03-03 11:27:18 -05:00
|
|
|
var doccount = 5000;
|
2012-07-10 13:51:19 -04:00
|
|
|
// Avoid empty extent issues
|
|
|
|
|
mdc.insert( { _id:-1, x:"dummy" } );
|
|
|
|
|
|
|
|
|
|
print ("inserting bigstrings");
|
2014-03-03 11:27:18 -05:00
|
|
|
var bulk = mdc.initializeUnorderedBulkOp();
|
2012-07-10 13:51:19 -04:00
|
|
|
for( i = 0; i < doccount; ++i ) {
|
2014-03-03 11:27:18 -05:00
|
|
|
bulk.insert( { _id:i, x:bigstring } );
|
2012-07-10 13:51:19 -04:00
|
|
|
bigstring += "a";
|
|
|
|
|
}
|
2014-03-03 11:27:18 -05:00
|
|
|
assert.writeOK(bulk.execute());
|
2012-07-10 13:51:19 -04:00
|
|
|
|
|
|
|
|
print ("inserting x");
|
2014-03-03 11:27:18 -05:00
|
|
|
bulk = mdc.initializeUnorderedBulkOp();
|
2012-07-10 13:51:19 -04:00
|
|
|
for( i = doccount; i < doccount*2; ++i ) {
|
2014-03-03 11:27:18 -05:00
|
|
|
bulk.insert( { _id:i, x:i } );
|
2012-07-10 13:51:19 -04:00
|
|
|
}
|
2014-03-03 11:27:18 -05:00
|
|
|
assert.writeOK(bulk.execute());
|
2012-07-10 13:51:19 -04:00
|
|
|
|
|
|
|
|
print ("deleting bigstrings");
|
2014-03-03 11:27:18 -05:00
|
|
|
bulk = mdc.initializeUnorderedBulkOp();
|
2012-07-10 13:51:19 -04:00
|
|
|
for( i = 0; i < doccount; ++i ) {
|
2014-03-03 11:27:18 -05:00
|
|
|
bulk.find({ _id: i }).remove();
|
2012-07-10 13:51:19 -04:00
|
|
|
}
|
2014-03-03 11:27:18 -05:00
|
|
|
assert.writeOK(bulk.execute());
|
2012-07-10 13:51:19 -04:00
|
|
|
|
|
|
|
|
// add a secondary
|
|
|
|
|
var slave = rt.add();
|
|
|
|
|
rt.reInitiate();
|
|
|
|
|
print ("initiation complete!");
|
|
|
|
|
var sc = slave.getDB( 'd' )[ 'c' ];
|
|
|
|
|
slave.setSlaveOk();
|
|
|
|
|
sleep(25000);
|
|
|
|
|
print ("updating documents backwards");
|
|
|
|
|
// Move all documents to the beginning by growing them to sizes that should
|
|
|
|
|
// fit the holes we made in phase 1
|
2014-03-03 11:27:18 -05:00
|
|
|
bulk = mdc.initializeUnorderedBulkOp();
|
2012-07-10 13:51:19 -04:00
|
|
|
for (i = doccount*2; i > doccount; --i) {
|
|
|
|
|
mdc.update( { _id:i, x:i }, { _id:i, x:bigstring } );
|
|
|
|
|
bigstring = bigstring.slice(0, -1); // remove last char
|
|
|
|
|
}
|
|
|
|
|
print ("finished");
|
|
|
|
|
// Wait for replication to catch up.
|
|
|
|
|
rt.awaitSecondaryNodes();
|
|
|
|
|
assert.eq(doccount+1, slave.getDB( 'd' )['c'].count());
|