diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2019-09-24 18:59:52 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-24 18:59:52 +0000 |
commit | 393c9d79b9f8e0cd39c652ab7784f2c4977d5ecd (patch) | |
tree | 378a9506cfaf827d5414ec70168f44f21ce0781e | |
parent | 1a3936b3ee365de5dde80e440c01fa6e868a1a54 (diff) | |
download | mongo-393c9d79b9f8e0cd39c652ab7784f2c4977d5ecd.tar.gz |
SERVER-42367 Disallow refineCollectionShardKey in FCV < 4.4
-rw-r--r-- | jstests/multiVersion/refine_collection_shard_key_fcv.js | 36 | ||||
-rw-r--r-- | src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp | 7 |
2 files changed, 43 insertions, 0 deletions
diff --git a/jstests/multiVersion/refine_collection_shard_key_fcv.js b/jstests/multiVersion/refine_collection_shard_key_fcv.js new file mode 100644 index 00000000000..1bdf5ca6461 --- /dev/null +++ b/jstests/multiVersion/refine_collection_shard_key_fcv.js @@ -0,0 +1,36 @@ +// Verifies refineCollectionShardKey can only be run when a cluster's FCV is 4.4. + +(function() { +"use strict"; + +const dbName = "test"; +const collName = "foo"; +const ns = dbName + '.' + collName; + +const st = new ShardingTest({shards: 1}); +const configAdminDB = st.configRS.getPrimary().getDB("admin"); + +assert.commandWorked(st.s.adminCommand({enableSharding: dbName})); +assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {_id: 1}})); + +// Create an index that can be used for the following shard key refines. +assert.commandWorked(st.s.getCollection(ns).createIndex({_id: 1, x: 1, y: 1})); + +// Refining a shard key succeeds in FCV 4.4. +checkFCV(configAdminDB, latestFCV); +assert.commandWorked(st.s.adminCommand({refineCollectionShardKey: ns, key: {_id: 1, x: 1}})); + +// Refining a shard key fails in FCV 4.2. +assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: lastStableFCV})); +checkFCV(configAdminDB, lastStableFCV); +assert.commandFailedWithCode( + st.s.adminCommand({refineCollectionShardKey: ns, key: {_id: 1, x: 1, y: 1}}), + ErrorCodes.CommandNotSupported); + +// Refining a shard key succeeds after upgrading back to FCV 4.4. +assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: latestFCV})); +checkFCV(configAdminDB, latestFCV); +assert.commandWorked(st.s.adminCommand({refineCollectionShardKey: ns, key: {_id: 1, x: 1, y: 1}})); + +st.stop(); +}()); diff --git a/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp b/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp index 0020ae529b4..3b6a9337014 100644 --- a/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp +++ b/src/mongo/db/s/config/configsvr_refine_collection_shard_key_command.cpp @@ -37,6 +37,7 @@ #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/s/config/sharding_catalog_manager.h" #include "mongo/db/s/shard_key_util.h" +#include "mongo/db/server_options.h" #include "mongo/s/catalog/dist_lock_manager.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/refine_collection_shard_key_gen.h" @@ -64,6 +65,12 @@ public: "refineCollectionShardKey must be called with majority writeConcern", opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority); + uassert(ErrorCodes::CommandNotSupported, + "'refineCollectionShardKey' is only supported in feature compatibility version " + "4.4", + serverGlobalParams.featureCompatibility.getVersion() == + ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44); + // Set the operation context read concern level to local for reads into the config // database. repl::ReadConcernArgs::get(opCtx) = |