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:
parent
5514fc4473
commit
4c0481213f
@ -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 ){
|
||||
|
@ -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" ){}
|
||||
|
Loading…
Reference in New Issue
Block a user