summaryrefslogtreecommitdiff
path: root/jstests/sharding/stats.js
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2015-01-15 22:06:33 -0500
committerBenety Goh <benety@mongodb.com>2015-01-16 14:37:06 -0500
commite0e780a5e3e4c717daa6a44ba19f3f2329ea7cee (patch)
tree9ef5b8ab112fcad777f6c80b6b028342925dbc6a /jstests/sharding/stats.js
parent1aa110cc7fc83517a5a428feb7783cd37375226c (diff)
downloadmongo-e0e780a5e3e4c717daa6a44ba19f3f2329ea7cee.tar.gz
SERVER-16870 db.collectons.stats() supports indexDetails on sharded collections
Diffstat (limited to 'jstests/sharding/stats.js')
-rw-r--r--jstests/sharding/stats.js76
1 files changed, 73 insertions, 3 deletions
diff --git a/jstests/sharding/stats.js b/jstests/sharding/stats.js
index 8aa3ae0f3c5..41fa2534cf7 100644
--- a/jstests/sharding/stats.js
+++ b/jstests/sharding/stats.js
@@ -13,6 +13,10 @@ function numKeys(o){
return num;
}
+db.foo.drop();
+assert.commandFailed(db.foo.stats(),
+ 'db.collection.stats() should fail on non-existent collection');
+
// ---------- load some data -----
// need collections sharded before and after main collection for proper test
@@ -40,6 +44,10 @@ assert.eq( N / 2 , x.shards.shard0000.count , "coll count on shard0000 expected"
assert.eq( N / 2 , x.shards.shard0001.count , "coll count on shard0001 expected" )
assert.eq( a.foo.count() , x.shards.shard0000.count , "coll count on shard0000 match" )
assert.eq( b.foo.count() , x.shards.shard0001.count , "coll count on shard0001 match" )
+assert(!x.shards.shard0000.indexDetails,
+ 'indexDetails should not be present in shard0000: ' + tojson(x.shards.shard0000));
+assert(!x.shards.shard0001.indexDetails,
+ 'indexDetails should not be present in shard0001: ' + tojson(x.shards.shard0001));
a_extras = a.stats().objects - a.foo.count(); // things like system.namespaces and system.indexes
@@ -108,12 +116,74 @@ coll_not_scaled = db.foo.stats();
coll_scaled_512 = db.foo.stats(512);
coll_scaled_1024 = db.foo.stats(1024);
-for (var shard in coll_not_scaled.raw) {
- collStatComp(coll_not_scaled.raw[shard], coll_scaled_512.raw[shard], 512, false);
- collStatComp(coll_not_scaled.raw[shard], coll_scaled_1024.raw[shard], 1024, false);
+for (var shard in coll_not_scaled.shards) {
+ collStatComp(coll_not_scaled.shards[shard], coll_scaled_512.shards[shard], 512, false);
+ collStatComp(coll_not_scaled.shards[shard], coll_scaled_1024.shards[shard], 1024, false);
}
collStatComp(coll_not_scaled, coll_scaled_512, 512, true);
collStatComp(coll_not_scaled, coll_scaled_1024, 1024, true);
+/* db.collection.stats() - indexDetails tests */
+(function() {
+ var t = db.foo;
+
+ assert.commandWorked(t.ensureIndex({a: 1}));
+ assert.eq(2, t.getIndexes().length);
+
+ var isWiredTiger = (jsTest.options().storageEngine == "wiredTiger");
+
+ var stats = assert.commandWorked(t.stats({indexDetails: true}));
+ var shardName;
+ var shardStats;
+ for (shardName in stats.shards) {
+ shardStats = stats.shards[shardName];
+ assert(shardStats.indexDetails,
+ 'indexDetails missing for ' + shardName + ': ' + tojson(shardStats));
+ if (isWiredTiger) {
+ assert.eq(t.getIndexes().length, Object.keys(shardStats.indexDetails).length,
+ 'incorrect number of entries in WiredTiger indexDetails: ' +
+ tojson(shardStats));
+ }
+ }
+
+ function getIndexName(indexKey) {
+ var indexes = t.getIndexes().filter(function(doc) {
+ return friendlyEqual(doc.key, indexKey);
+ });
+ assert.eq(1, indexes.length, tojson(indexKey) + ' not found in getIndexes() result: ' +
+ tojson(t.getIndexes()));
+ return indexes[0].name;
+ }
+
+ function checkIndexDetails(options, indexName) {
+ var stats = assert.commandWorked(t.stats(options));
+ for (shardName in stats.shards) {
+ shardStats = stats.shards[shardName];
+ assert(shardStats.indexDetails,
+ 'indexDetails missing from db.collection.stats(' + tojson(options) +
+ ').shards[' + shardName + '] result: ' + tojson(shardStats));
+ // Currently, indexDetails is only supported with WiredTiger.
+ if (isWiredTiger) {
+ assert.eq(1, Object.keys(shardStats.indexDetails).length,
+ 'WiredTiger indexDetails must have exactly one entry');
+ assert(shardStats.indexDetails[indexName],
+ indexName + ' missing from WiredTiger indexDetails: ' +
+ tojson(shardStats.indexDetails));
+ assert.neq(0, Object.keys(shardStats.indexDetails[indexName]).length,
+ indexName + ' exists in indexDetails but contains no information: ' +
+ tojson(shardStats.indexDetails));
+ }
+ }
+ }
+
+ // indexDetailsKey - show indexDetails results for this index key only.
+ var indexKey = {a: 1};
+ var indexName = getIndexName(indexKey);
+ checkIndexDetails({indexDetails: true, indexDetailsKey: indexKey}, indexName);
+
+ // indexDetailsName - show indexDetails results for this index name only.
+ checkIndexDetails({indexDetails: true, indexDetailsName: indexName}, indexName);
+}());
+
s.stop()