diff options
author | Dwight <dmerriman@gmail.com> | 2008-12-04 14:33:18 -0500 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2008-12-04 14:33:18 -0500 |
commit | 0fe5e50be0deb6790dc6789a027c821ea8eb6a81 (patch) | |
tree | 017f55c8c2d7fce68c36e49205b8c6901f123d3e | |
parent | 30573a6d913eb33db89ccafd6e1dbb34e901583d (diff) | |
download | mongo-0fe5e50be0deb6790dc6789a027c821ea8eb6a81.tar.gz |
web console work
-rw-r--r-- | db/database.h | 11 | ||||
-rw-r--r-- | db/dbwebserver.cpp | 14 | ||||
-rw-r--r-- | db/repl.cpp | 30 | ||||
-rw-r--r-- | dbgrid/griddatabase.cpp | 11 | ||||
-rw-r--r-- | util/sock.h | 12 |
5 files changed, 64 insertions, 14 deletions
diff --git a/db/database.h b/db/database.h index a8140089897..4120f53da52 100644 --- a/db/database.h +++ b/db/database.h @@ -102,6 +102,8 @@ extern map<string,Database*> databases; extern Database *database; extern const char *curNs; extern int dbLocked; +extern bool master; + /* returns true if the database ("database") did not exist, and it was created on this call */ inline bool setClient(const char *ns) { /* we must be in critical section at this point as these are global @@ -117,7 +119,14 @@ inline bool setClient(const char *ns) { database = it->second; return false; } - log() << "first operation for database " << cl << endl; + + // when master for replication, we advertise all the db's, and that + // looks like a 'first operation'. so that breaks this log message's + // meaningfulness. instead of fixing (which would be better), we just + // stop showing for now. + if( !master ) + log() << "first operation for database " << cl << endl; + bool justCreated; Database *c = new Database(cl, justCreated); databases[cl] = c; diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp index 0a3a5d6785d..3bbe1931491 100644 --- a/db/dbwebserver.cpp +++ b/db/dbwebserver.cpp @@ -23,7 +23,7 @@ #include "replset.h" extern int port; -extern string replInfo; +extern const char *replInfo; time_t started = time(0); @@ -43,7 +43,6 @@ public: ss << "replpair:\n"; ss << replPair->getInfo(); } - ss << replInfo << '\n'; } void doUnlockedStuff(stringstream& ss) { @@ -52,6 +51,7 @@ public: ss << "uptime: " << time(0)-started << " seconds\n"; if( allDead ) ss << "<b>replication allDead=" << allDead << "</b>\n"; + ss << "replInfo: " << replInfo << '\n'; } virtual void doRequest( @@ -65,7 +65,15 @@ public: { responseCode = 200; stringstream ss; - ss << "<html><head><title>db</title></head><body><h2>db</h2><p>\n<pre>"; + ss << "<html><head><title>"; + + string dbname; + { + stringstream z; + z << "db " << getHostName() << ':' << port << ' '; + dbname = z.str(); + } + ss << dbname << "</title></head><body><h2>" << dbname << "</h2><p>\n<pre>"; doUnlockedStuff(ss); diff --git a/db/repl.cpp b/db/repl.cpp index 0318768d7dc..0ae93f6ab45 100644 --- a/db/repl.cpp +++ b/db/repl.cpp @@ -56,10 +56,16 @@ const char *allDead = 0; ReplPair *replPair = 0; /* output by the web console */ -string replInfo = "no repl yet"; +const char *replInfo = ""; +struct ReplInfo { + ReplInfo(const char *msg) { replInfo = msg; } + ~ReplInfo() { replInfo = "?"; } +}; /* peer unreachable, try our arbiter */ void ReplPair::arbitrate() { + ReplInfo r("arbitrate"); + if( arbHost == "-" ) { // no arbiter. we are up, let's assume he is down and network is not partitioned. setMaster(State_Master, "remote unreachable"); @@ -392,6 +398,7 @@ bool ReplSource::resync(string db) { { log() << "resync: cloning database " << db << endl; + ReplInfo r("resync: cloning a database"); string errmsg; bool ok = cloneFrom(hostName.c_str(), errmsg, database->name, false); if( !ok ) { @@ -619,7 +626,7 @@ void ReplSource::sync_pullOpLog() { log() << "pull: time diff: " << (nextOpTime.getSecs() - syncedTo.getSecs()) << "sec\n"; log() << "pull: tailing: " << tailing << '\n'; log() << "pull: data too stale, halting replication" << endl; - allDead = "data too stale halted replication"; + replInfo = allDead = "data too stale halted replication"; assert( syncedTo < nextOpTime ); throw SyncException(); } @@ -660,6 +667,8 @@ void ReplSource::sync_pullOpLog() { returns true if everything happy. return false if you want to reconnect. */ bool ReplSource::sync() { + ReplInfo r("sync"); + log() << "pull: " << sourceName() << '@' << hostName << endl; nClonedThisPass = 0; @@ -672,6 +681,7 @@ bool ReplSource::sync() { if( conn.get() == 0 ) { conn = auto_ptr<DBClientConnection>(new DBClientConnection()); string errmsg; + ReplInfo r("trying to connect to sync source"); if( !conn->connect(hostName.c_str(), errmsg) ) { resetConnection(); log() << "pull: cantconn " << errmsg << endl; @@ -679,7 +689,10 @@ bool ReplSource::sync() { assert( startsWith(hostName.c_str(), replPair->remoteHost.c_str()) ); replPair->arbitrate(); } - sleepsecs(1); + { + ReplInfo r("can't connect to sync source, sleeping"); + sleepsecs(1); + } return false; } } @@ -794,6 +807,7 @@ void replMain() { while( 1 ) { { + ReplInfo r("replMain load sources"); dblock lk; ReplSource::loadAll(sources); } @@ -810,23 +824,28 @@ void replMain() { ok = s->sync(); } catch( SyncException& ) { + replInfo = "caught SyncException"; log() << "caught SyncException, sleeping 10 secs" << endl; sleepsecs(10); } catch( AssertionException& e ) { if( e.severe() ) { + ReplInfo r("replMain caught AssertionException, sleeping 1 minutes"); log() << "replMain caught AssertionException, sleeping 1 minutes" << endl; sleepsecs(60); } else { log() << e.toString() << '\n'; } + replInfo = "replMain caught AssertionException"; } if( !ok ) s->resetConnection(); } - - sleepsecs(3); + { + ReplInfo r("replMain: sleep 3 before next pass"); + sleepsecs(3); + } } ReplSource::cleanup(sources); @@ -844,6 +863,7 @@ void replSlaveThread() { sleepsecs(5); } catch( AssertionException& ) { + ReplInfo r("Assertion in replSlaveThread(): sleeping 5 minutes before retry"); problem() << "Assertion in replSlaveThread(): sleeping 5 minutes before retry" << endl; sleepsecs(300); } diff --git a/dbgrid/griddatabase.cpp b/dbgrid/griddatabase.cpp index af242273126..d2b89dff710 100644 --- a/dbgrid/griddatabase.cpp +++ b/dbgrid/griddatabase.cpp @@ -34,14 +34,15 @@ extern string dashDashGridDb; GridDatabase::GridDatabase() { } void GridDatabase::init() { - char buf[256]; - int ec = gethostname(buf, 127); - if( ec || *buf == 0 ) { - log() << "can't get this server's hostname errno:" << ec << endl; + string hn = getHostName(); + if( hn.empty() ) { sleepsecs(5); exit(16); } - ourHostname = buf; + ourHostname = hn; + + char buf[256]; + strcpy(buf, hn.c_str()); if( dashDashGridDb.empty() ) { char *p = strchr(buf, '-'); diff --git a/util/sock.h b/util/sock.h index f2be1b0f636..4f678098aec 100644 --- a/util/sock.h +++ b/util/sock.h @@ -190,3 +190,15 @@ inline SockAddr::SockAddr(const char *ip, int port) { sa.sin_addr.s_addr = inet_addr(ip); addressSize = sizeof(sa); } + +inline string getHostName() { + char buf[256]; + int ec = gethostname(buf, 127); + if( ec || *buf == 0 ) { + log() << "can't get this server's hostname errno:" << ec << endl; + return ""; + } + return buf; +} + + |