11// test that the resync command works with replica sets and that one does not need to manually
22// force a replica set resync by deleting all datafiles
3-
4- // TODO: Remove once test is fixed for SERVER-15704, add "use strict"
5- if ( false ) {
3+ // Also tests that you can do this from a node that is "too stale"
4+ ( function ( ) {
5+ "use strict" ;
66 var replTest = new ReplSetTest ( { name : 'resync' , nodes : 3 , oplogSize : 1 } ) ;
77 var nodes = replTest . nodeList ( ) ;
88
@@ -29,17 +29,27 @@ if (false) {
2929
3030 // create an oplog entry with an insert
3131 assert . writeOK ( A . foo . insert ( { x : 1 } , { writeConcern : { w : 3 , wtimeout : 60000 } } ) ) ;
32+ assert . eq ( B . foo . findOne ( ) . x , 1 )
33+
34+ // run resync and wait for it to happen
35+ assert . commandWorked ( b_conn . getDB ( "admin" ) . runCommand ( { resync :1 } ) ) ;
36+ replTest . awaitReplication ( ) ;
37+ replTest . awaitSecondaryNodes ( ) ;
38+
39+ assert . eq ( B . foo . findOne ( ) . x , 1 )
3240 replTest . stop ( BID ) ;
3341
3442 function hasCycled ( ) {
3543 var oplog = a_conn . getDB ( "local" ) . oplog . rs ;
36- return oplog . find ( { "o.x" : 1 } ) . sort ( { $natural : 1 } ) . _addSpecial ( "$maxScan" , 10 ) . itcount ( ) == 0 ;
44+ return oplog . find ( { "o.x" : 1 } ) . sort ( { $natural : 1 } ) . limit ( 10 ) . itcount ( ) == 0 ;
3745 }
3846
47+ // Make sure the oplog has rolled over on the primary and secondary that is up,
48+ // so when we bring up the other replica it is "too stale"
3949 for ( var cycleNumber = 0 ; cycleNumber < 10 ; cycleNumber ++ ) {
4050 // insert enough to cycle oplog
4151 var bulk = A . foo . initializeUnorderedBulkOp ( ) ;
42- for ( i = 2 ; i < 10000 ; i ++ ) {
52+ for ( var i = 2 ; i < 10000 ; i ++ ) {
4353 bulk . insert ( { x :i } ) ;
4454 }
4555
@@ -52,10 +62,9 @@ if (false) {
5262
5363 assert ( hasCycled ( ) ) ;
5464
55-
56-
5765 // bring node B and it will enter recovery mode because its newest oplog entry is too old
5866 replTest . restart ( BID ) ;
67+
5968 // check that it is in recovery mode
6069 assert . soon ( function ( ) {
6170 try {
@@ -71,6 +80,8 @@ if (false) {
7180 assert . commandWorked ( b_conn . getDB ( "admin" ) . runCommand ( { resync :1 } ) ) ;
7281 replTest . awaitReplication ( ) ;
7382 replTest . awaitSecondaryNodes ( ) ;
83+ assert . eq ( B . foo . findOne ( ) . x , 1 )
7484
7585 replTest . stopSet ( 15 ) ;
76- }
86+ jsTest . log ( "success" ) ;
87+ } ) ( ) ;
0 commit comments