2013-01-22 13:53:52 -05:00
|
|
|
// tests that listDatabases doesn't show config db on a shard, even if it is there
|
|
|
|
|
|
2015-06-30 10:47:58 -04:00
|
|
|
var test = new ShardingTest({shards: 1, mongos: 1, other: {chunksize:1}})
|
2013-01-22 13:53:52 -05:00
|
|
|
|
|
|
|
|
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;
|
2015-11-03 17:46:18 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var dbInConfigEntryCheck = function(dbEntry) {
|
|
|
|
|
assert.neq(null, dbEntry);
|
|
|
|
|
assert(!dbEntry.shards); // db should not be in shard.
|
|
|
|
|
assert.neq(null, dbEntry.sizeOnDisk);
|
|
|
|
|
assert.eq(false, dbEntry.empty);
|
|
|
|
|
};
|
2013-01-22 13:53:52 -05:00
|
|
|
|
2014-03-04 17:41:56 -05:00
|
|
|
assert.writeOK(mongos.getDB("blah").foo.insert({ _id: 1 }));
|
|
|
|
|
assert.writeOK(mongos.getDB("foo").foo.insert({ _id: 1 }));
|
|
|
|
|
assert.writeOK(mongos.getDB("raw").foo.insert({ _id: 1 }));
|
2013-01-22 13:53:52 -05:00
|
|
|
|
|
|
|
|
//verify that the config db is not on a shard
|
|
|
|
|
var res = mongos.adminCommand("listDatabases");
|
|
|
|
|
var dbArray = res.databases;
|
2015-11-03 17:46:18 -05:00
|
|
|
dbInConfigEntryCheck(getDBSection(dbArray, "config"));
|
|
|
|
|
|
|
|
|
|
// Should not have admin entry if it doesn't exists.
|
|
|
|
|
var adminSection = getDBSection(dbArray, 'admin');
|
|
|
|
|
assert(!adminSection);
|
|
|
|
|
|
|
|
|
|
// add doc in admin db on the config server.
|
|
|
|
|
mongos.getDB('admin').test.insert({ _id: 1 });
|
|
|
|
|
res = mongos.adminCommand("listDatabases");
|
|
|
|
|
dbArray = res.databases;
|
|
|
|
|
dbInConfigEntryCheck(getDBSection(dbArray, "config"));
|
|
|
|
|
dbInConfigEntryCheck(getDBSection(dbArray, 'admin'));
|
2013-01-22 13:53:52 -05:00
|
|
|
|
|
|
|
|
//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
|
2015-11-03 17:46:18 -05:00
|
|
|
res = mongos.adminCommand("listDatabases");
|
|
|
|
|
dbArray = res.databases;
|
2013-01-22 13:53:52 -05:00
|
|
|
//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")
|
|
|
|
|
|
2014-03-04 17:41:56 -05:00
|
|
|
test.stop()
|