From 159771fa2fd4c014fddead79af4025ffac1eab54 Mon Sep 17 00:00:00 2001 From: Ted Tuckman Date: Mon, 23 Mar 2020 15:38:14 -0400 Subject: [PATCH] SERVER-46649 Fix out_drop_temp_collections.js to work with two phase index builds --- .../noPassthrough/out_drop_temp_collection.js | 37 +++++++------------ src/mongo/db/pipeline/document_source_out.cpp | 5 --- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/jstests/noPassthrough/out_drop_temp_collection.js b/jstests/noPassthrough/out_drop_temp_collection.js index 0160dc137de..644718f5d6d 100644 --- a/jstests/noPassthrough/out_drop_temp_collection.js +++ b/jstests/noPassthrough/out_drop_temp_collection.js @@ -1,6 +1,5 @@ /** - * Test the behaviour of a dropDatabase command during an aggregation containing $out for single - * phase index builds. + * Test the behavior of a dropDatabase command during an aggregation containing $out. * * @tags: [ * assumes_unsharded_collection, @@ -36,27 +35,22 @@ function runTest(st, testDb, portNum) { mode: "alwaysOn", } }); + res.forEach(cmdResult => assert.commandWorked(cmdResult)); const aggDone = startParallelShell(() => { - const targetColl = db.getSiblingDB("out_drop_temp").out_target_coll; - const pipeline = [{$out: "out_target_coll"}]; - targetColl.aggregate(pipeline); + const targetDB = db.getSiblingDB("out_drop_temp"); + // There are a number of possible error codes depending on configuration and index build + // options. + assert.commandFailed(targetDB.runCommand( + {aggregate: "out_source_coll", pipeline: [{$out: "out_target_coll"}], cursor: {}})); + const collList = assert.commandWorked(targetDB.runCommand({listCollections: 1})); + assert.eq(collList.cursor.firstBatch.length, 0); }, portNum); waitForCurOpByFilter(testDb, {"failpointMsg": failpointName}); - // TODO SERVER-45358 Make it easier to run commands without retrying. - // Tests are run with an override function that retries commands that fail because of a - // background operation. Parallel shells don't automatically have that override, so drop has to - // be run in a parallel shell. - const dropColl = startParallelShell(() => { - const targetDb = db.getSiblingDB("out_drop_temp"); - assert.commandFailedWithCode(targetDb.runCommand({dropDatabase: 1}), [ - ErrorCodes.BackgroundOperationInProgressForDatabase, - ErrorCodes.BackgroundOperationInProgressForNamespace - ]); - }, portNum); - dropColl(); - // The $out should complete once the failpoint is disabled, not fail on index creation. + + assert.commandWorked(testDb.runCommand({dropDatabase: 1})); + FixtureHelpers.runCommandOnEachPrimary({ db: testDb.getSiblingDB("admin"), cmdObj: { @@ -66,13 +60,8 @@ function runTest(st, testDb, portNum) { }); aggDone(); } -const conn = MongoRunner.runMongod({}); -if (IndexBuildTest.supportsTwoPhaseIndexBuild(conn)) { - jsTest.log("Not running because two phase index builds are enabled."); - MongoRunner.stopMongod(conn); - return; -} +const conn = MongoRunner.runMongod({}); runTest(null, conn.getDB("out_drop_temp"), conn.port); MongoRunner.stopMongod(conn); const st = new ShardingTest({shards: 2, mongos: 1, config: 1}); diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp index 7ba4fdc48bf..31d896057cc 100644 --- a/src/mongo/db/pipeline/document_source_out.cpp +++ b/src/mongo/db/pipeline/document_source_out.cpp @@ -127,11 +127,6 @@ void DocumentSourceOut::initialize() { "namespace '{}' is capped so it can't be used for {}"_format(outputNs.ns(), kStageName), _originalOutOptions["capped"].eoo()); - // Create temp collection, copying options from the existing output collection if any. - // Disallows drops and renames on this namespace. This is required to ensure - // 'createIndexesOnEmptyCollection' is called on a namespace that both exists and is empty as - // the function expects. - BackgroundOperation backgroundOp(_tempNs.ns()); { BSONObjBuilder cmd; cmd << "create" << _tempNs.coll();