~james-page/ubuntu/precise/mongodb/arch-enablement

« back to all changes in this revision

Viewing changes to db/repl/rs_initialsync.cpp

  • Committer: Package Import Robot
  • Author(s): Antonin Kral
  • Date: 2012-06-05 19:52:28 UTC
  • mfrom: (1.2.18)
  • Revision ID: package-import@ubuntu.com-20120605195228-y35631zus0oblqd7
Tags: 1:2.0.6-1
New upstream release 2.0.6
https://jira.mongodb.org/browse/SERVER/fixforversion/11165

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    }
44
44
 
45
45
    void ReplSetImpl::syncDoInitialSync() {
 
46
        const static int maxFailedAttempts = 3;
46
47
        createOplog();
47
 
 
48
 
        while( 1 ) {
 
48
        int failedAttempts = 0;
 
49
        while ( failedAttempts < maxFailedAttempts ) {
49
50
            try {
50
51
                _syncDoInitialSync();
51
52
                break;
52
53
            }
53
54
            catch(DBException& e) {
54
 
                sethbmsg("initial sync exception " + e.toString(), 0);
 
55
                failedAttempts++;
 
56
                str::stream msg;
 
57
                msg << "initial sync exception: ";
 
58
                msg << e.toString() << " " << (maxFailedAttempts - failedAttempts) << " attempts remaining" ;
 
59
                sethbmsg(msg, 0);
55
60
                sleepsecs(30);
56
61
            }
57
62
        }
 
63
        if ( failedAttempts >= maxFailedAttempts ) ::abort();
58
64
    }
59
65
 
60
66
    /* todo : progress metering to sethbmsg. */
80
86
    }
81
87
 
82
88
    const Member* ReplSetImpl::getMemberToSyncTo() {
83
 
        Member *closest = 0;
 
89
 
84
90
        bool buildIndexes = true;
85
91
 
86
92
        // wait for 2N pings before choosing a sync target
95
101
            buildIndexes = myConfig().buildIndexes;
96
102
        }
97
103
 
 
104
        Member *closest = 0;
 
105
 
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)) {
106
 
                closest = m;
 
107
 
 
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)) {
 
120
 
 
121
                    if ( attempts == 0 && 
 
122
                         myConfig().slaveDelay < m->config().slaveDelay ) {
 
123
                        break; // skip this one in the first attempt
 
124
                    }
 
125
                    closest = m;
 
126
                }
107
127
            }
 
128
            if (closest) break; // no need for second attempt
108
129
        }
109
130
 
110
131
        {