diff options
author | Benety Goh <benety@mongodb.com> | 2020-02-18 13:11:28 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-02-18 19:11:39 +0000 |
commit | 046a1a3f14c42dc52f1d83c9e2fdb6127783a8d6 (patch) | |
tree | b4606169defcab3151bba4850f1d1a2502207b0a | |
parent | ad8f814bcac53e273acb563e2f96264a9bb973ab (diff) | |
download | mongo-046a1a3f14c42dc52f1d83c9e2fdb6127783a8d6.tar.gz |
SERVER-45944 disallow downgrade to 4.2 if there is an index build in progress
-rw-r--r-- | jstests/noPassthrough/index_downgrade_fcv.js | 4 | ||||
-rw-r--r-- | src/mongo/db/commands/set_feature_compatibility_version_command.cpp | 15 |
2 files changed, 18 insertions, 1 deletions
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); { |