diff options
author | Mihai Andrei <mihai.andrei@mongodb.com> | 2019-12-16 14:47:09 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-12-16 14:47:09 +0000 |
commit | 5e5d712c2ef0e91f93dc4bb4dd78006d1219bba2 (patch) | |
tree | ea9475b4850f3fd100b5dc4335634356c65f7e08 /jstests | |
parent | 817a57416b3069ae4738e5bd472d443a6b12f215 (diff) | |
download | mongo-5e5d712c2ef0e91f93dc4bb4dd78006d1219bba2.tar.gz |
SERVER-44915 Extend output to include full index options and shard name
Diffstat (limited to 'jstests')
3 files changed, 112 insertions, 10 deletions
diff --git a/jstests/aggregation/sources/indexStats/verify_index_stats_output.js b/jstests/aggregation/sources/indexStats/verify_index_stats_output.js new file mode 100644 index 00000000000..0209cc3e300 --- /dev/null +++ b/jstests/aggregation/sources/indexStats/verify_index_stats_output.js @@ -0,0 +1,84 @@ +/** + * Basic test to verify the output of $indexStats. + * + * @tags: [assumes_read_concern_unchanged, requires_wiredtiger, do_not_wrap_aggregations_in_facets] + */ +(function() { +"use strict"; +load('jstests/noPassthrough/libs/index_build.js'); // for waitForIndexBuildToStart(). +load('jstests/libs/fixture_helpers.js'); // for runCommandOnEachPrimary. +load("jstests/aggregation/extras/utils.js"); // for resultsEq. + +const coll = db.index_stats_output; +coll.drop(); + +let bulk = coll.initializeUnorderedBulkOp(); +const nDocs = 100; +for (let i = 0; i < nDocs; i++) { + bulk.insert({_id: i, a: i}); +} +assert.commandWorked(bulk.execute()); + +const indexKey = { + _id: 1, + a: 1 +}; +const indexName = "testIndex"; + +// Verify that in progress index builds report matching 'spec' and 'building: true' in the output of +// $indexStats. +FixtureHelpers.runCommandOnEachPrimary({ + db: db.getSiblingDB("admin"), + cmdObj: {configureFailPoint: "hangAfterStartingIndexBuild", mode: "alwaysOn"} +}); + +const join = startParallelShell(() => { + const indexName = "testIndex"; + const indexKey = {_id: 1, a: 1}; + assert.commandWorked(db.index_stats_output.createIndex(indexKey, {unique: 1, name: indexName})); +}); + +IndexBuildTest.waitForIndexBuildToStart(db, coll.getName(), indexName); + +let pausedOutput = coll.aggregate([{$indexStats: {}}, {$match: {name: indexName}}]).toArray(); + +let allShards = []; +let shardsFound = []; +db.getSiblingDB("config").shards.find().forEach(function(shard) { + allShards.push(shard._id); +}); + +for (const indexStats of pausedOutput) { + assert.hasFields(indexStats, ["building", "spec"]); + // Each index should report building: true since the index build was paused. + assert.eq(indexStats["building"], true); + // Each index should report a spec that matches the parameters passed to createIndex(). + let spec = indexStats["spec"]; + assert.hasFields(spec, ["unique", "name", "key"]); + assert.eq(spec["unique"], true); + assert.eq(spec["name"], indexName); + assert.eq(spec["key"], indexKey); + // In the sharded case, record the reported shard names and compare them against the + // names of known shards. + if (indexStats.hasOwnProperty("shard")) { + shardsFound.push(indexStats["shard"]); + } +} + +for (const shard of shardsFound) { + assert.contains(shard, allShards); +} + +FixtureHelpers.runCommandOnEachPrimary({ + db: db.getSiblingDB("admin"), + cmdObj: {configureFailPoint: "hangAfterStartingIndexBuild", mode: "off"} +}); +join(); + +// Verify that there is no 'building' field in the $indexStats output for our created index once the +// index build is complete. +let finishedOutput = coll.aggregate([{$indexStats: {}}, {$match: {name: indexName}}]).toArray(); +for (const indexStats of finishedOutput) { + assert(!indexStats.hasOwnProperty("building"), tojson(indexStats)); +} +})();
\ No newline at end of file diff --git a/jstests/libs/override_methods/detect_spawning_own_mongod.js b/jstests/libs/override_methods/detect_spawning_own_mongod.js index 42b95a58d51..3e542f048ec 100644 --- a/jstests/libs/override_methods/detect_spawning_own_mongod.js +++ b/jstests/libs/override_methods/detect_spawning_own_mongod.js @@ -27,12 +27,23 @@ const STOverrideConstructor = function() { // still keep any static properties it has. ShardingTest = Object.assign(STOverrideConstructor, ShardingTest); -const RSTOverrideConstructor = function() { - throw new Error("Detected ReplSetTest() call in js test from passthrough suite. " + - "Consider moving the test to one of the jstests/noPassthrough/, " + - "jstests/replsets/, or jstests/sharding/ directories."); +const RSTOverrideConstructor = function(opts) { + if (typeof opts !== 'string' && !(opts instanceof String)) { + throw new Error("Detected ReplSetTest() call in js test from passthrough suite. " + + "Consider moving the test to one of the jstests/noPassthrough/, " + + "jstests/replsets/, or jstests/sharding/ directories."); + } else { + // If we are creating a ReplSetTest using a pre-existing replica set, simply reassign + // the old constructor and invoke it. + Object.assign(this, ReplSetTest.overridenConstructor); + return this.overridenConstructor(opts); + } }; +// Capture the old constructor for ReplSetTest in the event that the call to ReplSetTest() is +// attempting to reconstruct a replica set and not creating a new one. +ReplSetTest.overridenConstructor = ReplSetTest; + // Same as the above Object.assign() call. In particular, we want to preserve the // ReplSetTest.kDefaultTimeoutMS property, which should be accessible to tests in the // passthrough suite. diff --git a/jstests/noPassthrough/libs/index_build.js b/jstests/noPassthrough/libs/index_build.js index e9d0c17191d..e60dabeb72c 100644 --- a/jstests/noPassthrough/libs/index_build.js +++ b/jstests/noPassthrough/libs/index_build.js @@ -19,22 +19,29 @@ class IndexBuildTest { * Accepts optional filter that can be used to customize the db.currentOp() query. */ static getIndexBuildOpId(database, collectionName, indexName, filter) { - const result = database.currentOp(filter || true); - assert.commandWorked(result); + let pipeline = [{$currentOp: {allUsers: true}}]; + if (filter) { + pipeline.push({$match: filter}); + } + const result = database.getSiblingDB("admin") + .aggregate(pipeline, {readConcern: {level: "local"}}) + .toArray(); let indexBuildOpId = -1; let indexBuildObj = {}; let indexBuildNamespace = ""; - result.inprog.forEach(function(op) { + result.forEach(function(op) { if (op.op != 'command') { return; } - if (op.command.createIndexes === undefined) { + const cmdBody = op.command; + + if (cmdBody.createIndexes === undefined) { return; } // If no collection is provided, return any index build. - if (!collectionName || op.command.createIndexes === collectionName) { - op.command.indexes.forEach((index) => { + if (!collectionName || cmdBody.createIndexes === collectionName) { + cmdBody.indexes.forEach((index) => { if (!indexName || index.name === indexName) { indexBuildOpId = op.opid; indexBuildObj = index; |