diff options
author | Kevin Pulo <kevin.pulo@mongodb.com> | 2017-09-18 15:27:07 +1000 |
---|---|---|
committer | Kevin Pulo <kevin.pulo@mongodb.com> | 2017-10-04 14:15:59 +1100 |
commit | cfd5d0743fa00409b5208f1ee2d14dfbdc269ea4 (patch) | |
tree | b182fff1390a9057a12ea85e8276ee0d81cdc09e | |
parent | 6c6a13f3a7707d39537789c7c125c9283c68987a (diff) | |
download | mongo-cfd5d0743fa00409b5208f1ee2d14dfbdc269ea4.tar.gz |
SERVER-19076 handle multiline shard keys in sh.status()
(cherry picked from commit a18d0f0c5754c750b44ba05ad7cc26b1f8054625)
-rw-r--r-- | jstests/sharding/printShardingStatus.js | 11 | ||||
-rw-r--r-- | src/mongo/shell/utils.js | 12 | ||||
-rw-r--r-- | src/mongo/shell/utils_sh.js | 126 |
3 files changed, 93 insertions, 56 deletions
diff --git a/jstests/sharding/printShardingStatus.js b/jstests/sharding/printShardingStatus.js index 5bfa70c2d8f..ac2b1bb0e16 100644 --- a/jstests/sharding/printShardingStatus.js +++ b/jstests/sharding/printShardingStatus.js @@ -7,6 +7,8 @@ var st = new ShardingTest({shards: 1, mongos: 2, config: 1, other: {smallfiles: true}}); + var standalone = MongoRunner.runMongod(); + var mongos = st.s0; var admin = mongos.getDB("admin"); @@ -85,9 +87,10 @@ testBasicVerboseOnly(outputVerbose); // Take a copy of the config db, in order to test the harder-to-setup cases below. + // Copy into a standalone to also test running printShardingStatus() against a config dump. // TODO: Replace this manual copy with copydb once SERVER-13080 is fixed. var config = mongos.getDB("config"); - var configCopy = mongos.getDB("configCopy"); + var configCopy = standalone.getDB("configCopy"); config.getCollectionInfos().forEach(function(c) { // Create collection with options. assert.commandWorked(configCopy.createCollection(c.name, c.options)); @@ -140,11 +143,11 @@ configCopy.mongos.remove({}); var output = grabStatusOutput(configCopy, false); - assertPresentInOutput(output, "most recently active mongoses:\n\tnone", "no mongoses"); + assertPresentInOutput(output, "most recently active mongoses:\n none", "no mongoses"); var output = grabStatusOutput(configCopy, true); assertPresentInOutput( - output, "most recently active mongoses:\n\tnone", "no mongoses (verbose)"); + output, "most recently active mongoses:\n none", "no mongoses (verbose)"); assert(mongos.getDB(dbName).dropDatabase()); @@ -233,5 +236,7 @@ assert(mongos.getDB("test").dropDatabase()); + MongoRunner.stopMongod(standalone); + st.stop(); })(); diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js index 2d86a1f6ac3..6b48765fc1a 100644 --- a/src/mongo/shell/utils.js +++ b/src/mongo/shell/utils.js @@ -159,6 +159,18 @@ print.captureAllOutput = function(fn, args) { return res; }; +var indentStr = function(indent, s) { + if (typeof(s) === "undefined") { + s = indent; + indent = 0; + } + if (indent > 0) { + indent = (new Array(indent + 1)).join(" "); + s = indent + s.replace(/\n/g, "\n" + indent); + } + return s; +}; + if (typeof TestData == "undefined") { TestData = undefined; } diff --git a/src/mongo/shell/utils_sh.js b/src/mongo/shell/utils_sh.js index 6cdb7ff645b..776423fd434 100644 --- a/src/mongo/shell/utils_sh.js +++ b/src/mongo/shell/utils_sh.js @@ -535,6 +535,18 @@ sh.getRecentMigrations = function(configDB) { return result; }; +sh._shardingStatusStr = function(indent, s) { + // convert from logical indentation to actual num of chars + if (indent == 0) { + indent = 0; + } else if (indent == 1) { + indent = 2; + } else { + indent = (indent - 1) * 8; + } + return indentStr(indent, s) + "\n"; +}; + function printShardingStatus(configDB, verbose) { // configDB is a DB object that contains the sharding metadata of interest. // Defaults to the db named "config" on the current connection. @@ -549,15 +561,15 @@ function printShardingStatus(configDB, verbose) { } var raw = ""; - var output = function(s) { - raw += s + "\n"; + var output = function(indent, s) { + raw += sh._shardingStatusStr(indent, s); }; - output("--- Sharding Status --- "); - output(" sharding version: " + tojson(configDB.getCollection("version").findOne())); + output(0, "--- Sharding Status --- "); + output(1, "sharding version: " + tojson(configDB.getCollection("version").findOne())); - output(" shards:"); + output(1, "shards:"); configDB.shards.find().sort({_id: 1}).forEach(function(z) { - output("\t" + tojsononeline(z)); + output(2, tojsononeline(z)); }); // (most recently) active mongoses @@ -575,9 +587,9 @@ function printShardingStatus(configDB, verbose) { } } - output(" " + mongosAdjective + " mongoses:"); + output(1, mongosAdjective + " mongoses:"); if (mostRecentMongosTime === null) { - output("\tnone"); + output(2, "none"); } else { var recentMongosQuery = { ping: { @@ -593,7 +605,7 @@ function printShardingStatus(configDB, verbose) { configDB.mongos.find(recentMongosQuery) .sort({ping: -1}) .forEach(function(z) { - output("\t" + tojsononeline(z)); + output(2, tojsononeline(z)); }); } else { configDB.mongos.aggregate([ @@ -602,18 +614,18 @@ function printShardingStatus(configDB, verbose) { {$sort: {num: -1}} ]) .forEach(function(z) { - output("\t" + tojson(z._id) + " : " + z.num); + output(2, tojson(z._id) + " : " + z.num); }); } } - output(" balancer:"); + output(1, "balancer:"); // Is the balancer currently enabled - output("\tCurrently enabled: " + (sh.getBalancerState(configDB) ? "yes" : "no")); + output(2, "Currently enabled: " + (sh.getBalancerState(configDB) ? "yes" : "no")); // Is the balancer currently active - output("\tCurrently running: " + (sh.isBalancerRunning(configDB) ? "yes" : "no")); + output(2, "Currently running: " + (sh.isBalancerRunning(configDB) ? "yes" : "no")); // Output details of the current balancer round var balLock = sh.getBalancerLockDetails(configDB); @@ -624,16 +636,17 @@ function printShardingStatus(configDB, verbose) { // Output the balancer window var balSettings = sh.getBalancerWindow(configDB); if (balSettings) { - output("\t\tBalancer active window is set between " + balSettings.start + " and " + - balSettings.stop + " server local time"); + output(3, + "Balancer active window is set between " + balSettings.start + " and " + + balSettings.stop + " server local time"); } // Output the list of active migrations var activeMigrations = sh.getActiveMigrations(configDB); if (activeMigrations.length > 0) { - output("\tCollections with active migrations: "); + output(2, "Collections with active migrations: "); activeMigrations.forEach(function(migration) { - output("\t\t" + migration._id + " started at " + migration.when); + output(3, migration._id + " started at " + migration.when); }); } @@ -654,31 +667,32 @@ function printShardingStatus(configDB, verbose) { // Review config.actionlog for errors var actionReport = sh.getRecentFailedRounds(configDB); // Always print the number of failed rounds - output("\tFailed balancer rounds in last 5 attempts: " + actionReport.count); + output(2, "Failed balancer rounds in last 5 attempts: " + actionReport.count); // Only print the errors if there are any if (actionReport.count > 0) { - output("\tLast reported error: " + actionReport.lastErr); - output("\tTime of Reported error: " + actionReport.lastTime); + output(2, "Last reported error: " + actionReport.lastErr); + output(2, "Time of Reported error: " + actionReport.lastTime); } - output("\tMigration Results for the last 24 hours: "); + output(2, "Migration Results for the last 24 hours: "); var migrations = sh.getRecentMigrations(configDB); if (migrations.length > 0) { migrations.forEach(function(x) { if (x._id === "Success") { - output("\t\t" + x.count + " : " + x._id); + output(3, x.count + " : " + x._id); } else { - output("\t\t" + x.count + " : Failed with error '" + x._id + "', from " + - x.from + " to " + x.to); + output(3, + x.count + " : Failed with error '" + x._id + "', from " + x.from + + " to " + x.to); } }); } else { - output("\t\tNo recent migrations"); + output(3, "No recent migrations"); } } - output(" databases:"); + output(1, "databases:"); configDB.databases.find().sort({name: 1}).forEach(function(db) { var truthy = function(value) { return !!value; @@ -694,20 +708,22 @@ function printShardingStatus(configDB, verbose) { return s; }; - output("\t" + tojsononeline(db, "", true)); + output(2, tojsononeline(db, "", true)); if (db.partitioned) { configDB.collections.find({_id: new RegExp("^" + RegExp.escape(db._id) + "\\.")}) .sort({_id: 1}) .forEach(function(coll) { if (!coll.dropped) { - output("\t\t" + coll._id); - output("\t\t\tshard key: " + tojson(coll.key)); - output("\t\t\tunique: " + truthy(coll.unique) + - nonBooleanNote("unique", coll.unique)); - output("\t\t\tbalancing: " + !truthy(coll.noBalance) + - nonBooleanNote("noBalance", coll.noBalance)); - output("\t\t\tchunks:"); + output(3, coll._id); + output(4, "shard key: " + tojson(coll.key)); + output(4, + "unique: " + truthy(coll.unique) + + nonBooleanNote("unique", coll.unique)); + output(4, + "balancing: " + !truthy(coll.noBalance) + + nonBooleanNote("noBalance", coll.noBalance)); + output(4, "chunks:"); res = configDB.chunks .aggregate({$match: {ns: coll._id}}, @@ -718,28 +734,31 @@ function printShardingStatus(configDB, verbose) { var totalChunks = 0; res.forEach(function(z) { totalChunks += z.nChunks; - output("\t\t\t\t" + z.shard + "\t" + z.nChunks); + output(5, z.shard + "\t" + z.nChunks); }); if (totalChunks < 20 || verbose) { configDB.chunks.find({"ns": coll._id}) .sort({min: 1}) .forEach(function(chunk) { - output("\t\t\t" + tojson(chunk.min) + " -->> " + - tojson(chunk.max) + " on : " + chunk.shard + " " + - tojson(chunk.lastmod) + " " + - (chunk.jumbo ? "jumbo " : "")); + output(4, + tojson(chunk.min) + " -->> " + tojson(chunk.max) + + " on : " + chunk.shard + " " + + tojson(chunk.lastmod) + " " + + (chunk.jumbo ? "jumbo " : "")); }); } else { output( - "\t\t\ttoo many chunks to print, use verbose if you want to force print"); + 4, + "too many chunks to print, use verbose if you want to force print"); } configDB.tags.find({ns: coll._id}) .sort({min: 1}) .forEach(function(tag) { - output("\t\t\t tag: " + tag.tag + " " + tojson(tag.min) + - " -->> " + tojson(tag.max)); + output(4, + " tag: " + tag.tag + " " + tojson(tag.min) + " -->> " + + tojson(tag.max)); }); } }); @@ -762,29 +781,29 @@ function printShardingSizes(configDB) { } var raw = ""; - var output = function(s) { - raw += s + "\n"; + var output = function(indent, s) { + raw += sh._shardingStatusStr(indent, s); }; - output("--- Sharding Status --- "); - output(" sharding version: " + tojson(configDB.getCollection("version").findOne())); + output(0, "--- Sharding Sizes --- "); + output(1, "sharding version: " + tojson(configDB.getCollection("version").findOne())); - output(" shards:"); + output(1, "shards:"); var shards = {}; configDB.shards.find().forEach(function(z) { shards[z._id] = new Mongo(z.host); - output(" " + tojson(z)); + output(2, tojson(z)); }); var saveDB = db; - output(" databases:"); + output(1, "databases:"); configDB.databases.find().sort({name: 1}).forEach(function(db) { - output("\t" + tojson(db, "", true)); + output(2, tojson(db, "", true)); if (db.partitioned) { configDB.collections.find({_id: new RegExp("^" + RegExp.escape(db._id) + "\.")}) .sort({_id: 1}) .forEach(function(coll) { - output("\t\t" + coll._id + " chunks:"); + output(3, coll._id + " chunks:"); configDB.chunks.find({"ns": coll._id}) .sort({min: 1}) .forEach(function(chunk) { @@ -798,8 +817,9 @@ function printShardingSizes(configDB) { delete out.millis; delete out.ok; - output("\t\t\t" + tojson(chunk.min) + " -->> " + tojson(chunk.max) + - " on : " + chunk.shard + " " + tojson(out)); + output(4, + tojson(chunk.min) + " -->> " + tojson(chunk.max) + " on : " + + chunk.shard + " " + tojson(out)); }); }); |