Skip to content

Commit

Permalink
SERVER-4992 Disable dropDatabase command on config
Browse files Browse the repository at this point in the history
i) Diallow completely via mongos
ii) And partially if mongod started with --configsvr
  • Loading branch information
singhsiddharth committed May 30, 2012
1 parent d66742b commit eef1039
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
38 changes: 38 additions & 0 deletions jstests/sharding/drop_configdb.js
@@ -0,0 +1,38 @@
var shardA = startMongodEmpty("--shardsvr", "--port", 30001, "--dbpath", "/data/shardA", "--nopreallocj");
var shardB = startMongodEmpty("--shardsvr", "--port", 30002, "--dbpath", "/data/shardB", "--nopreallocj");
var configsvr = startMongodEmpty("--configsvr", "--port", 29999, "--dbpath", "/data/configC", "--nopreallocj");

var mongos = startMongos({ port : 30000, configdb : "localhost:29999" })

var admin = mongos.getDB("admin")

admin.runCommand({ addshard : "localhost:30001" })
admin.runCommand({ addshard : "localhost:30002" })

var config = configsvr.getDB( "config" )

// Try to drop config db via configsvr

print ( "1: Try to drop config database via configsvr" )
config.dropDatabase()

print ( "2: Ensure it wasn't dropped" )
assert.eq( 1, config.databases.find({ _id : "admin", partitioned : false, primary : "config"}).toArray().length )


// Try to drop config db via mongos

var config = mongos.getDB( "config" )

print ( "1: Try to drop config database via mongos" )
config.dropDatabase()

print ( "2: Ensure it wasn't dropped" )
assert.eq( 1, config.databases.find({ _id : "admin", partitioned : false, primary : "config"}).toArray().length )


// Finish
stopMongod( 30000 );
stopMongod( 29999 );
stopMongod( 30001 );
stopMongod( 30002 );
5 changes: 5 additions & 0 deletions src/mongo/db/dbcommands.cpp
Expand Up @@ -340,6 +340,11 @@ namespace mongo {
virtual LockType locktype() const { return WRITE; }
CmdDropDatabase() : Command("dropDatabase") {}
bool run(const string& dbname, BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
// disallow dropping the config database
if ( cmdLine.configsvr && ( dbname == "config" ) ) {
errmsg = "Cannot drop 'config' database if mongod started with --configsvr";
return false;
}
BSONElement e = cmdObj.firstElement();
log() << "dropDatabase " << dbname << endl;
int p = (int) e.number();
Expand Down
5 changes: 5 additions & 0 deletions src/mongo/s/commands_public.cpp
Expand Up @@ -309,6 +309,11 @@ namespace mongo {
public:
DropDBCmd() : PublicGridCommand( "dropDatabase" ) {}
bool run(const string& dbName , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool) {
// disallow dropping the config database from mongos
if( dbName == "config" ) {
errmsg = "Cannot drop 'config' database via mongos";
return false;
}

BSONElement e = cmdObj.firstElement();

Expand Down

0 comments on commit eef1039

Please sign in to comment.