2008-11-09 23:49:37 +01:00
|
|
|
/* dbgrid/request.cpp
|
|
|
|
|
|
|
|
Top level handling of requests (operations such as query, insert, ...)
|
|
|
|
*/
|
2008-09-15 15:14:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (C) 2008 10gen Inc.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-09-15 15:14:42 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-09-15 15:14:42 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-09-15 15:14:42 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-10-13 23:58:51 +02:00
|
|
|
/* TODO
|
2008-11-09 23:49:37 +01:00
|
|
|
_ GridD
|
|
|
|
|
|
|
|
|
2008-10-13 23:58:51 +02:00
|
|
|
_ concurrency control.
|
|
|
|
_ connection pool
|
|
|
|
_ hostbyname_nonreentrant() problem
|
|
|
|
_ gridconfig object which gets config from the grid db.
|
|
|
|
connect to iad-sb-grid
|
|
|
|
_ limit() works right?
|
|
|
|
_ KillCursors
|
|
|
|
|
|
|
|
later
|
|
|
|
_ secondary indexes
|
|
|
|
*/
|
|
|
|
|
2008-09-15 15:14:42 +02:00
|
|
|
#include "stdafx.h"
|
2009-02-03 19:30:28 +01:00
|
|
|
#include "../util/message.h"
|
2008-12-05 22:03:35 +01:00
|
|
|
#include "../db/commands.h"
|
2008-09-30 00:00:53 +02:00
|
|
|
#include "../db/dbmessage.h"
|
2008-11-01 01:17:54 +01:00
|
|
|
#include "../client/connpool.h"
|
2008-10-09 00:20:02 +02:00
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
namespace mongo {
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
const char *tempHost = "localhost:27018";
|
|
|
|
|
|
|
|
void getMore(Message& m, MessagingPort& p) {
|
|
|
|
DbMessage d(m);
|
|
|
|
const char *ns = d.getns();
|
|
|
|
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << "TEMP: getmore: " << ns << endl;
|
2008-12-29 02:28:49 +01:00
|
|
|
|
|
|
|
ScopedDbConnection dbcon(tempHost);
|
|
|
|
DBClientConnection &c = dbcon.conn();
|
2009-01-15 16:17:11 +01:00
|
|
|
|
2008-12-29 02:28:49 +01:00
|
|
|
Message response;
|
|
|
|
bool ok = c.port().call(m, response);
|
2009-01-15 16:17:11 +01:00
|
|
|
uassert("dbgrid: getmore: error calling db", ok);
|
2008-12-29 02:28:49 +01:00
|
|
|
p.reply(m, response, m.data->id);
|
2009-02-03 17:05:16 +01:00
|
|
|
|
2008-12-29 02:28:49 +01:00
|
|
|
dbcon.done();
|
|
|
|
}
|
2009-01-15 16:17:11 +01:00
|
|
|
|
|
|
|
/* got query operation from a database */
|
|
|
|
void queryOp(Message& m, MessagingPort& p) {
|
2009-02-03 17:05:16 +01:00
|
|
|
const MSGID originalID = m.data->id;
|
2009-01-15 16:17:11 +01:00
|
|
|
DbMessage d(m);
|
|
|
|
QueryMessage q(d);
|
|
|
|
bool lateAssert = false;
|
|
|
|
try {
|
|
|
|
if ( q.ntoreturn == -1 && strstr(q.ns, ".$cmd") ) {
|
|
|
|
BSONObjBuilder builder;
|
2009-01-15 17:26:38 +01:00
|
|
|
out() << q.query.toString() << endl;
|
2009-01-15 16:17:11 +01:00
|
|
|
bool ok = runCommandAgainstRegistered(q.ns, q.query, builder);
|
|
|
|
if ( ok ) {
|
|
|
|
BSONObj x = builder.done();
|
|
|
|
replyToQuery(0, p, m, x);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopedDbConnection dbcon(tempHost);
|
|
|
|
DBClientConnection &c = dbcon.conn();
|
|
|
|
Message response;
|
|
|
|
bool ok = c.port().call(m, response);
|
|
|
|
uassert("dbgrid: error calling db", ok);
|
|
|
|
lateAssert = true;
|
2009-02-03 17:05:16 +01:00
|
|
|
p.reply(m, response, originalID );
|
2009-01-15 16:17:11 +01:00
|
|
|
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, p, m, errObj);
|
|
|
|
return;
|
|
|
|
}
|
2008-12-29 02:28:49 +01:00
|
|
|
}
|
2009-02-03 17:05:16 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
void writeOp(int op, Message& m, MessagingPort& p) {
|
|
|
|
DbMessage d(m);
|
|
|
|
const char *ns = d.getns();
|
|
|
|
assert( *ns );
|
2008-09-30 00:00:53 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
ScopedDbConnection dbcon(tempHost);
|
|
|
|
DBClientConnection &c = dbcon.conn();
|
2008-10-13 23:58:51 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
c.port().say(m);
|
2008-10-13 23:58:51 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
dbcon.done();
|
|
|
|
/*
|
2009-01-19 02:31:33 +01:00
|
|
|
while( d.mmoreJSObjs() ) {
|
2009-01-15 16:17:11 +01:00
|
|
|
BSONObj js = d.nextJsObj();
|
|
|
|
const char *ns = d.getns();
|
|
|
|
assert(*ns);
|
|
|
|
}
|
|
|
|
*/
|
2008-10-13 23:58:51 +02:00
|
|
|
}
|
2009-01-15 16:17:11 +01:00
|
|
|
|
|
|
|
void processRequest(Message& m, MessagingPort& p) {
|
|
|
|
int op = m.data->operation();
|
|
|
|
assert( op > dbMsg );
|
|
|
|
if ( op == dbQuery ) {
|
|
|
|
queryOp(m,p);
|
|
|
|
}
|
|
|
|
else if ( op == dbGetMore ) {
|
|
|
|
getMore(m,p);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
writeOp(op, m, p);
|
|
|
|
}
|
2008-10-13 21:55:38 +02:00
|
|
|
}
|
2009-01-14 23:09:51 +01:00
|
|
|
|
|
|
|
} // namespace mongo
|