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

107 lines
3.3 KiB
C++
Raw Normal View History

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/>.
*/
#include "stdafx.h"
2009-02-05 17:50:27 +01:00
#include "server.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
#include "request.h"
2009-02-13 03:03:46 +01:00
#include "config.h"
#include "shard.h"
2009-02-05 22:45:58 +01:00
2009-01-14 23:09:51 +01:00
namespace mongo {
2009-03-02 05:43:00 +01:00
Request::Request( Message& m, AbstractMessagingPort* p ) : _m(m) , _d( m ) , _p(p){
2009-02-06 21:44:21 +01:00
assert( _d.getns() );
_id = _m.data->id;
_config = grid.getDBConfig( getns() );
if ( _config->sharded( getns() ) ){
_shardInfo = _config->getShardManager( getns() );
uassert( (string)"no shard info for: " + getns() , _shardInfo );
}
else {
_shardInfo = 0;
}
2009-02-06 21:44:21 +01:00
}
string Request::singleServerName(){
if ( _shardInfo ){
if ( _shardInfo->numShards() > 1 )
throw UserException( "can't call singleServerName on a sharded collection" );
return _shardInfo->findShard( _shardInfo->getShardKey().globalMin() ).getServer();
}
string s = _config->getServer( getns() );
uassert( "can't call singleServerName on a sharded collection!" , s.size() > 0 );
return s;
}
2009-02-19 18:55:01 +01:00
void Request::process(){
2009-02-19 18:55:01 +01:00
int op = _m.data->operation();
assert( op > dbMsg );
2009-02-05 22:45:58 +01:00
2009-02-18 19:54:22 +01:00
Strategy * s = SINGLE;
2009-02-19 18:55:01 +01:00
if ( getConfig()->isPartitioned() && op == dbQuery ){
// there are a few things we need to check here
// 1. db.eval
// TODO: right now i'm just going to block all
// will need to make it look at function later
// 2. $where - can't access DB
// TODO: make it smarter
QueryMessage q( _d );
BSONObj query = q.query;
if ( q.ntoreturn == 1 &&
strstr( q.ns , ".$cmd" ) &&
2009-02-26 21:55:00 +01:00
strcmp( "$eval" , query.firstElement().fieldName() ) == 0 ){
2009-02-19 18:55:01 +01:00
log() << "trying to eval: " << q.query << endl;
throw UserException( "eval not supported on partitioned databases yet" );
}
if ( query.hasField( "$where" ) )
throw UserException( "$where not supported for partitioned databases yet" );
2009-02-18 19:54:22 +01:00
2009-02-19 18:55:01 +01:00
_d.resetPull();
}
2009-02-19 23:32:19 +01:00
if ( _shardInfo ){
if ( _shardInfo->numShards() > 1 )
2009-02-20 16:46:42 +01:00
s = SHARDED;
2009-02-19 23:32:19 +01:00
}
2009-02-19 18:55:01 +01:00
if ( op == dbQuery ) {
2009-02-19 18:55:01 +01:00
s->queryOp( *this );
}
else if ( op == dbGetMore ) {
2009-02-19 18:55:01 +01:00
s->getMore( *this );
}
else {
2009-02-19 18:55:01 +01:00
s->writeOp( op, *this );
}
}
2009-02-05 22:45:58 +01:00
2009-01-14 23:09:51 +01:00
} // namespace mongo