summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Pulo <kevin.pulo@mongodb.com>2015-07-13 23:22:35 +1000
committerKevin Pulo <kevin.pulo@mongodb.com>2015-07-13 23:22:35 +1000
commit63863aefa21b33e6f84b8b466f70581dd921dba7 (patch)
tree809e4b4bcfbaa1907a34c5e43ce9e12ec4ead835
parent48432412d79d0712367837a12637d3682c04fddb (diff)
downloadmongo-63863aefa21b33e6f84b8b466f70581dd921dba7.tar.gz
SERVER-18796: sh.status() show 'dropped:false' colls again
Specifically: * printShardingStatus()/sh.status() show collections with missing 'dropped' field * Don't omit 'dropped:false' in config.collections * Add jstest for basic validation of printShardingStatus() output
-rw-r--r--jstests/sharding/mrShardedOutputAuth.js2
-rw-r--r--jstests/sharding/printShardingStatus.js64
-rw-r--r--src/mongo/s/catalog/type_collection.cpp5
-rw-r--r--src/mongo/shell/shardingtest.js2
4 files changed, 67 insertions, 6 deletions
diff --git a/jstests/sharding/mrShardedOutputAuth.js b/jstests/sharding/mrShardedOutputAuth.js
index 36c1ace4966..cf1bf612085 100644
--- a/jstests/sharding/mrShardedOutputAuth.js
+++ b/jstests/sharding/mrShardedOutputAuth.js
@@ -34,7 +34,7 @@ function doMapReduce(connection, outputDb) {
function assertSuccess(configDb, outputDb) {
adminDb.printShardingStatus();
assert.eq(outputDb.numbers_out.count(), 50, "map/reduce failed");
- assert.eq(configDb.collections.findOne().dropped, undefined, "no sharded collections");
+ assert( ! configDb.collections.findOne().dropped, "no sharded collections");
}
function assertFailure(configDb, outputDb) {
diff --git a/jstests/sharding/printShardingStatus.js b/jstests/sharding/printShardingStatus.js
new file mode 100644
index 00000000000..5307691f6e0
--- /dev/null
+++ b/jstests/sharding/printShardingStatus.js
@@ -0,0 +1,64 @@
+// Check that the output from printShardingStatus() (aka sh.status())
+// contains important information that it should, like the major section
+// headings and the names of sharded collections and their shard keys.
+
+
+(function () {
+
+
+// SERVER-19368 to move this into utils.js
+// jstests/auth/show_log_auth.js does something similar and could also benefit from this
+print.captureAllOutput = function (fn, args) {
+ var res = {};
+ res.output = [];
+ var __orig_print = print;
+ print = function () {
+ Array.prototype.push.apply(res.output, Array.prototype.slice.call(arguments).join(" ").split("\n"));
+ };
+ res.result = fn.apply(undefined, args);
+ print = __orig_print;
+ return res;
+}
+
+// SERVER-19369 to move this into types.js next to startsWith() and endsWith()
+// Polyfill a default implementation of String.includes() (defined in ES6)
+if (typeof String.prototype.includes === 'undefined') {
+ String.prototype.includes = function(it) { return this.indexOf(it) >= 0; };
+}
+
+
+var st = new ShardingTest({ shards: 1, mongos: 1, config: 1, other: { smallfiles: true } });
+
+var mongos = st.s0;
+var admin = mongos.getDB( "admin" );
+
+var dbName = "thisIsTheDatabase";
+var collName = "thisIsTheCollection";
+var shardKeyName = "thisIsTheShardKey";
+var nsName = dbName + "." + collName;
+
+assert.commandWorked( admin.runCommand({ enableSharding: dbName }) );
+var key = {};
+key[shardKeyName] = 1;
+assert.commandWorked( admin.runCommand({ shardCollection: nsName, key: key }) );
+
+var res = print.captureAllOutput( function () { return st.printShardingStatus(); } );
+var output = res.output.join("\n");
+jsTestLog(output);
+
+
+function assertPresentInOutput(content, what) {
+ assert(output.includes(content), what + " \"" + content + "\" not present in output of printShardingStatus()");
+}
+
+assertPresentInOutput("shards:", "section header");
+assertPresentInOutput("databases:", "section header");
+assertPresentInOutput("balancer:", "section header");
+
+assertPresentInOutput(dbName, "database");
+assertPresentInOutput(collName, "collection");
+assertPresentInOutput(shardKeyName, "shard key");
+
+st.stop();
+
+})();
diff --git a/src/mongo/s/catalog/type_collection.cpp b/src/mongo/s/catalog/type_collection.cpp
index 7a125e52062..1d466314edb 100644
--- a/src/mongo/s/catalog/type_collection.cpp
+++ b/src/mongo/s/catalog/type_collection.cpp
@@ -180,14 +180,11 @@ BSONObj CollectionType::toBSON() const {
}
builder.append(epoch.name(), _epoch.get_value_or(OID()));
builder.append(updatedAt.name(), _updatedAt.get_value_or(Date_t()));
+ builder.append(dropped.name(), _dropped.get_value_or(false));
// These fields are optional, so do not include them in the metadata for the purposes of
// consuming less space on the config servers.
- if (_dropped.is_initialized()) {
- builder.append(dropped.name(), _dropped.get());
- }
-
if (_keyPattern.is_initialized()) {
builder.append(keyPattern.name(), _keyPattern->toBSON());
}
diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index cc1d85479b5..a24949f58c3 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -795,7 +795,7 @@ printShardingStatus = function( configDB , verbose ){
configDB.collections.find( { _id : new RegExp( "^" +
RegExp.escape(db._id) + "\\." ) } ).
sort( { _id : 1 } ).forEach( function( coll ){
- if ( coll.dropped == false ){
+ if ( ! coll.dropped ){
output( "\t\t" + coll._id );
output( "\t\t\tshard key: " + tojson(coll.key) );
output( "\t\t\tchunks:" );