diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2022-06-10 16:59:55 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-06-10 18:05:23 +0000 |
commit | 569d79ea269fd9d21fb91a28691806b65708bd0c (patch) | |
tree | 5be9f64122bda0ce1a73fdbcbd8de3ff69a32b48 | |
parent | 7ad95de6d0d0ff06f5161f7d5e3243b0cdd5e9cc (diff) | |
download | mongo-569d79ea269fd9d21fb91a28691806b65708bd0c.tar.gz |
SERVER-66934 Remove deprecated CollModCoordinatorPre60Compatible
-rw-r--r-- | jstests/sharding/timeseries_coll_mod.js | 37 | ||||
-rw-r--r-- | src/mongo/db/commands/set_feature_compatibility_version_command.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/s/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/s/collmod_coordinator_pre60_compatible.cpp | 264 | ||||
-rw-r--r-- | src/mongo/db/s/collmod_coordinator_pre60_compatible.h | 101 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_ddl_coordinator.idl | 2 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_ddl_coordinator_service.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/s/shardsvr_collmod_command.cpp | 96 |
8 files changed, 9 insertions, 508 deletions
diff --git a/jstests/sharding/timeseries_coll_mod.js b/jstests/sharding/timeseries_coll_mod.js index 2627fa21cf4..a4aa23bcc01 100644 --- a/jstests/sharding/timeseries_coll_mod.js +++ b/jstests/sharding/timeseries_coll_mod.js @@ -22,7 +22,7 @@ const viewNss = `${dbName}.${collName}`; const bucketNss = `${dbName}.system.buckets.${collName}`; const controlTimeField = `control.min.${timeField}`; -function runBasicTest(failPoint) { +function runBasicTest() { const st = new ShardingTest({shards: 2, rs: {nodes: 2}}); const mongos = st.s0; const db = mongos.getDB(dbName); @@ -37,14 +37,6 @@ function runBasicTest(failPoint) { assert.commandWorked( db.createCollection(collName, {timeseries: {timeField: timeField, metaField: metaField}})); - // Setting collModPrimaryDispatching failpoint to make sure the fallback logic of dispatching - // collMod command at primary shard works. - if (failPoint) { - const primary = st.getPrimaryShard(dbName); - assert.commandWorked( - primary.adminCommand({configureFailPoint: failPoint, mode: 'alwaysOn'})); - } - // Updates for timeField and metaField are disabled. assert.commandFailedWithCode(db.runCommand({collMod: collName, timeseries: {timeField: 'x'}}), 40415 /* Failed to parse */); @@ -74,23 +66,14 @@ function runBasicTest(failPoint) { assert.commandWorked( db.runCommand({collMod: collName, index: {name: indexName, hidden: false}})); - if (failPoint) { - // Granularity update disabled for sharded time-series collection, when we're using primary - // dispatching logic. - assert.commandFailedWithCode( - db.runCommand({collMod: collName, timeseries: {granularity: 'hours'}}), - ErrorCodes.NotImplemented); - } else { - // Granularity update works for sharded time-series collection, when we're using DDL - // coordinator logic. - const getGranularity = () => db.getSiblingDB('config') - .collections.findOne({_id: bucketNss}) - .timeseriesFields.granularity; - assert.eq(getGranularity(), 'minutes'); - assert.commandWorked( - db.runCommand({collMod: collName, timeseries: {granularity: 'hours'}})); - assert.eq(getGranularity(), 'hours'); - } + // Granularity update works for sharded time-series collection, when we're using DDL + // coordinator logic. + const getGranularity = () => db.getSiblingDB('config') + .collections.findOne({_id: bucketNss}) + .timeseriesFields.granularity; + assert.eq(getGranularity(), 'minutes'); + assert.commandWorked(db.runCommand({collMod: collName, timeseries: {granularity: 'hours'}})); + assert.eq(getGranularity(), 'hours'); st.stop(); } @@ -175,8 +158,6 @@ function runReadAfterWriteTest() { st.stop(); } -runBasicTest('collModPrimaryDispatching'); -runBasicTest('collModCoordinatorPre60Compatible'); runBasicTest(); runReadAfterWriteTest(); 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 e9884a73b8a..6a75dfef536 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -406,17 +406,6 @@ public: clearOrphanCountersFromRangeDeletionTasks(opCtx); } - // TODO (SERVER-62325): Remove collMod draining mechanism after 6.0 branching. - if (actualVersion > requestedVersion && - requestedVersion < multiversion::FeatureCompatibilityVersion::kVersion_6_0) { - // No more collMod coordinators will start because we have already switched - // the FCV value to kDowngrading. Wait for the ongoing collMod coordinators to - // finish. - ShardingDDLCoordinatorService::getService(opCtx) - ->waitForCoordinatorsOfGivenTypeToComplete( - opCtx, DDLCoordinatorTypeEnum::kCollMod); - } - // TODO SERVER-65077: Remove FCV check once 6.0 is released if (actualVersion > requestedVersion && !gFeatureFlagFLE2.isEnabledOnVersion(requestedVersion)) { diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 756d78e7de9..71a3a2267fd 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -334,7 +334,6 @@ env.Library( 'cluster_pipeline_cmd_d.cpp', 'cluster_write_cmd_d.cpp', 'collmod_coordinator_document.idl', - 'collmod_coordinator_pre60_compatible.cpp', 'collmod_coordinator.cpp', 'compact_structured_encryption_data_coordinator.cpp', 'compact_structured_encryption_data_coordinator.idl', diff --git a/src/mongo/db/s/collmod_coordinator_pre60_compatible.cpp b/src/mongo/db/s/collmod_coordinator_pre60_compatible.cpp deleted file mode 100644 index 37005996f3a..00000000000 --- a/src/mongo/db/s/collmod_coordinator_pre60_compatible.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/** - * Copyright (C) 2021-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. - */ - - -#include "mongo/db/s/collmod_coordinator_pre60_compatible.h" - -#include "mongo/db/catalog/collection_catalog.h" -#include "mongo/db/catalog/database_holder.h" -#include "mongo/db/coll_mod_gen.h" -#include "mongo/db/db_raii.h" -#include "mongo/db/ops/insert.h" -#include "mongo/db/s/sharded_collmod_gen.h" -#include "mongo/db/s/sharding_ddl_util.h" -#include "mongo/db/s/sharding_state.h" -#include "mongo/db/timeseries/catalog_helper.h" -#include "mongo/db/timeseries/timeseries_collmod.h" -#include "mongo/idl/idl_parser.h" -#include "mongo/logv2/log.h" -#include "mongo/s/async_requests_sender.h" -#include "mongo/s/cluster_commands_helpers.h" -#include "mongo/s/grid.h" - -#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding - - -namespace mongo { - -namespace { - -bool isShardedColl(OperationContext* opCtx, const NamespaceString& nss) { - try { - auto coll = Grid::get(opCtx)->catalogClient()->getCollection(opCtx, nss); - return true; - } catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) { - // The collection is not sharded or doesn't exist. - return false; - } -} - -bool hasTimeSeriesGranularityUpdate(const CollModRequest& request) { - return request.getTimeseries() && request.getTimeseries()->getGranularity(); -} - -} // namespace - -CollModCoordinatorPre60Compatible::CollModCoordinatorPre60Compatible( - ShardingDDLCoordinatorService* service, const BSONObj& initialState) - : ShardingDDLCoordinator(service, initialState) { - _initialState = initialState.getOwned(); - _doc = CollModCoordinatorDocument::parse(IDLParserErrorContext("CollModCoordinatorDocument"), - _initialState); -} - -void CollModCoordinatorPre60Compatible::checkIfOptionsConflict(const BSONObj& doc) const { - const auto otherDoc = - CollModCoordinatorDocument::parse(IDLParserErrorContext("CollModCoordinatorDocument"), doc); - - const auto& selfReq = _doc.getCollModRequest().toBSON(); - const auto& otherReq = otherDoc.getCollModRequest().toBSON(); - - uassert(ErrorCodes::ConflictingOperationInProgress, - str::stream() << "Another collMod for namespace " << nss() - << " is being executed with different parameters: " << selfReq, - SimpleBSONObjComparator::kInstance.evaluate(selfReq == otherReq)); -} - -boost::optional<BSONObj> CollModCoordinatorPre60Compatible::reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept { - - BSONObjBuilder cmdBob; - if (const auto& optComment = getForwardableOpMetadata().getComment()) { - cmdBob.append(optComment.get().firstElement()); - } - - const auto currPhase = [&]() { - stdx::lock_guard l{_docMutex}; - return _doc.getPhase(); - }(); - - cmdBob.appendElements(_doc.getCollModRequest().toBSON()); - BSONObjBuilder bob; - bob.append("type", "op"); - bob.append("desc", "CollModCoordinator"); - bob.append("op", "command"); - bob.append("ns", nss().toString()); - bob.append("command", cmdBob.obj()); - bob.append("currentPhase", currPhase); - bob.append("active", true); - return bob.obj(); -} - -void CollModCoordinatorPre60Compatible::_enterPhase(Phase newPhase) { - StateDoc newDoc(_doc); - newDoc.setPhase(newPhase); - - LOGV2_DEBUG(6482601, - 2, - "CollMod coordinator phase transition", - "namespace"_attr = nss(), - "newPhase"_attr = CollModCoordinatorPhase_serializer(newDoc.getPhase()), - "oldPhase"_attr = CollModCoordinatorPhase_serializer(_doc.getPhase())); - - if (_doc.getPhase() == Phase::kUnset) { - newDoc = _insertStateDocument(std::move(newDoc)); - } else { - newDoc = _updateStateDocument(cc().makeOperationContext().get(), std::move(newDoc)); - } - - { - stdx::unique_lock ul{_docMutex}; - _doc = std::move(newDoc); - } -} - -void CollModCoordinatorPre60Compatible::_performNoopRetryableWriteOnParticipants( - OperationContext* opCtx, const std::shared_ptr<executor::TaskExecutor>& executor) { - auto shardsAndConfigsvr = [&] { - const auto shardRegistry = Grid::get(opCtx)->shardRegistry(); - auto participants = shardRegistry->getAllShardIds(opCtx); - participants.emplace_back(shardRegistry->getConfigShard()->getId()); - return participants; - }(); - - _doc = _updateSession(opCtx, _doc); - sharding_ddl_util::performNoopRetryableWriteOnShards( - opCtx, shardsAndConfigsvr, getCurrentSession(_doc), executor); -} - -ExecutorFuture<void> CollModCoordinatorPre60Compatible::_runImpl( - std::shared_ptr<executor::ScopedTaskExecutor> executor, - const CancellationToken& token) noexcept { - return ExecutorFuture<void>(**executor) - .then(_executePhase( - Phase::kUpdateShards, - [this, executor = executor, anchor = shared_from_this()] { - auto opCtxHolder = cc().makeOperationContext(); - auto* opCtx = opCtxHolder.get(); - getForwardableOpMetadata().setOn(opCtx); - - const auto isTimeSeries = timeseries::getTimeseriesOptions( - opCtx, nss(), !nss().isTimeseriesBucketsCollection()); - const auto collNss = isTimeSeries && !nss().isTimeseriesBucketsCollection() - ? nss().makeTimeseriesBucketsNamespace() - : nss(); - const auto isSharded = isShardedColl(opCtx, collNss); - - if (isSharded) { - // Updating granularity on sharded time-series collections is not allowed. - if (isTimeSeries) { - uassert( - ErrorCodes::NotImplemented, - str::stream() - << "Cannot update granularity of a sharded time-series collection.", - !hasTimeSeriesGranularityUpdate(_doc.getCollModRequest())); - } - _doc.setCollUUID( - sharding_ddl_util::getCollectionUUID(opCtx, nss(), true /* allowViews */)); - - sharding_ddl_util::stopMigrations(opCtx, nss(), _doc.getCollUUID()); - - if (!_firstExecution) { - _performNoopRetryableWriteOnParticipants(opCtx, **executor); - } - - _doc = _updateSession(opCtx, _doc); - const OperationSessionInfo osi = getCurrentSession(_doc); - - const auto chunkManager = uassertStatusOK( - Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfoWithRefresh( - opCtx, collNss)); - std::unique_ptr<CollatorInterface> collator; - const auto expCtx = - make_intrusive<ExpressionContext>(opCtx, std::move(collator), collNss); - std::set<ShardId> participants; - chunkManager.getShardIdsForQuery( - expCtx, {} /* query */, {} /* collation */, &participants); - - ShardsvrCollModParticipant request(nss(), _doc.getCollModRequest()); - const auto cmdObj = - CommandHelpers::appendMajorityWriteConcern(request.toBSON({})); - const auto& responses = sharding_ddl_util::sendAuthenticatedCommandToShards( - opCtx, - nss().db(), - cmdObj.addFields(osi.toBSON()), - {std::make_move_iterator(participants.begin()), - std::make_move_iterator(participants.end())}, - **executor); - BSONObjBuilder builder; - std::string errmsg; - auto ok = appendRawResponses(opCtx, &errmsg, &builder, responses).responseOK; - if (!errmsg.empty()) { - CommandHelpers::appendSimpleCommandStatus(builder, ok, errmsg); - } - _result = builder.obj(); - sharding_ddl_util::resumeMigrations(opCtx, nss(), _doc.getCollUUID()); - } else { - CollMod cmd(nss()); - cmd.setCollModRequest(_doc.getCollModRequest()); - BSONObjBuilder collModResBuilder; - uassertStatusOK(timeseries::processCollModCommandWithTimeSeriesTranslation( - opCtx, nss(), cmd, true, &collModResBuilder)); - auto collModRes = collModResBuilder.obj(); - - const auto dbInfo = uassertStatusOK( - Grid::get(opCtx)->catalogCache()->getDatabase(opCtx, nss().db())); - const auto shard = uassertStatusOK( - Grid::get(opCtx)->shardRegistry()->getShard(opCtx, dbInfo->getPrimary())); - BSONObjBuilder builder; - builder.appendElements(collModRes); - BSONObjBuilder subBuilder(builder.subobjStart("raw")); - subBuilder.append(shard->getConnString().toString(), collModRes); - subBuilder.doneFast(); - _result = builder.obj(); - } - })) - .onError([this, anchor = shared_from_this()](const Status& status) { - if (!status.isA<ErrorCategory::NotPrimaryError>() && - !status.isA<ErrorCategory::ShutdownError>()) { - LOGV2_ERROR(6482602, - "Error running collMod", - "namespace"_attr = nss(), - "error"_attr = redact(status)); - // If we have the collection UUID set, this error happened in a sharded collection, - // we should restore the migrations. - if (_doc.getCollUUID()) { - auto opCtxHolder = cc().makeOperationContext(); - auto* opCtx = opCtxHolder.get(); - getForwardableOpMetadata().setOn(opCtx); - - sharding_ddl_util::resumeMigrations(opCtx, nss(), _doc.getCollUUID()); - } - } - return status; - }); -} - -} // namespace mongo diff --git a/src/mongo/db/s/collmod_coordinator_pre60_compatible.h b/src/mongo/db/s/collmod_coordinator_pre60_compatible.h deleted file mode 100644 index a8de0c67f53..00000000000 --- a/src/mongo/db/s/collmod_coordinator_pre60_compatible.h +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright (C) 2021-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. - */ - -#pragma once - -#include "mongo/db/s/collmod_coordinator_document_gen.h" -#include "mongo/db/s/sharding_ddl_coordinator.h" -#include "mongo/s/request_types/sharded_ddl_commands_gen.h" -#include "mongo/stdx/mutex.h" - -namespace mongo { - -class CollModCoordinatorPre60Compatible final : public ShardingDDLCoordinator { -public: - using StateDoc = CollModCoordinatorDocument; - using Phase = CollModCoordinatorPhaseEnum; - - CollModCoordinatorPre60Compatible(ShardingDDLCoordinatorService* service, - const BSONObj& initialState); - - void checkIfOptionsConflict(const BSONObj& doc) const override; - - boost::optional<BSONObj> reportForCurrentOp( - MongoProcessInterface::CurrentOpConnectionsMode connMode, - MongoProcessInterface::CurrentOpSessionsMode sessionMode) noexcept override; - - /** - * Waits for the termination of the parent DDLCoordinator (so all the resources are liberated) - * and then return the result. - */ - BSONObj getResult(OperationContext* opCtx) { - getCompletionFuture().get(opCtx); - invariant(_result.is_initialized()); - return *_result; - } - -private: - ShardingDDLCoordinatorMetadata const& metadata() const override { - stdx::lock_guard l{_docMutex}; - return _doc.getShardingDDLCoordinatorMetadata(); - } - - ExecutorFuture<void> _runImpl(std::shared_ptr<executor::ScopedTaskExecutor> executor, - const CancellationToken& token) noexcept override; - - template <typename Func> - auto _executePhase(const Phase& newPhase, Func&& func) { - return [=] { - const auto& currPhase = _doc.getPhase(); - - if (currPhase > newPhase) { - // Do not execute this phase if we already reached a subsequent one. - return; - } - if (currPhase < newPhase) { - // Persist the new phase if this is the first time we are executing it. - _enterPhase(newPhase); - } - return func(); - }; - } - - void _enterPhase(Phase newPhase); - - void _performNoopRetryableWriteOnParticipants( - OperationContext* opCtx, const std::shared_ptr<executor::TaskExecutor>& executor); - - BSONObj _initialState; - mutable Mutex _docMutex = MONGO_MAKE_LATCH("CollModCoordinatorPre60Compatible::_docMutex"); - CollModCoordinatorDocument _doc; - - boost::optional<BSONObj> _result; -}; - -} // namespace mongo diff --git a/src/mongo/db/s/sharding_ddl_coordinator.idl b/src/mongo/db/s/sharding_ddl_coordinator.idl index ef136439861..3a6b35e3eb4 100644 --- a/src/mongo/db/s/sharding_ddl_coordinator.idl +++ b/src/mongo/db/s/sharding_ddl_coordinator.idl @@ -50,8 +50,6 @@ enums: kCreateCollection: "createCollection_V2" kRefineCollectionShardKey: "refineCollectionShardKey" kSetAllowMigrations: "setAllowMigrations" - # TODO (SERVER-62325): Remove pre60 compatible collMod coordinator after 6.0 branching. - kCollModPre60Compatible: "collMod" kCollMod: "collMod_V2" kReshardCollection: "reshardCollection" kReshardCollectionNoResilient: "reshardCollectionNoResilient" diff --git a/src/mongo/db/s/sharding_ddl_coordinator_service.cpp b/src/mongo/db/s/sharding_ddl_coordinator_service.cpp index 7622c76402c..f4494ace7eb 100644 --- a/src/mongo/db/s/sharding_ddl_coordinator_service.cpp +++ b/src/mongo/db/s/sharding_ddl_coordinator_service.cpp @@ -38,7 +38,6 @@ #include "mongo/db/pipeline/document_source_count.h" #include "mongo/db/pipeline/expression_context.h" #include "mongo/db/s/collmod_coordinator.h" -#include "mongo/db/s/collmod_coordinator_pre60_compatible.h" #include "mongo/db/s/compact_structured_encryption_data_coordinator.h" #include "mongo/db/s/create_collection_coordinator.h" #include "mongo/db/s/database_sharding_state.h" @@ -90,10 +89,6 @@ std::shared_ptr<ShardingDDLCoordinator> constructShardingDDLCoordinatorInstance( case DDLCoordinatorTypeEnum::kCollMod: return std::make_shared<CollModCoordinator>(service, std::move(initialState)); break; - case DDLCoordinatorTypeEnum::kCollModPre60Compatible: - return std::make_shared<CollModCoordinatorPre60Compatible>(service, - std::move(initialState)); - break; case DDLCoordinatorTypeEnum::kReshardCollection: return std::make_shared<ReshardCollectionCoordinator>(service, std::move(initialState)); break; diff --git a/src/mongo/db/s/shardsvr_collmod_command.cpp b/src/mongo/db/s/shardsvr_collmod_command.cpp index f0564913aa1..3df3e521579 100644 --- a/src/mongo/db/s/shardsvr_collmod_command.cpp +++ b/src/mongo/db/s/shardsvr_collmod_command.cpp @@ -33,19 +33,12 @@ #include "mongo/db/coll_mod_gen.h" #include "mongo/db/coll_mod_reply_validation.h" #include "mongo/db/commands.h" -#include "mongo/db/commands/feature_compatibility_version.h" #include "mongo/db/curop.h" #include "mongo/db/s/collmod_coordinator.h" -#include "mongo/db/s/collmod_coordinator_pre60_compatible.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/s/sharding_util.h" #include "mongo/db/timeseries/catalog_helper.h" -#include "mongo/db/timeseries/timeseries_commands_conversion_helper.h" #include "mongo/logv2/log.h" -#include "mongo/s/chunk_manager_targeter.h" -#include "mongo/s/cluster_commands_helpers.h" -#include "mongo/s/grid.h" -#include "mongo/util/fail_point.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding @@ -53,9 +46,6 @@ namespace mongo { namespace { -MONGO_FAIL_POINT_DEFINE(collModPrimaryDispatching); -MONGO_FAIL_POINT_DEFINE(collModCoordinatorPre60Compatible); - class ShardsvrCollModCommand final : public BasicCommandWithRequestParser<ShardsvrCollModCommand> { public: using Request = ShardsvrCollMod; @@ -112,29 +102,6 @@ public: CurOp::get(opCtx)->raiseDbProfileLevel( CollectionCatalog::get(opCtx)->getDatabaseProfileLevel(cmd.getNamespace().dbName())); - boost::optional<FixedFCVRegion> fcvRegion; - fcvRegion.emplace(opCtx); - - if (MONGO_unlikely(collModPrimaryDispatching.shouldFail())) { - return runWithDispatchingCommands(opCtx, result, cmd); - } else if (MONGO_unlikely(collModCoordinatorPre60Compatible.shouldFail())) { - return runWithDDLCoordinatorPre60Compatible(opCtx, result, cmd, fcvRegion); - } - - if (fcvRegion.get()->isLessThan(multiversion::FeatureCompatibilityVersion::kVersion_5_3)) { - return runWithDispatchingCommands(opCtx, result, cmd); - } else if (fcvRegion.get()->isLessThan( - multiversion::FeatureCompatibilityVersion::kVersion_6_0)) { - return runWithDDLCoordinatorPre60Compatible(opCtx, result, cmd, fcvRegion); - } else { - return runWithDDLCoordinator(opCtx, result, cmd, fcvRegion); - } - } - - bool runWithDDLCoordinator(OperationContext* opCtx, - BSONObjBuilder& result, - const ShardsvrCollMod& cmd, - boost::optional<FixedFCVRegion>& fcvRegion) { auto coordinatorDoc = CollModCoordinatorDocument(); coordinatorDoc.setCollModRequest(cmd.getCollModRequest()); coordinatorDoc.setShardingDDLCoordinatorMetadata( @@ -142,73 +109,10 @@ public: auto service = ShardingDDLCoordinatorService::getService(opCtx); auto collModCoordinator = checked_pointer_cast<CollModCoordinator>( service->getOrCreateInstance(opCtx, coordinatorDoc.toBSON())); - fcvRegion = boost::none; - result.appendElements(collModCoordinator->getResult(opCtx)); - return true; - } - - bool runWithDDLCoordinatorPre60Compatible(OperationContext* opCtx, - BSONObjBuilder& result, - const ShardsvrCollMod& cmd, - boost::optional<FixedFCVRegion>& fcvRegion) { - auto coordinatorDoc = CollModCoordinatorDocument(); - coordinatorDoc.setCollModRequest(cmd.getCollModRequest()); - coordinatorDoc.setShardingDDLCoordinatorMetadata( - {{cmd.getNamespace(), DDLCoordinatorTypeEnum::kCollModPre60Compatible}}); - auto service = ShardingDDLCoordinatorService::getService(opCtx); - auto collModCoordinator = checked_pointer_cast<CollModCoordinatorPre60Compatible>( - service->getOrCreateInstance(opCtx, coordinatorDoc.toBSON())); - fcvRegion = boost::none; result.appendElements(collModCoordinator->getResult(opCtx)); return true; } - bool runWithDispatchingCommands(OperationContext* opCtx, - BSONObjBuilder& result, - const ShardsvrCollMod& cmd) { - const auto& nss = cmd.getNamespace(); - auto collModCmd = CollMod(nss); - collModCmd.setCollModRequest(cmd.getCollModRequest()); - auto collModCmdObj = collModCmd.toBSON({}); - - const auto targeter = ChunkManagerTargeter(opCtx, nss); - const auto& routingInfo = targeter.getRoutingInfo(); - if (targeter.timeseriesNamespaceNeedsRewrite(nss)) { - collModCmdObj = - timeseries::makeTimeseriesCommand(collModCmdObj, - nss, - CollMod::kCommandName, - CollMod::kIsTimeseriesNamespaceFieldName); - } - - std::set<ShardId> participants; - if (routingInfo.isSharded()) { - std::unique_ptr<CollatorInterface> collator; - const auto expCtx = - make_intrusive<ExpressionContext>(opCtx, std::move(collator), targeter.getNS()); - routingInfo.getShardIdsForQuery( - expCtx, {} /* query */, {} /* collation */, &participants); - } else { - participants.insert(routingInfo.dbPrimary()); - } - - auto executor = Grid::get(opCtx)->getExecutorPool()->getFixedExecutor(); - const auto& responses = sharding_util::sendCommandToShards( - opCtx, - targeter.getNS().db(), - CommandHelpers::appendMajorityWriteConcern(collModCmdObj, opCtx->getWriteConcern()), - {std::make_move_iterator(participants.begin()), - std::make_move_iterator(participants.end())}, - executor); - - std::string errmsg; - auto ok = appendRawResponses(opCtx, &errmsg, &result, std::move(responses)).responseOK; - if (!errmsg.empty()) { - CommandHelpers::appendSimpleCommandStatus(result, ok, errmsg); - } - return ok; - } - void validateResult(const BSONObj& resultObj) final { StringDataSet ignorableFields({"raw", "ok", "errmsg"}); auto reply = Response::parse(IDLParserErrorContext("CollModReply"), |