summaryrefslogtreecommitdiff
path: root/db/repl/connections.h
diff options
context:
space:
mode:
Diffstat (limited to 'db/repl/connections.h')
-rw-r--r--db/repl/connections.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/db/repl/connections.h b/db/repl/connections.h
index 95defe4..cdf2fad 100644
--- a/db/repl/connections.h
+++ b/db/repl/connections.h
@@ -44,19 +44,36 @@ 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;
struct X {
mutex z;
DBClientConnection cc;
- X() : z("X"), cc(/*reconnect*/true, 0, /*timeout*/10) {
+ X() : z("X"), cc(/*reconnect*/ true, 0,
+ /*timeout*/ theReplSet ? theReplSet->config().ho.heartbeatTimeoutMillis/1000.0 : 10.0) {
cc._logLevel = 2;
}
} *x;
typedef map<string,ScopedConn::X*> M;
static M& _map;
+ DBClientConnection* conn() { return &x->cc; }
};
inline ScopedConn::ScopedConn(string hostport) {
@@ -84,8 +101,8 @@ namespace mongo {
// conLock releases...
}
- inline DBClientConnection* ScopedConn::operator->() {
+ /*inline DBClientConnection* ScopedConn::operator->() {
return &x->cc;
- }
+ }*/
}