From 046a1a3f14c42dc52f1d83c9e2fdb6127783a8d6 Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Tue, 18 Feb 2020 13:11:28 -0500 Subject: SERVER-45944 disallow downgrade to 4.2 if there is an index build in progress --- jstests/noPassthrough/index_downgrade_fcv.js | 4 +++- .../set_feature_compatibility_version_command.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/jstests/noPassthrough/index_downgrade_fcv.js b/jstests/noPassthrough/index_downgrade_fcv.js index bbc29a5664b..a999feac75a 100644 --- a/jstests/noPassthrough/index_downgrade_fcv.js +++ b/jstests/noPassthrough/index_downgrade_fcv.js @@ -36,7 +36,9 @@ IndexBuildTest.waitForIndexBuildToScanCollection(testDB, coll.getName(), 'a_1'); // Downgrade the primary using the setFeatureCompatibilityVersion command. try { - assert.commandWorked(primary.adminCommand({setFeatureCompatibilityVersion: lastStableFCV})); + assert.commandFailedWithCode( + primary.adminCommand({setFeatureCompatibilityVersion: lastStableFCV}), + ErrorCodes.ConflictingOperationInProgress); } finally { IndexBuildTest.resumeIndexBuilds(primary); } diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index 6dc12d4af3f..7904e8db864 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -43,6 +43,7 @@ #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" +#include "mongo/db/index_builds_coordinator.h" #include "mongo/db/namespace_string.h" #include "mongo/db/ops/write_ops.h" #include "mongo/db/read_write_concern_defaults.h" @@ -289,6 +290,20 @@ public: } } } + + // Two phase index builds are only supported in 4.4. If the user tries to downgrade the + // cluster to FCV42, they must first wait for all index builds to run to completion, or + // abort the index builds (using the dropIndexes command). + if (auto indexBuildsCoord = IndexBuildsCoordinator::get(opCtx)) { + auto numIndexBuilds = indexBuildsCoord->getActiveIndexBuildCount(opCtx); + uassert( + ErrorCodes::ConflictingOperationInProgress, + str::stream() + << "Cannot downgrade the cluster when there are index builds in progress: " + << numIndexBuilds, + numIndexBuilds == 0U); + } + FeatureCompatibilityVersion::setTargetDowngrade(opCtx); { -- cgit v1.2.1