diff options
| author | Abdul Qadeer <abdul.qadeer@mongodb.com> | 2024-08-03 06:39:17 +0530 |
|---|---|---|
| committer | MongoDB Bot <mongo-bot@mongodb.com> | 2024-08-03 02:00:46 +0000 |
| commit | 59c3eab3edecaebdcd1133fe26303847dbc00453 (patch) | |
| tree | 45c30edaf39cf4807a8c6981160717bbdd24089d | |
| parent | 44eedf3a02875787ab22d5d1d0d2dd3c338e178a (diff) | |
SERVER-92896 Disable FeatureFlagReshardingForTimeseries by default (#25722)r8.0.0-rc16
GitOrigin-RevId: c05b57203089bb276c31ab34dfc538f1da972a36
7 files changed, 103 insertions, 20 deletions
diff --git a/buildscripts/resmokelib/testing/hooks/add_remove_shards.py b/buildscripts/resmokelib/testing/hooks/add_remove_shards.py index 2b1de87f9c0..30481987a10 100644 --- a/buildscripts/resmokelib/testing/hooks/add_remove_shards.py +++ b/buildscripts/resmokelib/testing/hooks/add_remove_shards.py @@ -286,6 +286,8 @@ class _AddRemoveShardThread(threading.Thread): if err.code == self._ILLEGAL_OPERATION: if "Can't move an internal resharding collection" in str(err): return True + if "Can't reshard a timeseries collection" in str(err): + return True for regex in self._UNMOVABLE_NAMESPACE_REGEXES: if re.search(regex, namespace): return True diff --git a/jstests/noPassthrough/move_primary_failpoint.js b/jstests/noPassthrough/move_primary_failpoint.js index 837a8c1ea82..c03995caa29 100644 --- a/jstests/noPassthrough/move_primary_failpoint.js +++ b/jstests/noPassthrough/move_primary_failpoint.js @@ -267,7 +267,7 @@ function testInternalCollections({featureFlagReshardingForTimeseries}) { assert.commandFailedWithCode( st.s.adminCommand( {moveCollection: dbName2 + "." + collName, toShard: st.shard1.shardName}), - ErrorCodes.NotImplemented); + ErrorCodes.IllegalOperation); assert.commandWorked(st.s.adminCommand({movePrimary: dbName2, to: st.shard1.shardName})); } diff --git a/jstests/noPassthrough/out_timeseries_cleans_up_bucket_collections.js b/jstests/noPassthrough/out_timeseries_cleans_up_bucket_collections.js index b734b776137..e11d8c02612 100644 --- a/jstests/noPassthrough/out_timeseries_cleans_up_bucket_collections.js +++ b/jstests/noPassthrough/out_timeseries_cleans_up_bucket_collections.js @@ -9,6 +9,7 @@ * ] */ import {configureFailPoint} from "jstests/libs/fail_point_util.js"; +import {FeatureFlagUtil} from "jstests/libs/feature_flag_util.js"; import {funWithArgs} from "jstests/libs/parallel_shell_helpers.js"; const st = new ShardingTest({shards: 2}); @@ -28,6 +29,10 @@ const kPrimary = st.shard0.shardName; const kOther = st.shard1.shardName; assert.commandWorked(st.s.adminCommand({enableSharding: kDbName, primaryShard: kPrimary})); +// TODO SERVER-93149: Remove 'reshardingForTimeseriesFeatureFlagEnabled' checks. +const reshardingForTimeseriesFeatureFlagEnabled = + FeatureFlagUtil.isPresentAndEnabled(testDB, "FeatureFlagReshardingForTimeseries"); + function listCollections(collName) { return testDB.getCollectionNames().filter(coll => coll === collName); } @@ -140,8 +145,10 @@ function testReplacingExistingCollectionOnSameShard(shard) { // same shard, but the view will always exist on the primary shard. assert.commandWorked(testDB.runCommand({create: kOutCollName, timeseries: {timeField: "t"}})); assert.commandWorked(testDB[kOutCollName].insert({a: 1, t: ISODate()})); - assert.commandWorked( - st.s.adminCommand({moveCollection: testDB[kOutCollName].getFullName(), toShard: shard})); + if (reshardingForTimeseriesFeatureFlagEnabled) { + assert.commandWorked(st.s.adminCommand( + {moveCollection: testDB[kOutCollName].getFullName(), toShard: shard})); + } let bucketCollections = listCollections(kOutBucketsCollName); assert.eq(1, bucketCollections.length, bucketCollections); @@ -161,11 +168,13 @@ function testReplacingExistingCollectionOnSameShard(shard) { } testReplacingExistingCollectionOnSameShard(kPrimary); -testReplacingExistingCollectionOnSameShard(kOther); +if (reshardingForTimeseriesFeatureFlagEnabled) { + testReplacingExistingCollectionOnSameShard(kOther); +} // Validates $out should not clean up the buckets collection if the command is interrupted when the // view exists. The source and output collections will be on different shards. -(function testReplacingExistingCollectionOnDifferentShard() { +function testReplacingExistingCollectionOnDifferentShard() { dropCollections(); // Create the source and foreign collection on the non-primary shard. @@ -222,6 +231,10 @@ testReplacingExistingCollectionOnSameShard(kOther); assert.eq(1, bucketCollections.length, bucketCollections); let view = listCollections(kOutCollName); assert.eq(1, view.length, view); -})(); +} + +if (reshardingForTimeseriesFeatureFlagEnabled) { + testReplacingExistingCollectionOnDifferentShard(); +} st.stop(); diff --git a/jstests/noPassthrough/timeseries/timeseries_resharding_disabled.js b/jstests/noPassthrough/timeseries/timeseries_resharding_disabled.js new file mode 100644 index 00000000000..cd3dc52e719 --- /dev/null +++ b/jstests/noPassthrough/timeseries/timeseries_resharding_disabled.js @@ -0,0 +1,48 @@ +/* + * Tests that moveCollection, reshardCollection and unshardCollection fail for timeseries + * when FeatureFlagReshardingForTimeseries is disabled. + * + * @tags: [ + * requires_timeseries + * ] + */ + +import {FeatureFlagUtil} from "jstests/libs/feature_flag_util.js"; + +const st = new ShardingTest({shards: 2}); + +const kDbName = jsTestName(); +const kCollName = 'test'; +const kFullName = kDbName + '.' + kCollName; +const testDB = st.s.getDB(kDbName); + +function runTest() { + const kPrimary = st.shard0.shardName; + const kOther = st.shard1.shardName; + + assert.commandWorked(st.s.adminCommand({enableSharding: kDbName, primaryShard: kPrimary})); + assert.commandWorked(testDB.runCommand({create: kCollName, timeseries: {timeField: "t"}})); + assert.commandWorked(testDB[kCollName].insert({a: 1, t: ISODate()})); + + assert.commandFailedWithCode(st.s.adminCommand({moveCollection: kFullName, toShard: kOther}), + ErrorCodes.IllegalOperation); + + assert.commandFailedWithCode(st.s.adminCommand({ + reshardCollection: kFullName, + key: {b: 1}, + shardDistribution: [ + {shard: kPrimary, min: {newKey: MinKey}, max: {newKey: 0}}, + {shard: kOther, min: {newKey: 0}, max: {newKey: MaxKey}} + ] + }), + ErrorCodes.IllegalOperation); + + assert.commandFailedWithCode(st.s.adminCommand({unshardCollection: kFullName, toShard: kOther}), + ErrorCodes.IllegalOperation); +} + +if (!FeatureFlagUtil.isEnabled(testDB, "ReshardingForTimeseries")) { + runTest(); +} + +st.stop(); diff --git a/jstests/sharding/timeseries_sharding_admin_commands.js b/jstests/sharding/timeseries_sharding_admin_commands.js index c187811b38c..3bf47236b3c 100644 --- a/jstests/sharding/timeseries_sharding_admin_commands.js +++ b/jstests/sharding/timeseries_sharding_admin_commands.js @@ -170,11 +170,11 @@ function assertRangeMatch(savedRange, paramRange) { assert.commandFailedWithCode( mongo.s0.adminCommand( {reshardCollection: viewNss, key: {[metaField]: 1, [controlTimeField]: 1}}), - [ErrorCodes.NotImplemented]); + [ErrorCodes.NotImplemented, ErrorCodes.IllegalOperation]); assert.commandFailedWithCode( mongo.s0.adminCommand( {reshardCollection: bucketNss, key: {[metaField]: 1, [controlTimeField]: 1}}), - ErrorCodes.NotImplemented); + [ErrorCodes.NotImplemented, ErrorCodes.IllegalOperation]); dropTimeSeriesColl(); } else { jsTestLog(`Skipping resharding for timeseries not implemented test.`); diff --git a/src/mongo/db/s/shardsvr_reshard_collection_command.cpp b/src/mongo/db/s/shardsvr_reshard_collection_command.cpp index b6039465378..86c73918229 100644 --- a/src/mongo/db/s/shardsvr_reshard_collection_command.cpp +++ b/src/mongo/db/s/shardsvr_reshard_collection_command.cpp @@ -101,6 +101,35 @@ public: CommandHelpers::uassertCommandRunWithMajority(Request::kCommandName, opCtx->getWriteConcern()); + { + FixedFCVRegion fixedFcvRegion{opCtx}; + bool isReshardingForTimeseriesEnabled = + mongo::resharding::gFeatureFlagReshardingForTimeseries.isEnabled( + fixedFcvRegion->acquireFCVSnapshot()); + + // (SERVER-93135) Use an alternative client region to avoid shard version checking + // because v7.0 routers wrongly attach UNSHARDED shard version + auto newClient = opCtx->getServiceContext() + ->getService(ClusterRole::ShardServer) + ->makeClient("CheckForTimeseriesCollection"); + AlternativeClientRegion acr(newClient); + auto newOpCtxPtr = cc().makeOperationContext(); + + AutoGetCollection collOrView{newOpCtxPtr.get(), + ns(), + MODE_IS, + AutoGetCollection::Options{}.viewMode( + auto_get_collection::ViewMode::kViewsPermitted)}; + + bool isTimeseries = collOrView.getView() + ? collOrView.getView()->timeseries() + : *collOrView && collOrView->getTimeseriesOptions().has_value(); + + uassert(ErrorCodes::IllegalOperation, + "Can't reshard a timeseries collection", + !isTimeseries || isReshardingForTimeseriesEnabled); + } + if (resharding::isMoveCollection(request().getProvenance())) { bool clusterHasTwoOrMoreShards = [&]() { auto* clusterParameters = ServerParameterSet::getClusterParameterSet(); @@ -118,16 +147,7 @@ public: uassert(ErrorCodes::IllegalOperation, "Can't move an internal resharding collection", !ns().isTemporaryReshardingCollection()); - { - FixedFCVRegion fixedFcvRegion{opCtx}; - bool isReshardingForTimeseriesEnabled = - mongo::resharding::gFeatureFlagReshardingForTimeseries.isEnabled( - fixedFcvRegion->acquireFCVSnapshot()); - uassert(ErrorCodes::IllegalOperation, - "Can't move a timeseries collection", - !ns().isTimeseriesBucketsCollection() || - isReshardingForTimeseriesEnabled); - } + // TODO (SERVER-88623): re-evalutate the need to track the collection before calling // into moveCollection ShardsvrCreateCollectionRequest trackCollectionRequest; diff --git a/src/mongo/s/resharding/resharding_feature_flag.idl b/src/mongo/s/resharding/resharding_feature_flag.idl index 99610487a88..e78e979c83b 100644 --- a/src/mongo/s/resharding/resharding_feature_flag.idl +++ b/src/mongo/s/resharding/resharding_feature_flag.idl @@ -54,9 +54,9 @@ feature_flags: default: true version: 8.0 shouldBeFCVGated: true + # TODO SERVER-93149: Enable 'featureFlagReshardingForTimeseries' featureFlagReshardingForTimeseries: description: "Feature flag for enabling resharding a timeseries collection." cpp_varname: gFeatureFlagReshardingForTimeseries - default: true - version: 8.0 + default: false shouldBeFCVGated: true |
