2009-02-06 20:11:31 +01:00
|
|
|
// strategy_simple.cpp
|
|
|
|
|
2009-02-06 20:25:06 +01:00
|
|
|
#include "stdafx.h"
|
2009-02-06 20:11:31 +01:00
|
|
|
#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 {
|
2009-02-06 20:11:31 +01:00
|
|
|
|
|
|
|
virtual void queryOp( Request& r ){
|
|
|
|
QueryMessage q( r.d() );
|
|
|
|
|
|
|
|
bool lateAssert = false;
|
|
|
|
|
2009-02-22 05:39:41 +01:00
|
|
|
log(3) << "single query: " << q.ns << " " << q.query << endl;
|
2009-02-06 20:11:31 +01:00
|
|
|
|
|
|
|
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-04-07 19:22:12 +02: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 );
|
|
|
|
}
|
2009-04-07 18:18:40 +02:00
|
|
|
}
|
2009-04-07 19:22:12 +02:00
|
|
|
|
|
|
|
log() << "don't know what i should do with command: " << commandName << " " << q.query << endl;
|
2009-04-07 18:18:40 +02:00
|
|
|
}
|
2009-04-07 19:22:12 +02:00
|
|
|
|
2009-02-06 20:11:31 +01:00
|
|
|
lateAssert = true;
|
2009-02-22 05:39:41 +01:00
|
|
|
doQuery( r , r.singleServerName() );
|
2009-02-06 20:11:31 +01:00
|
|
|
}
|
|
|
|
catch ( AssertionException& e ) {
|
|
|
|
assert( !lateAssert );
|
|
|
|
BSONObjBuilder err;
|
2009-02-19 19:26:25 +01:00
|
|
|
err.append("$err", string("mongos: ") + (e.msg.empty() ? "assertion during query" : e.msg));
|
2009-02-06 20:11:31 +01:00
|
|
|
BSONObj errObj = err.done();
|
|
|
|
replyToQuery(QueryResult::ResultFlag_ErrSet, r.p() , r.m() , errObj);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getMore( Request& r ){
|
|
|
|
const char *ns = r.getns();
|
|
|
|
|
2009-02-22 05:39:41 +01:00
|
|
|
log(3) << "single getmore: " << ns << endl;
|
2009-02-06 20:11:31 +01:00
|
|
|
|
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);
|
2009-02-06 20:11:31 +01:00
|
|
|
|
|
|
|
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();
|
2009-02-22 05:39:41 +01:00
|
|
|
log(3) << "single write: " << ns << endl;
|
2009-02-20 16:46:42 +01:00
|
|
|
doWrite( op , r , r.singleServerName() );
|
2009-02-06 20:11:31 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-02-06 20:25:06 +01:00
|
|
|
Strategy * SINGLE = new SingleStrategy();
|
2009-02-06 20:11:31 +01:00
|
|
|
}
|