From 30e604c3ccd325f8ec0502fd0830bbc90df860de Mon Sep 17 00:00:00 2001 From: Dwight Date: Thu, 28 Oct 2010 10:38:24 -0400 Subject: SERVER-2021 rs ScopedConn bug(2) 165 172 --- db/repl/health.cpp | 6 +++--- db/repl/rs_config.cpp | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/db/repl/health.cpp b/db/repl/health.cpp index 72396fe60db..c75221c5f5b 100644 --- a/db/repl/health.cpp +++ b/db/repl/health.cpp @@ -19,6 +19,7 @@ #include "health.h" #include "../../util/background.h" #include "../../client/dbclient.h" +#include "../../client/connpool.h" #include "../commands.h" #include "../../util/concurrency/value.h" #include "../../util/concurrency/task.h" @@ -186,7 +187,7 @@ namespace mongo { //const bo fields = BSON( "o" << false << "o2" << false ); const bo fields; - ScopedConn conn(m->fullName()); + ScopedDbConnection conn(m->fullName()); auto_ptr c = conn->query(rsoplog, Query().sort("$natural",1), 20, 0, &fields); if( c.get() == 0 ) { @@ -245,8 +246,6 @@ namespace mongo { ss << _table(); ss << p(time_t_to_String_short(time(0)) + " current time"); - //ss << "\n"; - if( !otEnd.isNull() ) { ss << "

Log length in time: "; unsigned d = otEnd.getSecs() - otFirst.getSecs(); @@ -259,6 +258,7 @@ namespace mongo { ss << "

\n"; } + conn.done(); } void ReplSetImpl::_summarizeAsHtml(stringstream& s) const { diff --git a/db/repl/rs_config.cpp b/db/repl/rs_config.cpp index 61b5a8d33b2..509381ed3aa 100644 --- a/db/repl/rs_config.cpp +++ b/db/repl/rs_config.cpp @@ -302,9 +302,8 @@ namespace mongo { clear(); int level = 2; DEV level = 0; - //log(0) << "replSet load config from: " << h.toString() << rsLog; - auto_ptr c; + BSONObj cfg; int v = -5; try { if( h.isSelf() ) { @@ -337,10 +336,12 @@ namespace mongo { } v = -4; + long long count = 0; try { ScopedConn conn(h.toString()); v = -3; - c = conn->query( rsConfigNs, Query() ); + cfg = conn->findOne(rsConfigNs, Query()).getOwned(); + count = conn->count(rsConfigNs); } catch ( DBException& e) { if ( !h.isSelf() ) { @@ -349,13 +350,14 @@ namespace mongo { // on startup, socket is not listening yet DBDirectClient cli; - c = cli.query( rsConfigNs, Query() ); + cfg = cli.findOne( rsConfigNs, Query() ).getOwned(); + count = cli.count(rsConfigNs); } + + if( count > 1 ) + uasserted(13109, str::stream() << "multiple rows in " << rsConfigNs << " not supported host: " << h.toString()); - if( c.get() == 0 ) { - version = v; return; - } - if( !c->more() ) { + if( cfg.isEmpty() ) { version = EMPTYCONFIG; return; } @@ -367,9 +369,7 @@ namespace mongo { return; } - BSONObj o = c->nextSafe(); - uassert(13109, "multiple rows in " + rsConfigNs + " not supported", !c->more()); - from(o); + from(cfg); checkRsConfig(); _ok = true; log(level) << "replSet load config ok from " << (h.isSelf() ? "self" : h.toString()) << rsLog; -- cgit v1.2.1