diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-02-13 09:22:04 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-02-13 09:22:04 -0500 |
commit | a835ed1af58ec5f4a7b74b9f27079f0cad6c2bc7 (patch) | |
tree | bceb81e40084137ccf10b30609e5809dbe026222 /s/strategy_single.cpp | |
parent | b859ae916306509aca6d4135e7826b15008ccf02 (diff) | |
download | mongo-a835ed1af58ec5f4a7b74b9f27079f0cad6c2bc7.tar.gz |
renamed dbgrid s
Diffstat (limited to 's/strategy_single.cpp')
-rw-r--r-- | s/strategy_single.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/s/strategy_single.cpp b/s/strategy_single.cpp new file mode 100644 index 00000000000..843b70ef578 --- /dev/null +++ b/s/strategy_single.cpp @@ -0,0 +1,89 @@ +// strategy_simple.cpp + +#include "stdafx.h" +#include "request.h" +#include "../client/connpool.h" +#include "../db/commands.h" + +namespace mongo { + + class SingleStrategy : public Strategy { + + virtual void queryOp( Request& r ){ + QueryMessage q( r.d() ); + + bool lateAssert = false; + + log(3) << "query: " << q.ns << " " << q.query << endl; + + try { + if ( q.ntoreturn == 1 && strstr(q.ns, ".$cmd") ) { + BSONObjBuilder builder; + bool ok = runCommandAgainstRegistered(q.ns, q.query, builder); + if ( ok ) { + BSONObj x = builder.done(); + replyToQuery(0, r.p(), r.m(), x); + return; + } + } + + ScopedDbConnection dbcon( r.primaryName() ); + DBClientBase &_c = dbcon.conn(); +/** Todo: This will not work with Paired connections. Fix. */ + DBClientConnection&c = dynamic_cast<DBClientConnection&>(_c); + Message response; + bool ok = c.port().call( r.m(), response); + uassert("dbgrid: error calling db", ok); + lateAssert = true; + r.reply( response ); + dbcon.done(); + } + catch ( AssertionException& e ) { + assert( !lateAssert ); + BSONObjBuilder err; + err.append("$err", string("dbgrid ") + (e.msg.empty() ? "dbgrid assertion during query" : e.msg)); + BSONObj errObj = err.done(); + replyToQuery(QueryResult::ResultFlag_ErrSet, r.p() , r.m() , errObj); + return; + } + + } + + virtual void getMore( Request& r ){ + const char *ns = r.getns(); + + log(3) << "getmore: " << ns << endl; + + ScopedDbConnection dbcon( r.primaryName() ); + DBClientBase& _c = dbcon.conn(); +/* TODO */ + DBClientConnection &c = dynamic_cast<DBClientConnection&>(_c); + + Message response; + bool ok = c.port().call( r.m() , response); + uassert("dbgrid: getmore: error calling db", ok); + r.reply( response ); + + dbcon.done(); + + } + + virtual void writeOp( int op , Request& r ){ + const char *ns = r.getns(); + log(3) << "write: " << ns << endl; + + ScopedDbConnection dbcon( r.primaryName() ); + DBClientBase &_c = dbcon.conn(); + /* TODO FIX - do not case and call DBClientBase::say() */ + DBClientConnection&c = dynamic_cast<DBClientConnection&>(_c); + + + c.port().say( r.m() ); + + dbcon.done(); + + } + }; + + Strategy * SINGLE = new SingleStrategy(); +} |