diff options
author | Dwight <dwight@10gen.com> | 2010-10-28 10:50:39 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-11-20 00:01:20 -0500 |
commit | c0044d58a7c43adb1456b676456c4f63aaed309b (patch) | |
tree | af42b8814038a28f93af165fe184eada55fc2ffd | |
parent | 30e604c3ccd325f8ec0502fd0830bbc90df860de (diff) | |
download | mongo-c0044d58a7c43adb1456b676456c4f63aaed309b.tar.gz |
make ScopedConn idiot-proof (safe from me)
-rw-r--r-- | db/repl/connections.h | 22 | ||||
-rw-r--r-- | db/repl/heartbeat.cpp | 2 | ||||
-rw-r--r-- | db/repl/multicmd.h | 2 | ||||
-rw-r--r-- | db/repl/rs_config.cpp | 6 |
4 files changed, 24 insertions, 8 deletions
diff --git a/db/repl/connections.h b/db/repl/connections.h index 95defe4fb83..19807920558 100644 --- a/db/repl/connections.h +++ b/db/repl/connections.h @@ -44,7 +44,22 @@ namespace mongo { /** throws assertions if connect failure etc. */ ScopedConn(string hostport); ~ScopedConn(); - DBClientConnection* operator->(); + + /* If we were to run a query and not exhaust the cursor, future use of the connection would be problematic. + So here what we do is wrapper known safe methods and not allow cursor-style queries at all. This makes + ScopedConn limited in functionality but very safe. More non-cursor wrappers can be added here if needed. + */ + + bool runCommand(const string &dbname, const BSONObj& cmd, BSONObj &info, int options=0) { + return conn()->runCommand(dbname, cmd, info, options); + } + unsigned long long count(const string &ns) { + return conn()->count(ns); + } + BSONObj findOne(const string &ns, const Query& q, const BSONObj *fieldsToReturn = 0, int queryOptions = 0) { + return conn()->findOne(ns, q, fieldsToReturn, queryOptions); + } + private: auto_ptr<scoped_lock> connLock; static mutex mapMutex; @@ -57,6 +72,7 @@ namespace mongo { } *x; typedef map<string,ScopedConn::X*> M; static M& _map; + DBClientConnection* conn() { return &x->cc; } }; inline ScopedConn::ScopedConn(string hostport) { @@ -84,8 +100,8 @@ namespace mongo { // conLock releases... } - inline DBClientConnection* ScopedConn::operator->() { + /*inline DBClientConnection* ScopedConn::operator->() { return &x->cc; - } + }*/ } diff --git a/db/repl/heartbeat.cpp b/db/repl/heartbeat.cpp index 4f288972fd8..b39fad73c30 100644 --- a/db/repl/heartbeat.cpp +++ b/db/repl/heartbeat.cpp @@ -134,7 +134,7 @@ namespace mongo { assert( theReplSet == 0 || !theReplSet->lockedByMe() ); ScopedConn conn(memberFullName); - return conn->runCommand("admin", cmd, result); + return conn.runCommand("admin", cmd, result, 0); } /* poll every other set member to check its status */ diff --git a/db/repl/multicmd.h b/db/repl/multicmd.h index 61c9b5f2168..9eb9a179b23 100644 --- a/db/repl/multicmd.h +++ b/db/repl/multicmd.h @@ -43,7 +43,7 @@ namespace mongo { void run() { try { ScopedConn c(d.toHost); - d.ok = c->runCommand("admin", cmd, d.result); + d.ok = c.runCommand("admin", cmd, d.result); } catch(DBException&) { DEV log() << "dev caught dbexception on multiCommand " << d.toHost << rsLog; diff --git a/db/repl/rs_config.cpp b/db/repl/rs_config.cpp index 509381ed3aa..371507d7221 100644 --- a/db/repl/rs_config.cpp +++ b/db/repl/rs_config.cpp @@ -336,12 +336,12 @@ namespace mongo { } v = -4; - long long count = 0; + unsigned long long count = 0; try { ScopedConn conn(h.toString()); v = -3; - cfg = conn->findOne(rsConfigNs, Query()).getOwned(); - count = conn->count(rsConfigNs); + cfg = conn.findOne(rsConfigNs, Query()).getOwned(); + count = conn.count(rsConfigNs); } catch ( DBException& e) { if ( !h.isSelf() ) { |