From 4c0481213f19b43d44707f81dac2537a80ab71d5 Mon Sep 17 00:00:00 2001 From: Mathias Stearn Date: Tue, 13 Apr 2010 20:53:48 -0400 Subject: [PATCH] sharded filemd5 command SERVER-935 --- db/dbcommands.cpp | 2 +- s/commands_public.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index 0706a3d2342..f40e5fc63d3 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -891,7 +891,7 @@ namespace mongo { return true; } virtual void help( stringstream& help ) const { - help << " example: { filemd5 : ObjectId(aaaaaaa) , key : { ts : 1 } }"; + help << " example: { filemd5 : ObjectId(aaaaaaa) , root : \"fs\" }"; } virtual LockType locktype(){ return READ; } bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){ diff --git a/s/commands_public.cpp b/s/commands_public.cpp index 649d7d1ac7e..5ead52cc1b5 100644 --- a/s/commands_public.cpp +++ b/s/commands_public.cpp @@ -413,6 +413,47 @@ namespace mongo { } } disinctCmd; + class FileMD5Cmd : public PublicGridCommand { + public: + FileMD5Cmd() : PublicGridCommand("filemd5"){} + virtual void help( stringstream &help ) const { + help << " example: { filemd5 : ObjectId(aaaaaaa) , root : \"fs\" }"; + } + bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){ + string dbName = getDBName( ns ); + + string fullns = dbName; + fullns += "."; + { + string root = cmdObj.getStringField( "root" ); + if ( root.size() == 0 ) + root = "fs"; + fullns += root; + } + fullns += ".chunks"; + + DBConfig * conf = grid.getDBConfig( dbName , false ); + + if ( ! conf || ! conf->isShardingEnabled() || ! conf->isSharded( fullns ) ){ + return passthrough( conf , cmdObj , result ); + } + + ChunkManager * cm = conf->getChunkManager( fullns ); + massert( 13091 , "how could chunk manager be null!" , cm ); + uassert( 13092 , "GridFS chunks collection can only be sharded on files_id", cm->getShardKey().key() == BSON("files_id" << 1)); + + const Chunk& chunk = cm->findChunk( BSON("files_id" << cmdObj.firstElement()) ); + + ScopedDbConnection conn( chunk.getShard() ); + BSONObj res; + bool ok = conn->runCommand( conf->getName() , cmdObj , res ); + conn.done(); + + result.appendElements(res); + return ok; + } + } fileMD5Cmd; + class MRCmd : public PublicGridCommand { public: MRCmd() : PublicGridCommand( "mapreduce" ){}