diff options
author | Eric Milkie <milkie@10gen.com> | 2012-05-07 12:47:56 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2012-05-10 11:56:44 -0400 |
commit | 1aaac5eb0dc31c80f82080c9b3e75b49409b74cd (patch) | |
tree | 23ee34f64e8edc5425ef882a22a4123edec7a9fd /db | |
parent | dd21525b0210951619935e0c8964158c12cfe70f (diff) | |
download | mongo-1aaac5eb0dc31c80f82080c9b3e75b49409b74cd.tar.gz |
SERVER-5706 if only slaveDelay'd nodes are available, use them
SERVER-4750 prevent syncing to secondaries with a slavedelay greater than yourself
Conflicts:
db/repl/rs_initialsync.cpp
jstests/replsets/slavedelay3.js
Diffstat (limited to 'db')
-rw-r--r-- | db/repl/rs_initialsync.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/db/repl/rs_initialsync.cpp b/db/repl/rs_initialsync.cpp index 112d7396bc5..1677bfc38c6 100644 --- a/db/repl/rs_initialsync.cpp +++ b/db/repl/rs_initialsync.cpp @@ -80,7 +80,7 @@ namespace mongo { } const Member* ReplSetImpl::getMemberToSyncTo() { - Member *closest = 0; + bool buildIndexes = true; // wait for 2N pings before choosing a sync target @@ -95,16 +95,31 @@ namespace mongo { buildIndexes = myConfig().buildIndexes; } + Member *closest = 0; + // find the member with the lowest ping time that has more data than me - for (Member *m = _members.head(); m; m = m->next()) { - if (m->hbinfo().up() && - // make sure members with buildIndexes sync from other members w/indexes - (!buildIndexes || (buildIndexes && m->config().buildIndexes)) && - (m->state() == MemberState::RS_PRIMARY || - (m->state() == MemberState::RS_SECONDARY && m->hbinfo().opTime > lastOpTimeWritten)) && - (!closest || m->hbinfo().ping < closest->hbinfo().ping)) { - closest = m; + + // Make two attempts. The first attempt, we ignore those nodes with + // slave delay higher than our own. The second attempt includes such + // nodes, in case those are the only ones we can reach. + for (int attempts = 0; attempts < 2; ++attempts) { + for (Member *m = _members.head(); m; m = m->next()) { + if (m->hbinfo().up() && + // make sure members with buildIndexes sync from other members w/indexes + (!buildIndexes || (buildIndexes && m->config().buildIndexes)) && + (m->state() == MemberState::RS_PRIMARY || + (m->state() == MemberState::RS_SECONDARY && + m->hbinfo().opTime > lastOpTimeWritten)) && + (!closest || m->hbinfo().ping < closest->hbinfo().ping)) { + + if ( attempts == 0 && + myConfig().slaveDelay < m->config().slaveDelay ) { + break; // skip this one in the first attempt + } + closest = m; + } } + if (closest) break; // no need for second attempt } { |