diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2017-11-27 18:19:40 -0500 |
---|---|---|
committer | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2017-11-29 20:07:37 -0500 |
commit | 2cc9396586e771a0484a4017bf3f126098818d2b (patch) | |
tree | 66a2201172fd5404dbea3b0344d2d8c8f718b55b /jstests | |
parent | 4174a84257760cae2ea9fdb26e8d3e65feadf253 (diff) | |
download | mongo-2cc9396586e771a0484a4017bf3f126098818d2b.tar.gz |
SERVER-25175 listIndexes command only includes ready indexes
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/noPassthrough/indexbg1.js | 5 | ||||
-rw-r--r-- | jstests/noPassthrough/indexbg2.js | 5 | ||||
-rw-r--r-- | jstests/noPassthrough/libs/index_build.js | 13 | ||||
-rw-r--r-- | jstests/noPassthrough/list_indexes_only_ready_indexes.js | 51 | ||||
-rw-r--r-- | jstests/noPassthroughWithMongod/indexbg_drop.js | 8 |
5 files changed, 72 insertions, 10 deletions
diff --git a/jstests/noPassthrough/indexbg1.js b/jstests/noPassthrough/indexbg1.js index d8a9c8e56a0..ae26b4a0494 100644 --- a/jstests/noPassthrough/indexbg1.js +++ b/jstests/noPassthrough/indexbg1.js @@ -2,6 +2,9 @@ (function() { "use strict"; + + load("jstests/noPassthrough/libs/index_build.js"); + const conn = MongoRunner.runMongod({smallfiles: "", nojournal: ""}); assert.neq(null, conn, "mongod failed to start."); var db = conn.getDB("test"); @@ -57,7 +60,7 @@ // wait for indexing to start print("wait for indexing to start"); assert.soon(function() { - return 2 === t.getIndexes().length; + return getIndexBuildOpId(db) != -1; }, "no index created", 30000, 50); print("started."); sleep(1000); // there is a race between when the index build shows up in curop and diff --git a/jstests/noPassthrough/indexbg2.js b/jstests/noPassthrough/indexbg2.js index cc89115cdd3..4320db072a1 100644 --- a/jstests/noPassthrough/indexbg2.js +++ b/jstests/noPassthrough/indexbg2.js @@ -2,6 +2,9 @@ (function() { "use strict"; + + load("jstests/noPassthrough/libs/index_build.js"); + const conn = MongoRunner.runMongod({smallfiles: "", nojournal: ""}); assert.neq(null, conn, "mongod failed to start."); var db = conn.getDB("test"); @@ -55,7 +58,7 @@ try { // wait for indexing to start assert.soon(function() { - return 2 === t.getIndexes().length; + return getIndexBuildOpId(db) != -1; }, "no index created", 30000, 50); assert.writeError(t.save({i: 0, n: true})); // duplicate key violation assert.writeOK(t.save({i: size - 1, n: true})); diff --git a/jstests/noPassthrough/libs/index_build.js b/jstests/noPassthrough/libs/index_build.js new file mode 100644 index 00000000000..3bb78889055 --- /dev/null +++ b/jstests/noPassthrough/libs/index_build.js @@ -0,0 +1,13 @@ +// Returns the op id for the running index build, or -1 if there is no current index build. +function getIndexBuildOpId(db) { + const result = db.currentOp(); + assert.commandWorked(result); + let indexBuildOpId = -1; + + result.inprog.forEach(function(op) { + if (op.op == 'command' && 'createIndexes' in op.command) { + indexBuildOpId = op.opid; + } + }); + return indexBuildOpId; +} diff --git a/jstests/noPassthrough/list_indexes_only_ready_indexes.js b/jstests/noPassthrough/list_indexes_only_ready_indexes.js new file mode 100644 index 00000000000..c1748792675 --- /dev/null +++ b/jstests/noPassthrough/list_indexes_only_ready_indexes.js @@ -0,0 +1,51 @@ +// SERVER-25175: Test the listIndexes command only shows ready indexes. +(function() { + "use strict"; + + load("jstests/noPassthrough/libs/index_build.js"); + + const conn = MongoRunner.runMongod({smallfiles: "", nojournal: ""}); + assert.neq(null, conn, "mongod was unable to start up"); + + const testDB = conn.getDB("test"); + assert.commandWorked(testDB.dropDatabase()); + + function assertIndexes(coll, numIndexes, indexes) { + let res = coll.runCommand("listIndexes"); + assert.eq(numIndexes, res.cursor.firstBatch.length); + for (var i = 0; i < numIndexes; i++) { + assert.eq(indexes[i], res.cursor.firstBatch[i].name); + } + } + + let coll = testDB.list_indexes_only_ready_indexes; + coll.drop(); + assert.commandWorked(testDB.createCollection(coll.getName())); + assertIndexes(coll, 1, ["_id_"]); + assert.commandWorked(coll.createIndex({a: 1})); + assertIndexes(coll, 2, ["_id_", "a_1"]); + + assert.commandWorked( + testDB.adminCommand({configureFailPoint: 'hangAfterStartingIndexBuild', mode: 'alwaysOn'})); + const createIdx = startParallelShell( + "let coll = db.getSiblingDB('test').list_indexes_only_ready_indexes;" + + "assert.commandWorked(coll.createIndex({ b: 1 }, { background: true }));", + conn.port); + assert.soon(function() { + return getIndexBuildOpId(testDB) != -1; + }, "Index build operation not found after starting via parallelShell"); + + // Verify there is no third index. + assertIndexes(coll, 2, ["_id_", "a_1"]); + + assert.commandWorked( + testDB.adminCommand({configureFailPoint: 'hangAfterStartingIndexBuild', mode: 'off'})); + // Wait for the index build to stop. + assert.soon(function() { + return getIndexBuildOpId(testDB) == -1; + }); + const exitCode = createIdx(); + assert.eq(0, exitCode, 'expected shell to exit cleanly'); + + assertIndexes(coll, 3, ["_id_", "a_1", "b_1"]); +}()); diff --git a/jstests/noPassthroughWithMongod/indexbg_drop.js b/jstests/noPassthroughWithMongod/indexbg_drop.js index d7cbb4a781b..df346f13c9b 100644 --- a/jstests/noPassthroughWithMongod/indexbg_drop.js +++ b/jstests/noPassthroughWithMongod/indexbg_drop.js @@ -56,14 +56,6 @@ jsTest.log("Starting background indexing for test of: " + tojson(dc)); masterDB.getCollection(collection).ensureIndex({b: 1}); masterDB.getCollection(collection).ensureIndex({i: 1}, {background: true}); -assert.eq(3, masterDB.getCollection(collection).getIndexes().length); - -// Wait for the secondary to get the index entry -assert.soon(function() { - return 3 == secondDB.getCollection(collection).getIndexes().length; -}, "index not created on secondary (prior to drop)", 240000); - -jsTest.log("Index created and index entry exists on secondary"); // make sure the index build has started on secondary assert.soon(function() { |