diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-04-22 16:46:43 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-04-22 16:46:43 -0400 |
commit | 0bbf65ae8f78b414ea35f96f03524822f7ecd821 (patch) | |
tree | 64a90c7fc0b952b9a36355197d650bc794e6760c /s | |
parent | 9afc7f05f8d7f1a728ab33b5581471170097001a (diff) | |
parent | 68b84b3f77213f5b857872aa84412305965e7ed2 (diff) | |
download | mongo-0bbf65ae8f78b414ea35f96f03524822f7ecd821.tar.gz |
Merge branch 'master' of git@github.com:mongodb/mongo
Diffstat (limited to 's')
-rw-r--r-- | s/commands_admin.cpp (renamed from s/commands.cpp) | 2 | ||||
-rw-r--r-- | s/commands_public.cpp | 87 | ||||
-rw-r--r-- | s/shard.cpp | 9 | ||||
-rw-r--r-- | s/shard.h | 7 | ||||
-rw-r--r-- | s/strategy_single.cpp | 14 |
5 files changed, 98 insertions, 21 deletions
diff --git a/s/commands.cpp b/s/commands_admin.cpp index 1ae5e4d5615..4fcf23a2d34 100644 --- a/s/commands.cpp +++ b/s/commands_admin.cpp @@ -1,4 +1,4 @@ -// dbgrid/request.cpp +// s/commands_admin.cpp /** * Copyright (C) 2008 10gen Inc. diff --git a/s/commands_public.cpp b/s/commands_public.cpp new file mode 100644 index 00000000000..6cf8a99ce1f --- /dev/null +++ b/s/commands_public.cpp @@ -0,0 +1,87 @@ +// s/commands_public.cpp + + +/** +* 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/>. +*/ + +#include "stdafx.h" +#include "../util/message.h" +#include "../db/dbmessage.h" +#include "../client/connpool.h" +#include "../db/commands.h" + +#include "config.h" +#include "shard.h" +#include "strategy.h" + +namespace mongo { + + namespace dbgrid_pub_cmds { + + class PublicGridCommand : public Command { + public: + PublicGridCommand( const char * n ) : Command( n ){ + } + virtual bool slaveOk(){ + return true; + } + virtual bool adminOnly() { + return false; + } + }; + + + class CountCmd : public PublicGridCommand { + public: + CountCmd() : PublicGridCommand("count") { } + bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){ + + string dbName = ns; + dbName = dbName.substr( 0 , dbName.size() - 5 ); + string collection = cmdObj.firstElement().valuestrsafe(); + string fullns = dbName + "." + collection; + + BSONObj filter = cmdObj["query"].embeddedObject(); + + DBConfig * conf = grid.getDBConfig( dbName , false ); + + if ( ! conf || ! conf->isPartitioned() || ! conf->sharded( fullns ) ){ + ScopedDbConnection conn( conf->getPrimary() ); + result.append( "n" , (double)conn->count( fullns , filter ) ); + conn.done(); + result.append( "ok" , 1 ); + return true; + } + + ShardManager * sm = conf->getShardManager( fullns ); + massert( "how could shard manager be null!" , sm ); + + vector<Shard*> shards; + sm->getShardsForQuery( shards , filter ); + + unsigned long long total = 0; + for ( vector<Shard*>::iterator i = shards.begin() ; i != shards.end() ; i++ ){ + Shard * s = *i; + total += s->countObjects(); + } + + result.append( "n" , (double)total ); + result.append( "ok" , 1 ); + return true; + } + } countCmd; + } +} diff --git a/s/shard.cpp b/s/shard.cpp index a202fc9e46d..ba347c7c701 100644 --- a/s/shard.cpp +++ b/s/shard.cpp @@ -273,15 +273,12 @@ namespace mongo { long Shard::countObjects(){ ScopedDbConnection conn( getServer() ); + BSONObj result; - uassert( "datasize failed!" , conn->runCommand( "admin" , BSON( "datasize" << _ns - << "keyPattern" << _manager->getShardKey().key() - << "min" << getMin() - << "max" << getMax() - ) , result ) ); + unsigned long long n = conn->count( _ns , getFilter() ); conn.done(); - return (long)result["numObjects"].number(); + return (long)n; } bool Shard::operator==( const Shard& s ){ diff --git a/s/shard.h b/s/shard.h index 09ca136b56b..800004ff685 100644 --- a/s/shard.h +++ b/s/shard.h @@ -36,10 +36,13 @@ namespace mongo { class ShardObjUnitTest; typedef unsigned long long ServerShardVersion; - + /** config.shard { ns : "alleyinsider.fs.chunks" , min : {} , max : {} , server : "localhost:30001" } + + x is in a shard iff + min <= x < max */ class Shard : public Model , boost::noncopyable { public: @@ -70,6 +73,8 @@ namespace mongo { } void getFilter( BSONObjBuilder& b ); + BSONObj getFilter(){ BSONObjBuilder b; getFilter( b ); return b.obj(); } + BSONObj pickSplitPoint(); Shard * split(); diff --git a/s/strategy_single.cpp b/s/strategy_single.cpp index 71c18ce7f35..b45af4c57c2 100644 --- a/s/strategy_single.cpp +++ b/s/strategy_single.cpp @@ -27,19 +27,7 @@ namespace mongo { } 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 << " " << q.query << endl; + log() << "passing through command: " << commandName << " " << q.query << endl; } lateAssert = true; |