Permalink
Browse files

SERVER-4992 Disable dropDatabase command on config

i) Diallow completely via mongos
ii) And partially if mongod started with --configsvr

Signed-off-by: Eric Milkie <milkie@10gen.com>
  • Loading branch information...
1 parent b39f7ff commit e25d6a41652eaebd1395582261e3c83718d10274 @singhsiddharth singhsiddharth committed with milkie May 30, 2012
Showing with 48 additions and 0 deletions.
  1. +5 −0 db/dbcommands.cpp
  2. +38 −0 jstests/sharding/drop_configdb.js
  3. +5 −0 s/commands_public.cpp
View
@@ -333,6 +333,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();
@@ -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 );
View
@@ -304,6 +304,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();

0 comments on commit e25d6a4

Please sign in to comment.