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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "../grid/message.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
|
|
|
|
2008-10-13 23:58:51 +02:00
|
|
|
const char *tempHost = "localhost:27018";
|
|
|
|
|
|
|
|
void getMore(Message& m, MessagingPort& p) {
|
|
|
|
DbMessage d(m);
|
|
|
|
const char *ns = d.getns();
|
|
|
|
|
|
|
|
cout << "TEMP: getmore: " << ns << endl;
|
|
|
|
|
|
|
|
ScopedDbConnection dbcon(tempHost);
|
|
|
|
DBClientConnection &c = dbcon.conn();
|
|
|
|
|
|
|
|
Message response;
|
|
|
|
bool ok = c.port().call(m, response);
|
|
|
|
uassert("dbgrid: getmore: error calling db", ok);
|
|
|
|
p.reply(m, response, m.data->id);
|
|
|
|
|
|
|
|
dbcon.done();
|
|
|
|
}
|
|
|
|
|
2008-10-22 22:56:39 +02:00
|
|
|
bool runCommandAgainstRegistered(const char *ns, BSONObj& jsobj, BSONObjBuilder& anObjBuilder);
|
2008-09-30 00:00:53 +02:00
|
|
|
|
2008-12-02 20:24:45 +01:00
|
|
|
/* got query operation from a database */
|
2008-10-22 22:56:39 +02:00
|
|
|
void queryOp(Message& m, MessagingPort& p) {
|
|
|
|
DbMessage d(m);
|
|
|
|
QueryMessage q(d);
|
2008-10-29 22:48:03 +01:00
|
|
|
bool lateAssert = false;
|
|
|
|
try {
|
|
|
|
if( q.ntoreturn == -1 && strstr(q.ns, ".$cmd") ) {
|
|
|
|
BSONObjBuilder builder;
|
|
|
|
cout << q.query.toString() << endl;
|
|
|
|
bool ok = runCommandAgainstRegistered(q.ns, q.query, builder);
|
|
|
|
if( ok ) {
|
|
|
|
BSONObj x = builder.done();
|
|
|
|
replyToQuery(p, m, x);
|
|
|
|
return;
|
|
|
|
}
|
2008-10-22 22:56:39 +02:00
|
|
|
}
|
2008-10-13 22:19:39 +02:00
|
|
|
|
2008-10-29 22:48:03 +01:00
|
|
|
ScopedDbConnection dbcon(tempHost);
|
|
|
|
DBClientConnection &c = dbcon.conn();
|
|
|
|
Message response;
|
|
|
|
bool ok = c.port().call(m, response);
|
|
|
|
uassert("dbgrid: error calling db", ok);
|
|
|
|
lateAssert = true;
|
|
|
|
p.reply(m, response, m.data->id);
|
|
|
|
dbcon.done();
|
|
|
|
}
|
|
|
|
catch( AssertionException& e ) {
|
|
|
|
assert( !lateAssert );
|
|
|
|
BSONObjBuilder err;
|
2008-11-14 17:20:23 +01:00
|
|
|
err.append("$err", string("dbgrid ") + (e.msg.empty() ? "dbgrid assertion during query" : e.msg));
|
2008-10-29 22:48:03 +01:00
|
|
|
BSONObj errObj = err.done();
|
|
|
|
replyToQuery(p, m, errObj);
|
|
|
|
return;
|
|
|
|
}
|
2008-10-13 21:55:38 +02:00
|
|
|
}
|
2008-09-30 00:00:53 +02:00
|
|
|
|
2008-10-29 22:48:03 +01:00
|
|
|
void writeOp(int op, Message& m, MessagingPort& p) {
|
2008-10-13 21:55:38 +02:00
|
|
|
DbMessage d(m);
|
|
|
|
const char *ns = d.getns();
|
2008-09-30 00:00:53 +02:00
|
|
|
|
2008-10-13 23:58:51 +02:00
|
|
|
ScopedDbConnection dbcon(tempHost);
|
|
|
|
DBClientConnection &c = dbcon.conn();
|
|
|
|
|
|
|
|
c.port().say(m);
|
|
|
|
|
|
|
|
dbcon.done();
|
|
|
|
/*
|
2008-10-09 00:20:02 +02:00
|
|
|
while( d.moreJSObjs() ) {
|
2008-10-21 22:13:48 +02:00
|
|
|
BSONObj js = d.nextJsObj();
|
2008-10-09 00:20:02 +02:00
|
|
|
const char *ns = d.getns();
|
|
|
|
assert(*ns);
|
|
|
|
}
|
2008-10-13 23:58:51 +02:00
|
|
|
*/
|
2008-10-09 00:20:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void processRequest(Message& m, MessagingPort& p) {
|
|
|
|
int op = m.data->operation();
|
2008-10-13 23:58:51 +02:00
|
|
|
assert( op > dbMsg );
|
2008-10-13 21:55:38 +02:00
|
|
|
if( op == dbQuery ) {
|
2008-10-13 22:19:39 +02:00
|
|
|
queryOp(m,p);
|
2008-10-13 21:55:38 +02:00
|
|
|
}
|
2008-10-13 23:58:51 +02:00
|
|
|
else if( op == dbGetMore ) {
|
|
|
|
getMore(m,p);
|
|
|
|
}
|
2008-10-13 21:55:38 +02:00
|
|
|
else {
|
|
|
|
writeOp(op, m, p);
|
|
|
|
}
|
2008-10-09 00:20:02 +02:00
|
|
|
}
|