summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jstests/sharding/listDatabases.js46
-rw-r--r--src/mongo/s/commands_admin.cpp28
2 files changed, 73 insertions, 1 deletions
diff --git a/jstests/sharding/listDatabases.js b/jstests/sharding/listDatabases.js
new file mode 100644
index 00000000000..e32ab5ab82b
--- /dev/null
+++ b/jstests/sharding/listDatabases.js
@@ -0,0 +1,46 @@
+// tests that listDatabases doesn't show config db on a shard, even if it is there
+
+var test = new ShardingTest({shards: 1, mongos: 1, config: 1, other: {chunksize:1, separateConfig:true}})
+
+var mongos = test.s0
+var mongod = test.shard0;
+
+//grab the config db instance by name
+var getDBSection = function (dbsArray, dbToFind) {
+ for(var pos in dbsArray) {
+ if (dbsArray[pos].name && dbsArray[pos].name === dbToFind)
+ return dbsArray[pos];
+ }
+ return null;
+}
+
+mongos.getDB("blah").foo.insert({_id:1})
+mongos.getDB("foo").foo.insert({_id:1})
+mongos.getDB("raw").foo.insert({_id:1})
+//wait for writes to finish
+mongos.getDB("raw").getLastError()
+
+//verify that the config db is not on a shard
+var res = mongos.adminCommand("listDatabases");
+var dbArray = res.databases;
+assert(getDBSection(dbArray, "config"), "config db not found! 1")
+assert(!getDBSection(dbArray, "config").shards, "config db is on a shard! 1")
+
+//add doc in config/admin db on the shard
+mongod.getDB("config").foo.insert({_id:1})
+mongod.getDB("admin").foo.insert({_id:1})
+
+//add doc in admin db (via mongos)
+mongos.getDB("admin").foo.insert({_id:1})
+
+//verify that the config db is not on a shard
+var res = mongos.adminCommand("listDatabases");
+var dbArray = res.databases;
+//check config db
+assert(getDBSection(dbArray, "config"), "config db not found! 2")
+assert(!getDBSection(dbArray, "config").shards, "config db is on a shard! 2")
+//check admin db
+assert(getDBSection(dbArray, "admin"), "admin db not found! 2")
+assert(!getDBSection(dbArray, "admin").shards, "admin db is on a shard! 2")
+
+test.stop() \ No newline at end of file
diff --git a/src/mongo/s/commands_admin.cpp b/src/mongo/s/commands_admin.cpp
index cd5aaaa69a2..292ae2038dc 100644
--- a/src/mongo/s/commands_admin.cpp
+++ b/src/mongo/s/commands_admin.cpp
@@ -1283,6 +1283,11 @@ namespace mongo {
continue;
}
+ if ( name == "config" || name == "admin" ) {
+ //always get this from the config servers
+ continue;
+ }
+
long long size = i->second;
totalSize += size;
@@ -1295,7 +1300,7 @@ namespace mongo {
bb.append( temp.obj() );
}
- if ( sizes.find( "config" ) == sizes.end() ){
+ { // get config db from the config servers (first one)
scoped_ptr<ScopedDbConnection> conn(
ScopedDbConnection::getInternalScopedDbConnection( configServer.getPrimary()
.getConnString() ) );
@@ -1316,6 +1321,27 @@ namespace mongo {
conn->done();
}
+ { // get admin db from the config servers (first one)
+ scoped_ptr<ScopedDbConnection> conn(
+ ScopedDbConnection::getInternalScopedDbConnection(
+ configServer.getPrimary().getConnString(), 30));
+ BSONObj x;
+ if ( conn->get()->simpleCommand( "admin" , &x , "dbstats" ) ){
+ BSONObjBuilder b;
+ b.append( "name" , "admin" );
+ b.appendBool( "empty" , false );
+ if ( x["fileSize"].type() )
+ b.appendAs( x["fileSize"] , "sizeOnDisk" );
+ else
+ b.append( "sizeOnDisk" , 1 );
+ bb.append( b.obj() );
+ }
+ else {
+ bb.append( BSON( "name" << "admin" ) );
+ }
+ conn->done();
+ }
+
bb.done();
result.appendNumber( "totalSize" , totalSize );