diff options
author | Dwight <dmerriman@gmail.com> | 2008-10-13 15:55:38 -0400 |
---|---|---|
committer | Dwight <dmerriman@gmail.com> | 2008-10-13 15:55:38 -0400 |
commit | e7931c2ad603a2d1ce597b69cfb4f6d14c08276f (patch) | |
tree | 497affab9033ae891ef40afc80c9cb63019e27c7 | |
parent | 7af92d70d6736cbb5c90a907e7b94a3b04646957 (diff) | |
download | mongo-e7931c2ad603a2d1ce597b69cfb4f6d14c08276f.tar.gz |
fix replication b ug with blank source name
-rw-r--r-- | db/dbclient.cpp | 2 | ||||
-rw-r--r-- | db/repl.cpp | 22 | ||||
-rw-r--r-- | db/repl.h | 5 | ||||
-rw-r--r-- | dbgrid/connpool.h | 3 | ||||
-rw-r--r-- | dbgrid/dbgrid.cpp | 8 | ||||
-rw-r--r-- | dbgrid/request.cpp | 15 |
6 files changed, 35 insertions, 20 deletions
diff --git a/db/dbclient.cpp b/db/dbclient.cpp index b0f3f0358e4..c1e9e7d3aca 100644 --- a/db/dbclient.cpp +++ b/db/dbclient.cpp @@ -36,7 +36,7 @@ JSObj DBClientConnection::findOne(const char *ns, JSObj query, JSObj *fieldsToRe } bool DBClientConnection::connect(const char *serverAddress, string& errmsg) { - /* not reentrant! + /* TODO not reentrant! ok as used right now (we are in a big lock), but won't be later, so fix. */ int port = DBPort; diff --git a/db/repl.cpp b/db/repl.cpp index c3e2b7a5b03..eea18cd76b2 100644 --- a/db/repl.cpp +++ b/db/repl.cpp @@ -213,18 +213,15 @@ int test2() { ReplSource::ReplSource() { nClonedThisPass = 0; paired = false; - sourceName = "main"; } ReplSource::ReplSource(JSObj o) : nClonedThisPass(0) { paired = false; only = o.getStringField("only"); hostName = o.getStringField("host"); - sourceName = o.getStringField("source"); - if( sourceName.empty() ) - sourceName = "main"; + _sourceName = o.getStringField("source"); uassert( "'host' field not set in sources collection object", !hostName.empty() ); - uassert( "'source' field not set in sources collection object", !sourceName.empty() ); + uassert( "only source='main' allowed for now with replication", sourceName() == "main" ); Element e = o.getField("syncedTo"); if( !e.eoo() ) { uassert( "bad sources 'syncedTo' field value", e.type() == Date ); @@ -249,7 +246,7 @@ ReplSource::ReplSource(JSObj o) : nClonedThisPass(0) { JSObj ReplSource::jsobj() { JSObjBuilder b; b.append("host", hostName); - b.append("source", sourceName); + b.append("source", sourceName()); if( !only.empty() ) b.append("only", only); b.appendDate("syncedTo", syncedTo.asDate()); @@ -265,16 +262,17 @@ JSObj ReplSource::jsobj() { void ReplSource::save() { JSObjBuilder b; + assert( !hostName.empty() ); b.append("host", hostName); - b.append("source", sourceName); + // todo: finish allowing multiple source configs. + // this line doesn't work right when source is null, if that is allowed as it is now: + //b.append("source", _sourceName); JSObj pattern = b.done(); JSObj o = jsobj(); stringstream ss; setClient("local.sources"); - //cout << o.toString() << endl; - //cout << pattern.toString() << endl; int u = _updateObjects("local.sources", o, pattern, true/*upsert for pair feature*/, ss); assert( u == 1 || u == 4 ); client = 0; @@ -310,7 +308,7 @@ void ReplSource::loadAll(vector<ReplSource*>& v) { auto_ptr<Cursor> c = findTableScan("local.sources", emptyObj); while( c->ok() ) { ReplSource tmp(c->current()); - if( replPair && tmp.hostName == replPair->remote && tmp.sourceName == "main" ) { + if( replPair && tmp.hostName == replPair->remote && tmp.sourceName() == "main" ) { gotPairWith = true; tmp.paired = true; } @@ -463,7 +461,7 @@ void ReplSource::sync_pullOpLog_applyOperation(JSObj& op) { /* note: not yet in mutex at this point. */ void ReplSource::sync_pullOpLog() { - string ns = string("local.oplog.$") + sourceName; + string ns = string("local.oplog.$") + sourceName(); bool tailing = true; DBClientCursor *c = cursor.get(); @@ -576,7 +574,7 @@ void ReplSource::sync_pullOpLog() { returns true if everything happy. return false if you want to reconnect. */ bool ReplSource::sync() { - log() << "pull: " << sourceName << '@' << hostName << endl; + log() << "pull: " << sourceName() << '@' << hostName << endl; nClonedThisPass = 0; if( (string("localhost") == hostName || string("127.0.0.1") == hostName) && port == DBPort ) { diff --git a/db/repl.h b/db/repl.h index f4d0ebedb81..541d4e4d36b 100644 --- a/db/repl.h +++ b/db/repl.h @@ -103,7 +103,8 @@ class ReplSource { public: bool paired; // --pair in use string hostName; // ip addr or hostname plus optionally, ":<port>" - string sourceName; // a logical source name. + string _sourceName; // a logical source name. + string sourceName() const { return _sourceName.empty() ? "main" : _sourceName; } string only; // only a certain db. note that in the sources collection, this may not be changed once you start replicating. /* the last time point we have already synced up to. */ @@ -132,7 +133,7 @@ public: JSObj jsobj(); bool operator==(const ReplSource&r) const { - return hostName == r.hostName && sourceName == r.sourceName; + return hostName == r.hostName && sourceName() == r.sourceName(); } }; diff --git a/dbgrid/connpool.h b/dbgrid/connpool.h index d28a5fffee8..92eed9687c8 100644 --- a/dbgrid/connpool.h +++ b/dbgrid/connpool.h @@ -38,6 +38,9 @@ public: extern DBConnectionPool pool; +/* create these to get a connection from the pool. then on exceptions things + clean up nicely. +*/ class ScopedDbConnection { const string host; DBClientConnection *_conn; diff --git a/dbgrid/dbgrid.cpp b/dbgrid/dbgrid.cpp index 1369a934dc9..b1f32d133a7 100644 --- a/dbgrid/dbgrid.cpp +++ b/dbgrid/dbgrid.cpp @@ -74,12 +74,14 @@ void _dbGridConnThread() { } -void dbGridConnThread() { +void dbGridConnThread() { + MessagingPort *p = grab; try { _dbGridConnThread(); } catch( ... ) { - problem() << "uncaught exception in dbgridconnthread, terminating" << endl; - dbexit(15); + /* todo: don't terminate; maybe close the socket. */ + problem() << "uncaught exception in dbgridconnthread, closing connection" << endl; + delete p; } } diff --git a/dbgrid/request.cpp b/dbgrid/request.cpp index 97cea33dab6..f5e40e18c28 100644 --- a/dbgrid/request.cpp +++ b/dbgrid/request.cpp @@ -21,11 +21,18 @@ #include "../db/dbmessage.h" #include "connpool.h" -void writeOp(int op, Message& m, MessagingPort& p) {
+void queryOp(Message& m, MessagingPort& p) { DbMessage d(m); const char *ns = d.getns(); + cout << "TEMP: " << ns << endl; + + ScopedDbConnection c("localhost"); +} +void writeOp(int op, Message& m, MessagingPort& p) {
+ DbMessage d(m); + const char *ns = d.getns(); while( d.moreJSObjs() ) { JSObj js = d.nextJsObj(); @@ -41,5 +48,9 @@ void writeOp(int op, Message& m, MessagingPort& p) { void processRequest(Message& m, MessagingPort& p) { int op = m.data->operation(); - writeOp(op, m, p); + if( op == dbQuery ) { + } + else { + writeOp(op, m, p); + } } |