diff options
-rw-r--r-- | db/repl/rs_initialsync.cpp | 14 | ||||
-rw-r--r-- | jstests/replsets/initial_sync2.js | 22 |
2 files changed, 13 insertions, 23 deletions
diff --git a/db/repl/rs_initialsync.cpp b/db/repl/rs_initialsync.cpp index 8880282d940..2d8b3303b1e 100644 --- a/db/repl/rs_initialsync.cpp +++ b/db/repl/rs_initialsync.cpp @@ -181,19 +181,11 @@ namespace mongo { } /** - * Do the initial sync for this member. There must be a primary available - * for the whole intial sync, even if we're syncing from a secondary. + * Do the initial sync for this member. */ void ReplSetImpl::_syncDoInitialSync() { sethbmsg("initial sync pending",0); - const Member *cp = box.getPrimary(); - if (!cp) { - sethbmsg("initial sync needs a member to be primary to begin"); - sleepsecs(15); - return; - } - const Member *source = getMemberToSyncTo(); if (!source) { sethbmsg("initial sync need a member to be primary or secondary to do our initial sync", 0); @@ -248,7 +240,7 @@ namespace mongo { sethbmsg("initial sync query minValid",0); - isyncassert( "initial sync source must remain primary throughout our initial sync", box.getPrimary() == cp ); + isyncassert( "initial sync source must remain readable throughout our initial sync", source->state().readable() ); /* our cloned copy will be strange until we apply oplog events that occurred through the process. we note that time point here. */ @@ -261,7 +253,7 @@ namespace mongo { */ { sethbmsg("initial sync initial oplog application"); - isyncassert( "initial sync source must remain primary throughout our initial sync [2]", box.getPrimary() == cp ); + isyncassert( "initial sync source must remain readable throughout our initial sync [2]", source->state().readable() ); if( ! initialSyncOplogApplication(source, /*applyGTE*/startingTS, /*minValid*/mvoptime) ) { // note we assume here that this call does not throw log() << "replSet initial sync failed during applyoplog" << rsLog; emptyOplog(); // otherwise we'll be up! diff --git a/jstests/replsets/initial_sync2.js b/jstests/replsets/initial_sync2.js index 80962a633e6..cb929296562 100644 --- a/jstests/replsets/initial_sync2.js +++ b/jstests/replsets/initial_sync2.js @@ -8,7 +8,7 @@ * 5. Freeze #2 * 6. Bring up #3 * 7. Kill #1 in the middle of syncing - * 8. Check that #1 doesn't make it into secondary state for a while + * 8. Check that #3 makes it into secondary state * 9. Bring #1 back up * 10. Initial sync should succeed * 11. Insert some stuff @@ -99,17 +99,15 @@ print("7. Kill #1 in the middle of syncing"); replTest.stop(0); -print("8. Check that #3 doesn't make it into secondary state for a while"); -for (var i=0; i<100; i++) { - var status = admin_s2.runCommand({replSetGetStatus:1}); - occasionally(function() { printjson(status);}, 10); - assert(status.members[2].state != 2); - if (status.members[2].state == 1) { - print("#3 completed its initial sync, we should just stop"); - return; - } - sleep(1000); -} +print("8. Check that #3 makes it into secondary state"); +wait(function() { + var status = admin_s2.runCommand({replSetGetStatus:1}); + occasionally(function() { printjson(status);}, 10); + if (status.members[2].state == 2 || status.members[2].state == 1) { + return true; + } + return false; + }); print("9. Bring #1 back up"); |