0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00
mongodb/s/strategy_single.cpp

88 lines
2.9 KiB
C++
Raw Normal View History

// strategy_simple.cpp
2009-02-06 20:25:06 +01:00
#include "stdafx.h"
#include "request.h"
#include "../client/connpool.h"
#include "../db/commands.h"
namespace mongo {
2009-02-06 20:25:06 +01:00
class SingleStrategy : public Strategy {
virtual void queryOp( Request& r ){
QueryMessage q( r.d() );
bool lateAssert = false;
log(3) << "single 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;
}
}
2009-02-17 17:41:34 +01:00
string commandName = q.query.firstElement().fieldName();
if ( commandName == "count" ){
string dbName = q.ns;
dbName = dbName.substr( 0 , dbName.size() - 5 );
string collection = q.query.firstElement().valuestrsafe();
DBConfig * conf = grid.getDBConfig( dbName , false );
if ( conf && conf->isPartitioned() && conf->sharded( dbName + "." + collection ) ){
uassert( "can't handle sharded count yet" , 0 );
}
}
log() << "don't know what i should do with command: " << commandName << endl;
lateAssert = true;
doQuery( r , r.singleServerName() );
}
catch ( AssertionException& e ) {
assert( !lateAssert );
BSONObjBuilder err;
err.append("$err", string("mongos: ") + (e.msg.empty() ? "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) << "single getmore: " << ns << endl;
2009-02-17 17:41:34 +01:00
ScopedDbConnection dbcon( r.singleServerName() );
2009-02-07 15:21:29 +01:00
DBClientBase& _c = dbcon.conn();
2009-02-17 17:41:34 +01:00
// TODO
2009-02-07 15:21:29 +01:00
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) << "single write: " << ns << endl;
2009-02-20 16:46:42 +01:00
doWrite( op , r , r.singleServerName() );
}
};
2009-02-06 20:25:06 +01:00
Strategy * SINGLE = new SingleStrategy();
}