summaryrefslogtreecommitdiff
path: root/src/mongo/s/commands/cluster_list_databases_cmd.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2017-01-13 11:09:17 -0500
committerDavid Storch <david.storch@10gen.com>2017-01-19 17:48:18 -0500
commit7e8db821ae2c8ed1eaa637f97c301d53b48b2a26 (patch)
tree5820464d8a140d0b5163ef5afe92798d196ba558 /src/mongo/s/commands/cluster_list_databases_cmd.cpp
parent9af9840664bc7b892c1c017db31b086bf0ea9bf9 (diff)
downloadmongo-7e8db821ae2c8ed1eaa637f97c301d53b48b2a26.tar.gz
SERVER-27584 add filter to listDatabases command
(cherry picked from commit d7bd800d3d06004c4ca9114627ee882442e4d5e4)
Diffstat (limited to 'src/mongo/s/commands/cluster_list_databases_cmd.cpp')
-rw-r--r--src/mongo/s/commands/cluster_list_databases_cmd.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/mongo/s/commands/cluster_list_databases_cmd.cpp b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
index 9151d244bfe..2ae555e8593 100644
--- a/src/mongo/s/commands/cluster_list_databases_cmd.cpp
+++ b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
@@ -32,6 +32,7 @@
#include <string>
#include <vector>
+#include "mongo/bson/util/bson_extract.h"
#include "mongo/client/read_preference.h"
#include "mongo/client/remote_command_targeter.h"
#include "mongo/db/commands.h"
@@ -105,7 +106,7 @@ public:
txn,
ReadPreferenceSetting{ReadPreference::PrimaryPreferred},
"admin",
- BSON("listDatabases" << 1),
+ cmdObj,
Shard::RetryPolicy::kIdempotent));
uassertStatusOK(response.commandStatus);
BSONObj x = std::move(response.response);
@@ -117,13 +118,13 @@ public:
const string name = dbObj["name"].String();
const long long size = dbObj["sizeOnDisk"].numberLong();
- long long& totalSize = sizes[name];
+ long long& sizeSumForDbAcrossShards = sizes[name];
if (size == 1) {
- if (totalSize <= 1) {
- totalSize = 1;
+ if (sizeSumForDbAcrossShards <= 1) {
+ sizeSumForDbAcrossShards = 1;
}
} else {
- totalSize += size;
+ sizeSumForDbAcrossShards += size;
}
unique_ptr<BSONObjBuilder>& bb = dbShardInfo[name];
@@ -135,8 +136,6 @@ public:
}
}
- long long totalSize = 0;
-
BSONArrayBuilder dbListBuilder(result.subarrayStart("databases"));
for (map<string, long long>::iterator i = sizes.begin(); i != sizes.end(); ++i) {
const string name = i->first;
@@ -152,7 +151,6 @@ public:
}
long long size = i->second;
- totalSize += size;
BSONObjBuilder temp;
temp.append("name", name);
@@ -165,13 +163,25 @@ public:
// Get information for config and admin dbs from the config servers.
auto catalogClient = grid.catalogClient(txn);
- auto appendStatus = catalogClient->appendInfoForConfigServerDatabases(txn, &dbListBuilder);
+ auto appendStatus =
+ catalogClient->appendInfoForConfigServerDatabases(txn, cmdObj, &dbListBuilder);
if (!appendStatus.isOK()) {
return Command::appendCommandStatus(result, appendStatus);
}
dbListBuilder.done();
+ // Compute the combined total size based on the response we've built so far.
+ long long totalSize = 0;
+ for (auto&& dbElt : result.asTempObj()["databases"].Obj()) {
+ long long sizeOnDisk;
+ uassertStatusOK(bsonExtractIntegerField(dbElt.Obj(), "sizeOnDisk"_sd, &sizeOnDisk));
+ uassert(ErrorCodes::BadValue,
+ str::stream() << "Found negative 'sizeOnDisk' in: " << dbElt.Obj(),
+ sizeOnDisk >= 0);
+ totalSize += sizeOnDisk;
+ }
+
result.appendNumber("totalSize", totalSize);
result.appendNumber("totalSizeMb", totalSize / (1024 * 1024));