Skip to content

Commit

Permalink
Make create and $eval commands on mongos go through standard command …
Browse files Browse the repository at this point in the history
…codepath
  • Loading branch information
stbrody committed Jun 22, 2012
1 parent 425b091 commit c921c81
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
29 changes: 29 additions & 0 deletions src/mongo/s/commands_public.cpp
Expand Up @@ -280,6 +280,20 @@ namespace mongo {
}
} DBStatsCmdObj;

class CreateCmd : public PublicGridCommand {
public:
CreateCmd() : PublicGridCommand( "create" ) {}
bool run(const string& dbName,
BSONObj& cmdObj,
int,
string&,
BSONObjBuilder& result,
bool) {
DBConfigPtr conf = grid.getDBConfig( dbName , false );
return passthrough( conf , cmdObj , result );
}
} createCmd;

class DropCmd : public PublicGridCommand {
public:
DropCmd() : PublicGridCommand( "drop" ) {}
Expand Down Expand Up @@ -1480,6 +1494,21 @@ namespace mongo {
}
} compactCmd;

class EvalCmd : public PublicGridCommand {
public:
EvalCmd() : PublicGridCommand( "$eval" ) {}
virtual bool run(const string& dbName,
BSONObj& cmdObj,
int,
string&,
BSONObjBuilder& result,
bool) {
// $eval isn't allowed to access sharded collections, but we need to leave the
// shard to detect that.
DBConfigPtr conf = grid.getDBConfig( dbName , false );
return passthrough( conf , cmdObj , result );
}
} evalCmd;

/*
Note these are in the pub_grid_cmds namespace, so they don't
Expand Down
9 changes: 2 additions & 7 deletions src/mongo/s/strategy_single.cpp
Expand Up @@ -27,10 +27,7 @@ namespace mongo {
class SingleStrategy : public Strategy {

public:
SingleStrategy() {
_commandsSafeToPass.insert( "$eval" );
_commandsSafeToPass.insert( "create" );
}
SingleStrategy() {}

private:
virtual void queryOp( Request& r ) {
Expand Down Expand Up @@ -89,7 +86,7 @@ namespace mongo {

string commandName = q.query.firstElementFieldName();

uassert(13390, "unrecognized command: " + commandName, _commandsSafeToPass.count(commandName) != 0);
uasserted(13390, "unrecognized command: " + commandName);
}

doQuery( r , r.primaryShard() );
Expand Down Expand Up @@ -200,8 +197,6 @@ namespace mongo {
replyToQuery(0, r.p(), r.m(), x);
return true;
}

set<string> _commandsSafeToPass;
};

Strategy * SINGLE = new SingleStrategy();
Expand Down

0 comments on commit c921c81

Please sign in to comment.