2012-05-18 09:18:41 -04:00
|
|
|
|
|
|
|
|
// test for SERVER-5040 - if documents move forward during an initial sync.
|
2012-05-18 10:33:40 -04:00
|
|
|
|
2012-05-18 09:18:41 -04:00
|
|
|
var rt = new ReplSetTest( { name : "replset7tests" , nodes: 1 } );
|
|
|
|
|
|
|
|
|
|
var nodes = rt.startSet();
|
|
|
|
|
rt.initiate();
|
2015-11-25 11:20:43 -05:00
|
|
|
var master = rt.getPrimary();
|
2012-05-18 09:18:41 -04:00
|
|
|
|
|
|
|
|
var md = master.getDB( 'd' );
|
|
|
|
|
var mdc = md[ 'c' ];
|
|
|
|
|
|
|
|
|
|
// prep the data
|
2014-03-03 11:27:18 -05:00
|
|
|
var doccount = 5000;
|
|
|
|
|
var bulk = mdc.initializeUnorderedBulkOp();
|
2012-05-18 09:18:41 -04:00
|
|
|
for( i = 0; i < doccount; ++i ) {
|
2014-03-03 11:27:18 -05:00
|
|
|
bulk.insert( { _id:i, x:i } );
|
2012-05-18 09:18:41 -04:00
|
|
|
}
|
2014-03-03 11:27:18 -05:00
|
|
|
assert.writeOK(bulk.execute());
|
2012-05-18 09:18:41 -04:00
|
|
|
|
2014-03-14 15:21:49 -04:00
|
|
|
assert.commandWorked(mdc.ensureIndex( { x : 1 }, { unique: true } ));
|
2012-05-18 09:18:41 -04:00
|
|
|
|
|
|
|
|
// add a secondary
|
|
|
|
|
var slave = rt.add();
|
|
|
|
|
rt.reInitiate();
|
|
|
|
|
print ("initiation complete!");
|
|
|
|
|
var sc = slave.getDB( 'd' )[ 'c' ];
|
|
|
|
|
slave.setSlaveOk();
|
|
|
|
|
|
|
|
|
|
// Wait for slave to start cloning.
|
|
|
|
|
//assert.soon( function() { c = sc.find( { _id:1, x:1 } ); print( c ); return c > 0; } );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Move all documents to the end by growing it
|
2014-03-03 11:27:18 -05:00
|
|
|
bulk = mdc.initializeUnorderedBulkOp();
|
|
|
|
|
var bigStr = "ayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayayay" +
|
|
|
|
|
"ayayayayayayayayayayayay";
|
2012-05-18 09:18:41 -04:00
|
|
|
for (i = 0; i < doccount; ++i) {
|
2014-03-03 11:27:18 -05:00
|
|
|
bulk.find({ _id: i, x: i }).remove();
|
|
|
|
|
bulk.insert({ _id: doccount + i, x: i, bigstring: bigStr });
|
2012-05-18 09:18:41 -04:00
|
|
|
}
|
2014-03-03 11:27:18 -05:00
|
|
|
assert.writeOK(bulk.execute());
|
2012-05-18 09:18:41 -04:00
|
|
|
|
|
|
|
|
// Wait for replication to catch up.
|
|
|
|
|
rt.awaitSecondaryNodes();
|
|
|
|
|
|
|
|
|
|
// Do we have an index?
|
2014-10-06 14:37:07 -04:00
|
|
|
assert.eq(1, slave.getDB( 'd' )['c'].getIndexes().filter(function (doc) {
|
|
|
|
|
return (doc.v === 1
|
|
|
|
|
&& JSON.stringify(doc.key) === JSON.stringify({x: 1})
|
|
|
|
|
&& doc.ns === 'd.c'
|
|
|
|
|
&& doc.name === 'x_1');
|
|
|
|
|
}).length);
|