0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

sharded filemd5 command SERVER-935

This commit is contained in:
Mathias Stearn 2010-04-13 20:53:48 -04:00
parent 5514fc4473
commit 4c0481213f
2 changed files with 42 additions and 1 deletions

View File

@ -891,7 +891,7 @@ namespace mongo {
return true; return true;
} }
virtual void help( stringstream& help ) const { 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; } virtual LockType locktype(){ return READ; }
bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){ bool run(const char *dbname, BSONObj& jsobj, string& errmsg, BSONObjBuilder& result, bool fromRepl ){

View File

@ -413,6 +413,47 @@ namespace mongo {
} }
} disinctCmd; } 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 { class MRCmd : public PublicGridCommand {
public: public:
MRCmd() : PublicGridCommand( "mapreduce" ){} MRCmd() : PublicGridCommand( "mapreduce" ){}