~ubuntu-branches/ubuntu/wily/mongodb/wily

« back to all changes in this revision

Viewing changes to src/mongo/db/repl/rs_rollback.cpp

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-26 09:41:32 UTC
  • mfrom: (1.2.25)
  • Revision ID: package-import@ubuntu.com-20130826094132-8cknfm4syxyip1zt
Tags: 1:2.4.6-0ubuntu1
* New upstream point release.
* d/control,d/tests/*: Add autopkgtests for server process and client
  shell functionality.

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
 
69
69
    class rsfatal : public std::exception {
70
70
    public:
71
 
        virtual const char* what() const throw() { return "replica set fatal exception"; }
 
71
        rsfatal(std::string m = "replica set fatal exception") : msg(m) {}
 
72
        virtual ~rsfatal() throw() {};
 
73
        virtual const char* what() const throw() { return msg.c_str(); }
 
74
    private:
 
75
        std::string msg;
72
76
    };
73
77
 
74
78
    struct DocID {
193
197
    int getRBID(DBClientConnection*);
194
198
 
195
199
    static void syncRollbackFindCommonPoint(DBClientConnection *them, HowToFixUp& h) {
196
 
        static time_t last;
197
 
        if( time(0)-last < 60 ) {
198
 
            throw "findcommonpoint waiting a while before trying again";
199
 
        }
200
 
        last = time(0);
201
 
 
202
200
        verify( Lock::isLocked() );
203
201
        Client::Context c(rsoplog);
204
202
        NamespaceDetails *nsd = nsdetails(rsoplog);
205
203
        verify(nsd);
206
204
        ReverseCappedCursor u(nsd);
207
205
        if( !u.ok() )
208
 
            throw "our oplog empty or unreadable";
 
206
            throw rsfatal("our oplog empty or unreadable");
209
207
 
210
208
        const Query q = Query().sort(reverseNaturalObj);
211
209
        const bo fields = BSON( "ts" << 1 << "h" << 1 );
215
213
        h.rbid = getRBID(them);
216
214
        auto_ptr<DBClientCursor> t = them->query(rsoplog, q, 0, 0, &fields, 0, 0);
217
215
 
218
 
        if( t.get() == 0 || !t->more() ) throw "remote oplog empty or unreadable";
 
216
        if( t.get() == 0 || !t->more() ) throw rsfatal("remote oplog empty or unreadable");
219
217
 
220
218
        BSONObj ourObj = u.current();
221
219
        OpTime ourTime = ourObj["ts"]._opTime();
230
228
            log() << "replSet info rollback diff in end of log times: " << diff << " seconds" << rsLog;
231
229
            if( diff > 1800 ) {
232
230
                log() << "replSet rollback too long a time period for a rollback." << rsLog;
233
 
                throw "error not willing to roll back more than 30 minutes of data";
 
231
                throw rsfatal(str::stream() << "rollback error: not willing to roll back "
 
232
                                            << "more than 30 minutes of data");
234
233
            }
235
234
        }
236
235
 
256
255
                    log() << "replSet   them:      " << them->toString() << " scanned: " << scanned << rsLog;
257
256
                    log() << "replSet   theirTime: " << theirTime.toStringLong() << rsLog;
258
257
                    log() << "replSet   ourTime:   " << ourTime.toStringLong() << rsLog;
259
 
                    throw "RS100 reached beginning of remote oplog [2]";
 
258
                    throw rsfatal("RS100 reached beginning of remote oplog [2]");
260
259
                }
261
260
                theirObj = t->nextSafe();
262
261
                theirTime = theirObj["ts"]._opTime();
267
266
                    log() << "replSet   them:      " << them->toString() << " scanned: " << scanned << rsLog;
268
267
                    log() << "replSet   theirTime: " << theirTime.toStringLong() << rsLog;
269
268
                    log() << "replSet   ourTime:   " << ourTime.toStringLong() << rsLog;
270
 
                    throw "RS101 reached beginning of local oplog [1]";
 
269
                    throw rsfatal("RS101 reached beginning of local oplog [1]");
271
270
                }
272
271
                ourObj = u.current();
273
272
                ourTime = ourObj["ts"]._opTime();
278
277
                    log() << "replSet   them:      " << them->toString() << " scanned: " << scanned << rsLog;
279
278
                    log() << "replSet   theirTime: " << theirTime.toStringLong() << rsLog;
280
279
                    log() << "replSet   ourTime:   " << ourTime.toStringLong() << rsLog;
281
 
                    throw "RS100 reached beginning of remote oplog [1]";
 
280
                    throw rsfatal("RS100 reached beginning of remote oplog [1]");
282
281
                }
283
282
                theirObj = t->nextSafe();
284
283
                theirTime = theirObj["ts"]._opTime();
292
291
                    log() << "replSet   them:      " << them->toString() << " scanned: " << scanned << rsLog;
293
292
                    log() << "replSet   theirTime: " << theirTime.toStringLong() << rsLog;
294
293
                    log() << "replSet   ourTime:   " << ourTime.toStringLong() << rsLog;
295
 
                    throw "RS101 reached beginning of local oplog [2]";
 
294
                    throw rsfatal("RS101 reached beginning of local oplog [2]");
296
295
                }
297
296
                ourObj = u.current();
298
297
                ourTime = ourObj["ts"]._opTime();
637
636
            try {
638
637
                syncRollbackFindCommonPoint(r.conn(), how);
639
638
            }
640
 
            catch( const char *p ) {
641
 
                sethbmsg(string("rollback 2 error ") + p);
642
 
                return 10;
643
 
            }
644
 
            catch( rsfatal& ) {
 
639
            catch( rsfatal& e ) {
 
640
                sethbmsg(string(e.what()));
645
641
                _fatal();
646
642
                return 2;
647
643
            }