45
45
void ReplSetImpl::syncDoInitialSync() {
46
const static int maxFailedAttempts = 3;
48
int failedAttempts = 0;
49
while ( failedAttempts < maxFailedAttempts ) {
50
51
_syncDoInitialSync();
53
54
catch(DBException& e) {
54
sethbmsg("initial sync exception " + e.toString(), 0);
57
msg << "initial sync exception: ";
58
msg << e.toString() << " " << (maxFailedAttempts - failedAttempts) << " attempts remaining" ;
63
if ( failedAttempts >= maxFailedAttempts ) ::abort();
60
66
/* todo : progress metering to sethbmsg. */
95
101
buildIndexes = myConfig().buildIndexes;
98
106
// find the member with the lowest ping time that has more data than me
99
for (Member *m = _members.head(); m; m = m->next()) {
100
if (m->hbinfo().up() &&
101
// make sure members with buildIndexes sync from other members w/indexes
102
(!buildIndexes || (buildIndexes && m->config().buildIndexes)) &&
103
(m->state() == MemberState::RS_PRIMARY ||
104
(m->state() == MemberState::RS_SECONDARY && m->hbinfo().opTime > lastOpTimeWritten)) &&
105
(!closest || m->hbinfo().ping < closest->hbinfo().ping)) {
108
// Make two attempts. The first attempt, we ignore those nodes with
109
// slave delay higher than our own. The second attempt includes such
110
// nodes, in case those are the only ones we can reach.
111
for (int attempts = 0; attempts < 2; ++attempts) {
112
for (Member *m = _members.head(); m; m = m->next()) {
113
if (m->hbinfo().up() &&
114
// make sure members with buildIndexes sync from other members w/indexes
115
(!buildIndexes || (buildIndexes && m->config().buildIndexes)) &&
116
(m->state() == MemberState::RS_PRIMARY ||
117
(m->state() == MemberState::RS_SECONDARY &&
118
m->hbinfo().opTime > lastOpTimeWritten)) &&
119
(!closest || m->hbinfo().ping < closest->hbinfo().ping)) {
121
if ( attempts == 0 &&
122
myConfig().slaveDelay < m->config().slaveDelay ) {
123
break; // skip this one in the first attempt
128
if (closest) break; // no need for second attempt