diff options
author | dwight <dwight@10gen.com> | 2010-07-18 15:02:46 -0400 |
---|---|---|
committer | dwight <dwight@10gen.com> | 2010-07-18 15:02:46 -0400 |
commit | b12d4c2aff247986c30a12b9ef4e4c8803739b51 (patch) | |
tree | 3f6b312c4398a21fdcfaa19a1979568f5a989c0c | |
parent | 528ad7a41a490d487b2fc6774ee796ab877f79ea (diff) | |
download | mongo-b12d4c2aff247986c30a12b9ef4e4c8803739b51.tar.gz |
rs
-rw-r--r-- | db/db_10.sln | 4 | ||||
-rw-r--r-- | db/instance.cpp | 2 | ||||
-rw-r--r-- | db/oplog.cpp | 4 | ||||
-rw-r--r-- | db/oplogreader.h | 4 | ||||
-rw-r--r-- | db/repl/rs.cpp | 2 | ||||
-rw-r--r-- | db/repl/rs.h | 7 | ||||
-rw-r--r-- | db/repl/rs_initialsync.cpp | 54 | ||||
-rw-r--r-- | db/repl/rs_initiate.cpp | 4 | ||||
-rw-r--r-- | db/repl/rs_optime.h | 2 |
9 files changed, 73 insertions, 10 deletions
diff --git a/db/db_10.sln b/db/db_10.sln index ea642b7bf85..0aa382fc338 100644 --- a/db/db_10.sln +++ b/db/db_10.sln @@ -8,10 +8,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{40 EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{2B262D59-9DC7-4BF1-A431-1BD4966899A5}"
ProjectSection(SolutionItems) = preProject
+ ..\tools\bridge.cpp = ..\tools\bridge.cpp
+ ..\tools\bsondump.cpp = ..\tools\bsondump.cpp
..\tools\dump.cpp = ..\tools\dump.cpp
+ ..\tools\export.cpp = ..\tools\export.cpp
..\tools\files.cpp = ..\tools\files.cpp
..\tools\import.cpp = ..\tools\import.cpp
..\tools\restore.cpp = ..\tools\restore.cpp
+ ..\tools\sniffer.cpp = ..\tools\sniffer.cpp
..\tools\stat.cpp = ..\tools\stat.cpp
..\tools\tool.cpp = ..\tools\tool.cpp
..\tools\tool.h = ..\tools\tool.h
diff --git a/db/instance.cpp b/db/instance.cpp index eb05c9c6eb6..45586719466 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -598,7 +598,7 @@ namespace mongo { { readlock lk(rsoplog); BSONObj o; - if( Helpers::getFirst(rsoplog.c_str(), o) ) + if( Helpers::getFirst(rsoplog, o) ) return true; } } diff --git a/db/oplog.cpp b/db/oplog.cpp index 4bc563017f0..6ca81ae0b3e 100644 --- a/db/oplog.cpp +++ b/db/oplog.cpp @@ -90,7 +90,7 @@ namespace mongo { Record *r; DEV assert( logNS == 0 ); { - const char *logns = rsoplog.c_str(); + const char *logns = rsoplog; if ( rsOplogDetails == 0 ) { Client::Context ctx( logns , dbpath, 0, false); localDB = ctx.db(); @@ -273,7 +273,7 @@ namespace mongo { bool rs = !cmdLine.replSet.empty(); if( rs ) - ns = rsoplog.c_str(); + ns = rsoplog; Client::Context ctx(ns); diff --git a/db/oplogreader.h b/db/oplogreader.h index 7ccc6bc466c..8e34a202d55 100644 --- a/db/oplogreader.h +++ b/db/oplogreader.h @@ -27,6 +27,10 @@ namespace mongo { return conn()->findOne(ns, q); } + BSONObj getLastOp(const char *ns) { + return findOne(ns, Query().sort( BSON( "$natural" << -1 ) )); + } + /* ok to call if already connected */ bool connect(string hostname); diff --git a/db/repl/rs.cpp b/db/repl/rs.cpp index ae32885fbd6..de230010014 100644 --- a/db/repl/rs.cpp +++ b/db/repl/rs.cpp @@ -183,7 +183,7 @@ namespace mongo { assert( lastOpTimeWritten.isNull() ); readlock lk(rsoplog); BSONObj o; - if( Helpers::getLast(rsoplog.c_str(), o) ) { + if( Helpers::getLast(rsoplog, o) ) { cout << "TEMP " << o.toString() << endl; lastOpTimeWritten = o["ts"]._opTime(); uassert(13290, "bad replSet oplog entry?", !lastOpTimeWritten.isNull()); diff --git a/db/repl/rs.h b/db/repl/rs.h index b4c105af413..82ae4abe93f 100644 --- a/db/repl/rs.h +++ b/db/repl/rs.h @@ -185,11 +185,13 @@ namespace mongo { // "heartbeat message" // sent in requestHeartbeat respond in field "hbm" char _hbmsg[256]; - void sethbmsg(string s) { + public: + void sethbmsg(string s, int logLevel = 2) { assert(s.size() < sizeof(_hbmsg)); strcpy(_hbmsg, s.c_str()); + log(logLevel) << "replSet " << s << rsLog; } - + protected: bool initFromConfig(ReplSetConfig& c); // true if ok; throws if config really bad; false if config doesn't include self void _fillIsMaster(BSONObjBuilder&); void _fillIsMasterHost(const Member*, vector<string>&, vector<string>&, vector<string>&); @@ -248,6 +250,7 @@ namespace mongo { private: /* pulling data from primary related - see rs_sync.cpp */ + void _syncDoInitialSync(); void syncDoInitialSync(); }; diff --git a/db/repl/rs_initialsync.cpp b/db/repl/rs_initialsync.cpp index 456202f9d77..dda8e9bf21d 100644 --- a/db/repl/rs_initialsync.cpp +++ b/db/repl/rs_initialsync.cpp @@ -19,19 +19,71 @@ #include "../../client/dbclient.h" #include "rs.h" #include "../oplogreader.h" +#include "../../util/mongoutils/str.h" namespace mongo { + using namespace mongoutils; + void dropAllDatabasesExceptLocal(); + // add try/catch with sleep + + void isyncassert(const char *msg, bool expr) { + if( !expr ) { + string m = str::stream() << "initial sync " << msg; + theReplSet->sethbmsg(m, 0); + uasserted(13388, m); + } + } + void ReplSetImpl::syncDoInitialSync() { - log() << "replSet syncDoInitialSync" << rsLog; + while( 1 ) { + try { + _syncDoInitialSync(); + break; + } + catch(DBException&) { + log(1) << "replSet initial sync exception; sleep 30 sec" << rsLog; + sleepsecs(30); + } + } + } + + void ReplSetImpl::_syncDoInitialSync() { + sethbmsg("initial sync pending"); + + assert( !isPrimary() ); // wouldn't make sense if we were. + + const Member *cp = currentPrimary(); + if( cp == 0 ) { + sethbmsg("initial sync need a member to be primary"); + sleepsecs(15); + return; + } OplogReader r; + if( !r.connect(cp->h().toString()) ) { + sethbmsg( str::stream() << "initial sync couldn't connect to " << cp->h().toString() ); + sleepsecs(15); + return; + } + + BSONObj lastOp = r.getLastOp(rsoplog); + OpTime ts = lastOp["ts"]._opTime(); + long long h = lastOp["h"].numberLong(); + + { + /* make sure things aren't too flappy */ + sleepsecs(5); + isyncassert( "flapping?", currentPrimary() == cp ); + } sethbmsg("initial sync drop all databases"); dropAllDatabasesExceptLocal(); sethbmsg("initial sync - not yet implemented"); + + assert( !isPrimary() ); // wouldn't make sense if we were. } } diff --git a/db/repl/rs_initiate.cpp b/db/repl/rs_initiate.cpp index e6a0e3bbdb9..36f93a94f75 100644 --- a/db/repl/rs_initiate.cpp +++ b/db/repl/rs_initiate.cpp @@ -123,8 +123,8 @@ namespace mongo { it is ok if the initiating member has *other* data than that. */ BSONObj o; - if( Helpers::getFirst(rsoplog.c_str(), o) ) { - errmsg = rsoplog + " is not empty on the initiating member. cannot initiate."; + if( Helpers::getFirst(rsoplog, o) ) { + errmsg = rsoplog + string(" is not empty on the initiating member. cannot initiate."); return false; } } diff --git a/db/repl/rs_optime.h b/db/repl/rs_optime.h index ceae163d923..b3607fac22a 100644 --- a/db/repl/rs_optime.h +++ b/db/repl/rs_optime.h @@ -22,7 +22,7 @@ namespace mongo {
- const string rsoplog = "local.oplog.rs"; + const char rsoplog[] = "local.oplog.rs"; /*
class RSOpTime : public OpTime {
|