diff options
| author | Abdul Qadeer <abdul.qadeer@mongodb.com> | 2022-09-20 18:48:30 +0000 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-20 20:22:57 +0000 |
| commit | e782061186dae5a650d8d28a80e4c4e92051a528 (patch) | |
| tree | 3f88c4d7b14fa8a9e24bd0c0692e7d50c23b2481 /src/mongo | |
| parent | 9529d985675a29c931c30d0f2272e1153e150d97 (diff) | |
| download | mongo-e782061186dae5a650d8d28a80e4c4e92051a528.tar.gz | |
SERVER-62720 Implement checkIfConflictsWithOtherInstances for ReshardingCoordinatorService
Diffstat (limited to 'src/mongo')
9 files changed, 287 insertions, 62 deletions
diff --git a/src/mongo/base/error_codes.yml b/src/mongo/base/error_codes.yml index c2e8fcd1a5d..48fba9a0813 100644 --- a/src/mongo/base/error_codes.yml +++ b/src/mongo/base/error_codes.yml @@ -488,9 +488,12 @@ error_codes: - {code: 376, name: ChangeStreamNotEnabled} - {code: 377, name: FLEMaxTagLimitExceeded } - {code: 378, name: NonConformantBSON, categories: [ValidationError]} + - {code: 379, name: DatabaseMetadataRefreshCanceled, categories: [InternalOnly]} - {code: 380, name: RequestAlreadyFulfilled} + - {code: 381, name: ReshardingCoordinatorServiceConflictingOperationInProgress, extra: ReshardingCoordinatorServiceConflictingOperationInProgressInfo, categories: [InternalOnly]} + - {code: 382, name: RemoteCommandExecutionError, extra: RemoteCommandExecutionErrorInfo, categories: [InternalOnly]} diff --git a/src/mongo/db/repl/primary_only_service.h b/src/mongo/db/repl/primary_only_service.h index bf9d3d76436..6d5c5b3ac5e 100644 --- a/src/mongo/db/repl/primary_only_service.h +++ b/src/mongo/db/repl/primary_only_service.h @@ -302,7 +302,9 @@ protected: /** * Validate the instance to be created with initialState does not conflict with any existing - * ones. The implementation should throw ConflictingOperationInProgress if there is a conflict. + * ones. The implementation can choose to throw ConflictingOperationInProgress if there is a + * conflict or a named error code specified to the particular service if it would like to attach + * ErrorExtraInfo. */ virtual void checkIfConflictsWithOtherInstances( OperationContext* opCtx, diff --git a/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp b/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp index 2d4c84b7e8e..d3ec9111437 100644 --- a/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp +++ b/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp @@ -46,35 +46,17 @@ #include "mongo/s/catalog/type_tags.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/reshard_collection_gen.h" +#include "mongo/s/resharding/resharding_coordinator_service_conflicting_op_in_progress_info.h" #include "mongo/s/resharding/resharding_feature_flag_gen.h" #define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kCommand - namespace mongo { MONGO_FAIL_POINT_DEFINE(reshardCollectionJoinedExistingOperation); namespace { -// Returns a resharding instance if one exists for the same collection and shard key already. -boost::optional<std::shared_ptr<ReshardingCoordinatorService::ReshardingCoordinator>> -getExistingInstanceToJoin(OperationContext* opCtx, - const NamespaceString& nss, - const BSONObj& newShardKey) { - auto instances = - resharding::getReshardingStateMachines<ReshardingCoordinatorService, - ReshardingCoordinatorService::ReshardingCoordinator>( - opCtx, nss); - for (const auto& instance : instances) { - if (SimpleBSONObjComparator::kInstance.evaluate( - instance->getMetadata().getReshardingKey().toBSON() == newShardKey)) { - return instance; - } - } - return boost::none; -} - class ConfigsvrReshardCollectionCommand final : public TypedCommand<ConfigsvrReshardCollectionCommand> { public: @@ -146,7 +128,7 @@ public: // Returns boost::none if there isn't any work to be done by the resharding operation. auto instance = ([&]() -> boost::optional<std::shared_ptr< - ReshardingCoordinatorService::ReshardingCoordinator>> { + const ReshardingCoordinatorService::ReshardingCoordinator>> { FixedFCVRegion fixedFcv(opCtx); uassert(ErrorCodes::CommandNotSupported, @@ -154,17 +136,6 @@ public: resharding::gFeatureFlagResharding.isEnabled( serverGlobalParams.featureCompatibility)); - if (auto existingInstance = - getExistingInstanceToJoin(opCtx, nss, request().getKey())) { - // Join the existing resharding operation to prevent generating a new resharding - // instance if the same command is issued consecutively due to client disconnect - // etc. - opCtx->setAlwaysInterruptAtStepDownOrUp_UNSAFE(); - reshardCollectionJoinedExistingOperation.pauseWhileSet(opCtx); - existingInstance.value()->getCoordinatorDocWrittenFuture().get(opCtx); - return existingInstance; - } - // (Generic FCV reference): To run this command and ensure the consistency of the // metadata we need to make sure we are on a stable state. uassert(ErrorCodes::CommandNotSupported, @@ -214,12 +185,7 @@ public: coordinatorDoc.setNumInitialChunks(request().getNumInitialChunks()); opCtx->setAlwaysInterruptAtStepDownOrUp_UNSAFE(); - auto registry = repl::PrimaryOnlyServiceRegistry::get(opCtx->getServiceContext()); - auto service = - registry->lookupServiceByName(ReshardingCoordinatorService::kServiceName); - auto instance = ReshardingCoordinatorService::ReshardingCoordinator::getOrCreate( - opCtx, service, coordinatorDoc.toBSON()); - + auto instance = getOrCreateReshardingCoordinator(opCtx, coordinatorDoc); instance->getCoordinatorDocWrittenFuture().get(opCtx); return instance; })(); @@ -232,6 +198,15 @@ public: repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx); } + /** + * Helper function to create a new instance or join the existing resharding operation to + * prevent generating a new resharding instance if the same command is issued consecutively + * due to client disconnect etc. + */ + std::shared_ptr<const ReshardingCoordinatorService::ReshardingCoordinator> + getOrCreateReshardingCoordinator(OperationContext* opCtx, + const ReshardingCoordinatorDocument& coordinatorDoc); + private: NamespaceString ns() const override { return request().getCommandParameter(); @@ -267,7 +242,31 @@ public: AllowedOnSecondary secondaryAllowed(ServiceContext*) const override { return AllowedOnSecondary::kNever; } + } configsvrReshardCollectionCmd; +std::shared_ptr<const ReshardingCoordinatorService::ReshardingCoordinator> +ConfigsvrReshardCollectionCommand::Invocation::getOrCreateReshardingCoordinator( + OperationContext* opCtx, const ReshardingCoordinatorDocument& coordinatorDoc) { + try { + auto registry = repl::PrimaryOnlyServiceRegistry::get(opCtx->getServiceContext()); + auto service = registry->lookupServiceByName(ReshardingCoordinatorService::kServiceName); + auto instance = ReshardingCoordinatorService::ReshardingCoordinator::getOrCreate( + opCtx, service, coordinatorDoc.toBSON()); + + return std::shared_ptr<const ReshardingCoordinatorService::ReshardingCoordinator>(instance); + } catch ( + const ExceptionFor<ErrorCodes::ReshardingCoordinatorServiceConflictingOperationInProgress>& + ex) { + reshardCollectionJoinedExistingOperation.pauseWhileSet(opCtx); + return checked_pointer_cast<const ReshardingCoordinatorService::ReshardingCoordinator>( + ex.extraInfo<ReshardingCoordinatorServiceConflictingOperationInProgressInfo>() + ->getInstance()); + + } catch (const ExceptionFor<ErrorCodes::ConflictingOperationInProgress>& ex) { + uasserted(ErrorCodes::ReshardCollectionInProgress, ex.toStatus().reason()); + } +} + } // namespace } // namespace mongo diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp index 9afe2f6cb3a..ae36fd5199d 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp @@ -65,6 +65,7 @@ #include "mongo/s/request_types/drop_collection_if_uuid_not_matching_gen.h" #include "mongo/s/request_types/flush_resharding_state_change_gen.h" #include "mongo/s/request_types/flush_routing_table_cache_updates_gen.h" +#include "mongo/s/resharding/resharding_coordinator_service_conflicting_op_in_progress_info.h" #include "mongo/s/write_ops/batched_command_request.h" #include "mongo/s/write_ops/batched_command_response.h" #include "mongo/util/assert_util.h" @@ -710,20 +711,7 @@ void insertCoordDocAndChangeOrigCollEntry(OperationContext* opCtx, // Insert the coordinator document to config.reshardingOperations. invariant(coordinatorDoc.getActive()); - try { - writeToCoordinatorStateNss(opCtx, metrics, coordinatorDoc, txnNumber); - } catch (const ExceptionFor<ErrorCodes::DuplicateKey>& ex) { - auto extraInfo = ex.extraInfo<DuplicateKeyErrorInfo>(); - if (extraInfo->getKeyPattern().woCompare(BSON("active" << 1)) == 0) { - uasserted(ErrorCodes::ReshardCollectionInProgress, - str::stream() - << "Only one resharding operation is allowed to be active at a " - "time, aborting resharding op for " - << coordinatorDoc.getSourceNss()); - } - - throw; - } + writeToCoordinatorStateNss(opCtx, metrics, coordinatorDoc, txnNumber); // Update the config.collections entry for the original collection to include // 'reshardingFields' @@ -974,6 +962,37 @@ ThreadPool::Limits ReshardingCoordinatorService::getThreadPoolLimits() const { return threadPoolLimit; } +void ReshardingCoordinatorService::checkIfConflictsWithOtherInstances( + OperationContext* opCtx, + BSONObj initialState, + const std::vector<const PrimaryOnlyService::Instance*>& existingInstances) { + auto coordinatorDoc = ReshardingCoordinatorDocument::parse( + IDLParserContext("ReshardingCoordinatorService::checkIfConflictsWithOtherInstances"), + std::move(initialState)); + + for (const auto& instance : existingInstances) { + auto typedInstance = + checked_cast<const ReshardingCoordinatorService::ReshardingCoordinator*>(instance); + const bool isNssSame = + typedInstance->getMetadata().getSourceNss() == coordinatorDoc.getSourceNss(); + const bool isReshardingKeySame = SimpleBSONObjComparator::kInstance.evaluate( + typedInstance->getMetadata().getReshardingKey().toBSON() == + coordinatorDoc.getReshardingKey().toBSON()); + + iassert(ErrorCodes::ConflictingOperationInProgress, + str::stream() << "Only one resharding operation is allowed to be active at a " + "time, aborting resharding op for " + << coordinatorDoc.getSourceNss(), + isNssSame && isReshardingKeySame); + + iasserted(ReshardingCoordinatorServiceConflictingOperationInProgressInfo( + typedInstance->shared_from_this()), + str::stream() << "Found an active resharding operation for " + << coordinatorDoc.getSourceNss() << " with resharding key " + << coordinatorDoc.getReshardingKey().toString()); + } +} + std::shared_ptr<repl::PrimaryOnlyService::Instance> ReshardingCoordinatorService::constructInstance( BSONObj initialState) { return std::make_shared<ReshardingCoordinator>( diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.h b/src/mongo/db/s/resharding/resharding_coordinator_service.h index be08ef7ba9b..cae6ab5df3c 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service.h +++ b/src/mongo/db/s/resharding/resharding_coordinator_service.h @@ -218,7 +218,7 @@ public: void checkIfConflictsWithOtherInstances( OperationContext* opCtx, BSONObj initialState, - const std::vector<const PrimaryOnlyService::Instance*>& existingInstances) override{}; + const std::vector<const PrimaryOnlyService::Instance*>& existingInstances) override; std::shared_ptr<PrimaryOnlyService::Instance> constructInstance(BSONObj initialState) override; diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp index 0d46faf2977..58dc179f3d9 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_service_test.cpp @@ -34,6 +34,7 @@ #include "mongo/db/op_observer/op_observer_impl.h" #include "mongo/db/op_observer/op_observer_noop.h" #include "mongo/db/op_observer/op_observer_registry.h" +#include "mongo/db/repl/primary_only_service_op_observer.h" #include "mongo/db/repl/primary_only_service_test_fixture.h" #include "mongo/db/repl/wait_for_majority_service.h" #include "mongo/db/s/config/config_server_test_fixture.h" @@ -50,6 +51,7 @@ #include "mongo/logv2/log.h" #include "mongo/s/catalog/type_collection.h" #include "mongo/s/catalog/type_shard.h" +#include "mongo/s/resharding/resharding_coordinator_service_conflicting_op_in_progress_info.h" #include "mongo/stdx/unordered_map.h" #include "mongo/unittest/unittest.h" #include "mongo/util/clock_source_mock.h" @@ -184,14 +186,21 @@ public: } ReshardingCoordinatorDocument makeCoordinatorDoc( - CoordinatorStateEnum state, boost::optional<Timestamp> fetchTimestamp = boost::none) { + CoordinatorStateEnum state, + UUID reshardingUUID, + NamespaceString originalNss, + NamespaceString tempNss, + const ShardKeyPattern& newShardKey, + boost::optional<Timestamp> fetchTimestamp = boost::none) { CommonReshardingMetadata meta( - _reshardingUUID, _originalNss, UUID::gen(), _tempNss, _newShardKey.toBSON()); + reshardingUUID, originalNss, UUID::gen(), tempNss, newShardKey.toBSON()); + meta.setStartTime(getServiceContext()->getFastClockSource()->now()); ReshardingCoordinatorDocument doc(state, {DonorShardEntry(ShardId("shard0000"), {})}, {RecipientShardEntry(ShardId("shard0001"), {})}); + doc.setCommonReshardingMetadata(meta); resharding::emplaceCloneTimestampIfExists(doc, cloneTimestamp); return doc; @@ -355,10 +364,23 @@ public: CoordinatorStateEnum state, OID epoch, boost::optional<Timestamp> fetchTimestamp = boost::none) { + return insertStateAndCatalogEntries( + state, epoch, _originalUUID, _originalNss, _tempNss, _newShardKey, fetchTimestamp); + } + + ReshardingCoordinatorDocument insertStateAndCatalogEntries( + CoordinatorStateEnum state, + OID epoch, + UUID reshardingUUID, + NamespaceString originalNss, + NamespaceString tempNss, + const ShardKeyPattern& newShardKey, + boost::optional<Timestamp> fetchTimestamp = boost::none) { auto opCtx = operationContext(); DBDirectClient client(opCtx); - auto coordinatorDoc = makeCoordinatorDoc(state, fetchTimestamp); + auto coordinatorDoc = makeCoordinatorDoc( + state, reshardingUUID, originalNss, tempNss, newShardKey, fetchTimestamp); TypeCollectionReshardingFields reshardingFields(coordinatorDoc.getReshardingUUID()); reshardingFields.setState(coordinatorDoc.getState()); @@ -494,18 +516,35 @@ public: } auto initializeAndGetCoordinator() { - auto doc = insertStateAndCatalogEntries(CoordinatorStateEnum::kUnused, _originalEpoch); + return initializeAndGetCoordinator( + _reshardingUUID, _originalNss, _tempNss, _newShardKey, _originalUUID, _oldShardKey); + } + + std::shared_ptr<ReshardingCoordinator> initializeAndGetCoordinator( + UUID reshardingUUID, + NamespaceString originalNss, + NamespaceString tempNss, + const ShardKeyPattern& newShardKey, + UUID originalUUID, + const ShardKeyPattern& oldShardKey, + boost::optional<Timestamp> fetchTimestamp = boost::none) { + auto doc = insertStateAndCatalogEntries(CoordinatorStateEnum::kUnused, + _originalEpoch, + reshardingUUID, + originalNss, + tempNss, + newShardKey, + fetchTimestamp); auto opCtx = operationContext(); - auto donorChunk = makeAndInsertChunksForDonorShard(_originalUUID, + auto donorChunk = makeAndInsertChunksForDonorShard(originalUUID, _originalEpoch, _originalTimestamp, - _oldShardKey, + oldShardKey, std::vector{OID::gen(), OID::gen()}); - - auto initialChunks = makeChunks(_reshardingUUID, + auto initialChunks = makeChunks(reshardingUUID, _tempEpoch, _tempTimestamp, - _newShardKey, + newShardKey, std::vector{OID::gen(), OID::gen()}); std::vector<ReshardedChunk> presetReshardedChunks; @@ -888,5 +927,49 @@ TEST_F(ReshardingCoordinatorServiceTest, ReshardingCoordinatorFailsIfMigrationNo } } +TEST_F(ReshardingCoordinatorServiceTest, MultipleReshardingOperationsFail) { + auto coordinator = initializeAndGetCoordinator(); + + // Asserts that a resharding op with same namespace and same shard key fails with + // ReshardingCoordinatorServiceConflictingOperationInProgress + ASSERT_THROWS_WITH_CHECK( + initializeAndGetCoordinator( + UUID::gen(), _originalNss, _tempNss, _newShardKey, UUID::gen(), _oldShardKey), + DBException, + [&](const DBException& ex) { + ASSERT_EQ(ex.code(), + ErrorCodes::ReshardingCoordinatorServiceConflictingOperationInProgress); + ASSERT_EQ(ex.extraInfo<ReshardingCoordinatorServiceConflictingOperationInProgressInfo>() + ->getInstance(), + coordinator); + }); + + // Asserts that a resharding op with different namespace and different shard key fails with + // ConflictingOperationInProgress. + ASSERT_THROWS_CODE(initializeAndGetCoordinator( + UUID::gen(), + NamespaceString("db.moo"), + NamespaceString("db.system.resharding." + UUID::gen().toString()), + ShardKeyPattern(BSON("shardKeyV1" << 1)), + UUID::gen(), + ShardKeyPattern(BSON("shardKeyV2" << 1))), + DBException, + ErrorCodes::ConflictingOperationInProgress); + + // Asserts that a resharding op with same namespace and different shard key fails with + // ConflictingOperationInProgress. + ASSERT_THROWS_CODE(initializeAndGetCoordinator( + UUID::gen(), + _originalNss, + NamespaceString("db.system.resharding." + UUID::gen().toString()), + ShardKeyPattern(BSON("shardKeyV1" << 1)), + UUID::gen(), + _oldShardKey), + DBException, + ErrorCodes::ConflictingOperationInProgress); + + runReshardingToCompletion(); +} + } // namespace } // namespace mongo diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index c99dd308612..21a039e0ef8 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -194,6 +194,7 @@ env.Library( 'resharding/resharding_feature_flag.idl', 'resharding/resume_token.idl', 'resharding/type_collection_fields.idl', + 'resharding/resharding_coordinator_service_conflicting_op_in_progress_info.cpp', 'shard_cannot_refresh_due_to_locks_held_exception.cpp', 'shard_invalidated_for_targeting_exception.cpp', 'shard_version.cpp', diff --git a/src/mongo/s/resharding/resharding_coordinator_service_conflicting_op_in_progress_info.cpp b/src/mongo/s/resharding/resharding_coordinator_service_conflicting_op_in_progress_info.cpp new file mode 100644 index 00000000000..06ca0d9d6dc --- /dev/null +++ b/src/mongo/s/resharding/resharding_coordinator_service_conflicting_op_in_progress_info.cpp @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2022-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/s/resharding/resharding_coordinator_service_conflicting_op_in_progress_info.h" + +#include "mongo/base/init.h" + +namespace mongo { + +MONGO_INIT_REGISTER_ERROR_EXTRA_INFO( + ReshardingCoordinatorServiceConflictingOperationInProgressInfo); + +ReshardingCoordinatorServiceConflictingOperationInProgressInfo:: + ReshardingCoordinatorServiceConflictingOperationInProgressInfo( + std::shared_ptr<const repl::PrimaryOnlyService::Instance> instance) + : reshardingCoordinatorInstance(std::move(instance)) {} + +void ReshardingCoordinatorServiceConflictingOperationInProgressInfo::serialize( + BSONObjBuilder* builder) const {} + +std::shared_ptr<const ErrorExtraInfo> +ReshardingCoordinatorServiceConflictingOperationInProgressInfo::parse(const BSONObj& obj) { + return std::make_shared<ReshardingCoordinatorServiceConflictingOperationInProgressInfo>( + ReshardingCoordinatorServiceConflictingOperationInProgressInfo()); +} + +std::shared_ptr<const repl::PrimaryOnlyService::Instance> +ReshardingCoordinatorServiceConflictingOperationInProgressInfo::getInstance() const { + return reshardingCoordinatorInstance; +} + +} // namespace mongo diff --git a/src/mongo/s/resharding/resharding_coordinator_service_conflicting_op_in_progress_info.h b/src/mongo/s/resharding/resharding_coordinator_service_conflicting_op_in_progress_info.h new file mode 100644 index 00000000000..2342b48943f --- /dev/null +++ b/src/mongo/s/resharding/resharding_coordinator_service_conflicting_op_in_progress_info.h @@ -0,0 +1,60 @@ +/** + * Copyright (C) 2022-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/base/error_extra_info.h" +#include "mongo/db/repl/primary_only_service.h" + +namespace mongo { + +class ReshardingCoordinatorServiceConflictingOperationInProgressInfo final : public ErrorExtraInfo { +public: + static constexpr auto code = + ErrorCodes::ReshardingCoordinatorServiceConflictingOperationInProgress; + + explicit ReshardingCoordinatorServiceConflictingOperationInProgressInfo( + std::shared_ptr<const repl::PrimaryOnlyService::Instance> instance); + + ReshardingCoordinatorServiceConflictingOperationInProgressInfo() = default; + + void serialize(BSONObjBuilder* builder) const override; + + static std::shared_ptr<const ErrorExtraInfo> parse(const BSONObj&); + + std::shared_ptr<const repl::PrimaryOnlyService::Instance> getInstance() const; + +private: + // This variable is of type repl::PrimaryOnlyService::Instance rather than a + // ReshardingCoordinator instance to avoid linking the + // ReshardingCoordinatorService::ReshardingCoordinator type into mongos and the mongo shell + std::shared_ptr<const repl::PrimaryOnlyService::Instance> reshardingCoordinatorInstance; +}; + +} // namespace mongo |
