diff options
author | Antonio Fuschetto <antonio.fuschetto@mongodb.com> | 2021-10-04 20:18:13 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-04 21:01:56 +0000 |
commit | 862b138c377fab52f2e71772731d9de08fb27efe (patch) | |
tree | a04e0b3746b9a9e968dad32f7e05b35399b9d65d | |
parent | e24c4546b90a5af883dc111c0a60c6424ac395d2 (diff) | |
download | mongo-862b138c377fab52f2e71772731d9de08fb27efe.tar.gz |
SERVER-58367 Create Feature flag for PM-2384
-rw-r--r-- | jstests/multiVersion/upgrade_downgrade_sharded_cluster.js | 41 | ||||
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/s/create_collection_coordinator.cpp | 20 | ||||
-rw-r--r-- | src/mongo/s/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/s/long_collection_names.idl | 36 |
5 files changed, 84 insertions, 23 deletions
diff --git a/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js b/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js index 529727c0131..e245d2e38b2 100644 --- a/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js +++ b/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js @@ -20,12 +20,8 @@ function setupClusterAndDatabase(binVersion) { mongos: 1, config: 1, shards: 2, - other: { - mongosOptions: {binVersion: binVersion}, - configOptions: {binVersion: binVersion}, - shardOptions: {binVersion: binVersion}, - rs: {nodes: 2} - } + rs: {nodes: 2, binVersion: binVersion}, + other: {mongosOptions: {binVersion: binVersion}, configOptions: {binVersion: binVersion}} }); st.configRS.awaitReplication(); @@ -77,7 +73,7 @@ function createShardedCollection() { } function testDisabledLongNameSupport(collNs) { - jsTestLog('Verify that long name support is properly disabled on collection ' + collNs); + jsTest.log('Verify that long name support is properly disabled on collection ' + collNs); const collConfigDoc = st.s.getDB('config').collections.findOne({_id: collNs}); assert.eq(collConfigDoc.supportingLongName, undefined); @@ -91,7 +87,7 @@ function testDisabledLongNameSupport(collNs) { shard1Secondary.setSecondaryOk(); for (const node of [shard0Primary, shard0Secondary, shard1Primary, shard1Secondary]) { - jsTestLog('Verify the consistency of the persisted cache on node ' + getNodeName(node)); + jsTest.log('Verify the consistency of the persisted cache on node ' + getNodeName(node)); const configDb = node.getDB('config'); @@ -104,7 +100,7 @@ function testDisabledLongNameSupport(collNs) { } function testImplicitlyEnabledLongNameSupport(collNs) { - jsTestLog('Verify that long name support is properly enabled on collection ' + collNs); + jsTest.log('Verify that long name support is properly enabled on collection ' + collNs); const collConfigDoc = st.s.getDB('config').collections.findOne({_id: collNs}); assert.eq(collConfigDoc.supportingLongName, 'implicitly_enabled'); @@ -118,7 +114,7 @@ function testImplicitlyEnabledLongNameSupport(collNs) { shard1Secondary.setSecondaryOk(); for (const node of [shard0Primary, shard0Secondary, shard1Primary, shard1Secondary]) { - jsTestLog('Verify the consistency of the persisted cache on node ' + getNodeName(node)); + jsTest.log('Verify the consistency of the persisted cache on node ' + getNodeName(node)); const configDb = node.getDB('config'); @@ -130,9 +126,21 @@ function testImplicitlyEnabledLongNameSupport(collNs) { } } +function isFeatureFlagLongCollectionNamesEnabled() { + const getClusterLookupParam = + st.configRS.getPrimary().adminCommand({getParameter: 1, featureFlagLongCollectionNames: 1}); + return getClusterLookupParam.hasOwnProperty('featureFlagLongCollectionNames') && + getClusterLookupParam.featureFlagLongCollectionNames.value; +} + function checkClusterBeforeUpgrade(fcv, collNs) { checkConfigAndShardsFCV(fcv); - testDisabledLongNameSupport(collNs); + + if (isFeatureFlagLongCollectionNamesEnabled()) { + testImplicitlyEnabledLongNameSupport(collNs); + } else { + testDisabledLongNameSupport(collNs); + } } function checkClusterAfterBinaryUpgrade() { @@ -141,8 +149,14 @@ function checkClusterAfterBinaryUpgrade() { function checkClusterAfterFCVUpgrade(fcv, call1Ns, call2Ns) { checkConfigAndShardsFCV(fcv); - testImplicitlyEnabledLongNameSupport(call1Ns); - testImplicitlyEnabledLongNameSupport(call2Ns); + + if (isFeatureFlagLongCollectionNamesEnabled()) { + testImplicitlyEnabledLongNameSupport(call1Ns); + testImplicitlyEnabledLongNameSupport(call2Ns); + } else { + testDisabledLongNameSupport(call1Ns); + testDisabledLongNameSupport(call2Ns); + } } function checkClusterAfterFCVDowngrade() { @@ -151,6 +165,7 @@ function checkClusterAfterFCVDowngrade() { function checkClusterAfterBinaryDowngrade(fcv, call1Ns, call2Ns, call3Ns) { checkConfigAndShardsFCV(fcv); + testDisabledLongNameSupport(call1Ns); testDisabledLongNameSupport(call2Ns); testDisabledLongNameSupport(call3Ns); diff --git a/src/mongo/db/s/config/sharding_catalog_manager.cpp b/src/mongo/db/s/config/sharding_catalog_manager.cpp index 295fa1bc183..188279a1b7c 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager.cpp @@ -61,6 +61,7 @@ #include "mongo/s/client/shard_registry.h" #include "mongo/s/database_version.h" #include "mongo/s/grid.h" +#include "mongo/s/long_collection_names_gen.h" #include "mongo/s/write_ops/batched_command_request.h" #include "mongo/s/write_ops/batched_command_response.h" #include "mongo/transport/service_entry_point.h" @@ -669,7 +670,9 @@ void ShardingCatalogManager::upgradeMetadataTo51Phase2(OperationContext* opCtx) LOGV2(5857402, "Starting metadata upgrade to FCV 5.1 (phase 2)"); try { - _enableSupportForLongCollectionName(opCtx); + if (feature_flags::gFeatureFlagLongCollectionNames.isEnabledAndIgnoreFCV()) { + _enableSupportForLongCollectionName(opCtx); + } } catch (const DBException& e) { LOGV2_ERROR( 5857403, "Failed to upgrade metadata to FCV 5.1 (phase 2)", "error"_attr = redact(e)); @@ -683,7 +686,9 @@ void ShardingCatalogManager::downgradeMetadataToPre51Phase2(OperationContext* op LOGV2(5857405, "Starting metadata downgrade to pre FCV 5.1 (phase 2)"); try { - _disableSupportForLongCollectionName(opCtx); + if (feature_flags::gFeatureFlagLongCollectionNames.isEnabledAndIgnoreFCV()) { + _disableSupportForLongCollectionName(opCtx); + } } catch (const DBException& e) { LOGV2_ERROR(5857406, "Failed to downgrade metadata to pre FCV 5.1 (phase 2)", diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp index 9cc00c593f2..1b0621f2a94 100644 --- a/src/mongo/db/s/create_collection_coordinator.cpp +++ b/src/mongo/db/s/create_collection_coordinator.cpp @@ -54,6 +54,7 @@ #include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/cluster_write.h" #include "mongo/s/grid.h" +#include "mongo/s/long_collection_names_gen.h" namespace mongo { namespace { @@ -822,18 +823,21 @@ void CreateCollectionCoordinator::_commit(OperationContext* opCtx) { coll.setKeyPattern(_shardKeyPattern->getKeyPattern()); - // Prevent the FCV from changing before committing the new collection to the config server. This - // ensures that the 'supportingLongName' field is properly set (and committed) based on the - // current shard's FCV. + // Prevent the FCV from changing before committing the new collection to the config server. + // This ensures that the 'supportingLongName' field is properly set (and committed) based on + // the current shard's FCV. // // TODO: Remove once FCV 6.0 becomes last-lts - FixedFCVRegion fixedFCVRegion(opCtx); + std::shared_ptr<FixedFCVRegion> currentFCV; // TODO: Remove condition once FCV 6.0 becomes last-lts - const auto& currentFCV = serverGlobalParams.featureCompatibility; - if (currentFCV.isGreaterThanOrEqualTo( - multiversion::FeatureCompatibilityVersion::kUpgradingFrom_5_0_To_5_1)) { - coll.setSupportingLongName(SupportingLongNameStatusEnum::kImplicitlyEnabled); + if (feature_flags::gFeatureFlagLongCollectionNames.isEnabledAndIgnoreFCV()) { + currentFCV = std::make_shared<FixedFCVRegion>(opCtx); + if ((*currentFCV) + ->isGreaterThanOrEqualTo( + multiversion::FeatureCompatibilityVersion::kUpgradingFrom_5_0_To_5_1)) { + coll.setSupportingLongName(SupportingLongNameStatusEnum::kImplicitlyEnabled); + } } if (_doc.getCreateCollectionRequest().getTimeseries()) { diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index b9b22e5851c..52de11e1322 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -174,6 +174,7 @@ env.Library( 'chunk_version.idl', 'database_version.cpp', 'database_version.idl', + 'long_collection_names.idl', 'mongod_and_mongos_server_parameters.idl', 'request_types/abort_reshard_collection.idl', 'request_types/add_shard_request_type.cpp', diff --git a/src/mongo/s/long_collection_names.idl b/src/mongo/s/long_collection_names.idl new file mode 100644 index 00000000000..aa5d47dad89 --- /dev/null +++ b/src/mongo/s/long_collection_names.idl @@ -0,0 +1,36 @@ +# Copyright (C) 2020-present MongoDB, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the Server Side Public License, version 1, +# as published by MongoDB, Inc. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Server Side Public License for more details. +# +# You should have received a copy of the Server Side Public License +# along with this program. If not, see +# <http://www.mongodb.com/licensing/server-side-public-license>. +# +# As a special exception, the copyright holders give permission to link the +# code of portions of this program with the OpenSSL library under certain +# conditions as described in each individual source file and distribute +# linked combinations including the program with the OpenSSL library. You +# must comply with the Server Side Public License in all respects for +# all of the code used other than as permitted herein. If you modify file(s) +# with this exception, you may extend this exception to your version of the +# file(s), but you are not obligated to do so. If you do not wish to do so, +# delete this exception statement from your version. If you delete this +# exception statement from all source files in the program, then also delete +# it in the license file. + +global: + cpp_namespace: mongo::feature_flags + +feature_flags: + featureFlagLongCollectionNames: + description: Extend the maximum name length of sharded collections from 236 to 256 bytes, + aligning it to the limit of non-sharded collections. + cpp_varname: gFeatureFlagLongCollectionNames + default: false |