diff options
author | Didier Nadeau <didier.nadeau@mongodb.com> | 2023-01-10 14:37:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-10 15:12:28 +0000 |
commit | 2a0e666a35280595b4486fafc22271783537fd32 (patch) | |
tree | 63ab627ca693af5ec756595ad109d71765d3ce1e /src/mongo/db | |
parent | efb394a3e7b3133148181e50f86edddedbc588d9 (diff) | |
download | mongo-2a0e666a35280595b4486fafc22271783537fd32.tar.gz |
SERVER-72000 Send commit decision in recipientForgetMigration for merge
Diffstat (limited to 'src/mongo/db')
4 files changed, 55 insertions, 9 deletions
diff --git a/src/mongo/db/commands/tenant_migration_recipient_cmds.cpp b/src/mongo/db/commands/tenant_migration_recipient_cmds.cpp index b389068bf8a..c4b0726b2fd 100644 --- a/src/mongo/db/commands/tenant_migration_recipient_cmds.cpp +++ b/src/mongo/db/commands/tenant_migration_recipient_cmds.cpp @@ -43,6 +43,31 @@ namespace mongo { namespace { +// This function requires the definition of MigrationDecision. It cannot be moved to +// tenant_migration_util.h as this would cause a dependency cycle. +inline void protocolCheckRecipientForgetDecision( + const MigrationProtocolEnum protocol, const boost::optional<MigrationDecisionEnum>& committed) { + switch (protocol) { + case MigrationProtocolEnum::kShardMerge: { + uassert(ErrorCodes::InvalidOptions, + str::stream() << "'decision' is required for protocol '" + << MigrationProtocol_serializer(protocol) << "'", + committed.has_value()); + break; + } + case MigrationProtocolEnum::kMultitenantMigrations: { + uassert(ErrorCodes::InvalidOptions, + str::stream() << "'decision' must be empty for protocol '" + << MigrationProtocol_serializer(protocol) << "'", + !committed.has_value()); + break; + } + default: + MONGO_UNREACHABLE; + } +} + + MONGO_FAIL_POINT_DEFINE(returnResponseOkForRecipientSyncDataCmd); MONGO_FAIL_POINT_DEFINE(returnResponseOkForRecipientForgetMigrationCmd); @@ -255,6 +280,7 @@ public: tenant_migration_util::protocolTenantIdCompatibilityCheck(migrationProtocol, tenantId); tenant_migration_util::protocolTenantIdsCompatibilityCheck(migrationProtocol, tenantIds); + protocolCheckRecipientForgetDecision(migrationProtocol, cmd.getDecision()); opCtx->setAlwaysInterruptAtStepDownOrUp_UNSAFE(); auto recipientService = diff --git a/src/mongo/db/commands/tenant_migration_recipient_cmds.idl b/src/mongo/db/commands/tenant_migration_recipient_cmds.idl index a47fa23279e..f3477f0fb4d 100644 --- a/src/mongo/db/commands/tenant_migration_recipient_cmds.idl +++ b/src/mongo/db/commands/tenant_migration_recipient_cmds.idl @@ -42,6 +42,14 @@ imports: - "mongo/db/repl/replication_types.idl" - "mongo/util/net/hostandport.idl" +enums: + MigrationDecision: + description: "Whether the migration committed or aborted." + type: string + values: + kCommitted: "committed" + kAborted: "aborted" + structs: recipientSyncDataResponse: description: "Response for the 'recipientSyncData' command" @@ -158,3 +166,8 @@ commands: inline_chained_structs: true chained_structs: MigrationRecipientCommonData: MigrationRecipientCommonData + fields: + decision: + description: "Enumeration that defines whether the migration committed or aborted. This field applies only for shard merge protocol" + type: MigrationDecision + optional: true diff --git a/src/mongo/db/repl/tenant_migration_donor_service.cpp b/src/mongo/db/repl/tenant_migration_donor_service.cpp index 3906900198f..51c305c646e 100644 --- a/src/mongo/db/repl/tenant_migration_donor_service.cpp +++ b/src/mongo/db/repl/tenant_migration_donor_service.cpp @@ -832,10 +832,18 @@ ExecutorFuture<void> TenantMigrationDonorService::Instance::_sendRecipientForget MigrationRecipientCommonData commonData( _migrationUuid, donorConnString.toString(), _readPreference); commonData.setRecipientCertificateForDonor(_recipientCertificateForDonor); - if (_protocol == MigrationProtocolEnum::kMultitenantMigrations) { - commonData.setTenantId(boost::optional<StringData>(_tenantId)); - } else { - commonData.setTenantIds(_tenantIds); + { + stdx::lock_guard<Latch> lg(_mutex); + if (_protocol == MigrationProtocolEnum::kMultitenantMigrations) { + commonData.setTenantId(boost::optional<StringData>(_tenantId)); + } else { + commonData.setTenantIds(_tenantIds); + if (_stateDoc.getState() == TenantMigrationDonorStateEnum::kCommitted) { + request.setDecision(MigrationDecisionEnum::kCommitted); + } else { + request.setDecision(MigrationDecisionEnum::kAborted); + } + } } commonData.setProtocol(_protocol); diff --git a/src/mongo/db/repl/tenant_migration_util.h b/src/mongo/db/repl/tenant_migration_util.h index 85f5e734a02..78426ab0ea7 100644 --- a/src/mongo/db/repl/tenant_migration_util.h +++ b/src/mongo/db/repl/tenant_migration_util.h @@ -170,7 +170,7 @@ inline Status validatePrivateKeyPEMPayload(const StringData& payload) { } -inline void protocolTenantIdCompatibilityCheck(const MigrationProtocolEnum& protocol, +inline void protocolTenantIdCompatibilityCheck(const MigrationProtocolEnum protocol, const boost::optional<StringData>& tenantId) { switch (protocol) { case MigrationProtocolEnum::kShardMerge: { @@ -193,8 +193,7 @@ inline void protocolTenantIdCompatibilityCheck(const MigrationProtocolEnum& prot } inline void protocolTenantIdsCompatibilityCheck( - const MigrationProtocolEnum& protocol, - const boost::optional<std::vector<TenantId>>& tenantIds) { + const MigrationProtocolEnum protocol, const boost::optional<std::vector<TenantId>>& tenantIds) { if (serverGlobalParams.featureCompatibility.isLessThan( multiversion::FeatureCompatibilityVersion::kVersion_6_3)) { uassert(ErrorCodes::InvalidOptions, @@ -224,7 +223,7 @@ inline void protocolTenantIdsCompatibilityCheck( } inline void protocolStorageOptionsCompatibilityCheck(OperationContext* opCtx, - const MigrationProtocolEnum& protocol) { + const MigrationProtocolEnum protocol) { if (protocol != MigrationProtocolEnum::kShardMerge) return; @@ -240,7 +239,7 @@ inline void protocolStorageOptionsCompatibilityCheck(OperationContext* opCtx, } inline void protocolReadPreferenceCompatibilityCheck(OperationContext* opCtx, - const MigrationProtocolEnum& protocol, + const MigrationProtocolEnum protocol, const ReadPreferenceSetting& readPreference) { if (protocol != MigrationProtocolEnum::kShardMerge) return; |