From 96654daf62093db136bbbea634d53b3746f5c52c Mon Sep 17 00:00:00 2001 From: Jordi Serra Torrens Date: Fri, 8 Apr 2022 11:50:26 +0000 Subject: [PATCH] SERVER-65371 Ensure MigraitonSourceManager is only instantiated by a primary --- src/mongo/db/s/shardsvr_move_range_command.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mongo/db/s/shardsvr_move_range_command.cpp b/src/mongo/db/s/shardsvr_move_range_command.cpp index f2c3dded83d..7c476ce8c9b 100644 --- a/src/mongo/db/s/shardsvr_move_range_command.cpp +++ b/src/mongo/db/s/shardsvr_move_range_command.cpp @@ -32,6 +32,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/commands.h" #include "mongo/db/repl/repl_client_info.h" +#include "mongo/db/repl/replication_coordinator.h" #include "mongo/db/s/active_migrations_registry.h" #include "mongo/db/s/auto_split_vector.h" #include "mongo/db/s/migration_source_manager.h" @@ -152,6 +153,12 @@ public: // (under the ActiveMigrationRegistry lock) on the same term during // which the migrationCoordinators document will be persisted. Lock::GlobalLock lk(opCtx, MODE_IX); + uassert(ErrorCodes::InterruptedDueToReplStateChange, + "Not primary while attempting to start chunk migration " + "donation", + repl::ReplicationCoordinator::get(opCtx) + ->getMemberState() + .primary()); } // Note: This internal authorization is tied to the lifetime of the -- 2.17.1