diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2021-07-26 12:10:15 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-07-27 16:46:25 +0000 |
commit | 1b8d8f798c353b2661e9063281ce3fe3c6882545 (patch) | |
tree | bcf69ff92e2cfeb714d1227619d00cf81dc9c70f | |
parent | 7cccaa4720c8ca16e7c8a35d325ea281fc1f9e2e (diff) | |
download | mongo-1b8d8f798c353b2661e9063281ce3fe3c6882545.tar.gz |
SERVER-58595 Remove legacy ConfigsvrCommitMovePrimary command
23 files changed, 35 insertions, 985 deletions
diff --git a/jstests/core/views/views_all_commands.js b/jstests/core/views/views_all_commands.js index 24246ddabb4..31a315730b3 100644 --- a/jstests/core/views/views_all_commands.js +++ b/jstests/core/views/views_all_commands.js @@ -88,7 +88,8 @@ let viewsCommandTests = { _configsvrCommitChunksMerge: {skip: isAnInternalCommand}, _configsvrCommitChunkMigration: {skip: isAnInternalCommand}, _configsvrCommitChunkSplit: {skip: isAnInternalCommand}, - _configsvrCommitMovePrimary: {skip: isAnInternalCommand}, + _configsvrCommitMovePrimary: + {skip: isAnInternalCommand}, // Can be removed once 6.0 is last LTS _configsvrCommitReshardCollection: {skip: isAnInternalCommand}, _configsvrCreateDatabase: {skip: isAnInternalCommand}, _configsvrDropCollection: @@ -98,7 +99,7 @@ let viewsCommandTests = { _configsvrEnableSharding: {skip: isAnInternalCommand}, // TODO (SERVER-58843): Remove once 6.0 becomes last LTS _configsvrEnsureChunkVersionIsGreaterThan: {skip: isAnInternalCommand}, - _configsvrMoveChunk: {skip: isAnInternalCommand}, + _configsvrMoveChunk: {skip: isAnInternalCommand}, // Can be removed once 6.0 is last LTS _configsvrMovePrimary: {skip: isAnInternalCommand}, _configsvrRefineCollectionShardKey: {skip: isAnInternalCommand}, _configsvrRenameCollection: {skip: isAnInternalCommand}, diff --git a/jstests/libs/override_methods/network_error_and_txn_override.js b/jstests/libs/override_methods/network_error_and_txn_override.js index d42e267ec7c..4de5cd9ba65 100644 --- a/jstests/libs/override_methods/network_error_and_txn_override.js +++ b/jstests/libs/override_methods/network_error_and_txn_override.js @@ -80,7 +80,6 @@ const kNonRetryableCommands = new Set([ "_configsvrCommitChunkSplit", "_configsvrCreateDatabase", "_configsvrMoveChunk", - "_configsvrMovePrimary", "_configsvrRemoveShard", "_configsvrRemoveShardFromZone", "_configsvrUpdateZoneKeyRange", diff --git a/jstests/libs/override_methods/read_and_write_concern_helpers.js b/jstests/libs/override_methods/read_and_write_concern_helpers.js index 0e83b39d6b3..eddb709d740 100644 --- a/jstests/libs/override_methods/read_and_write_concern_helpers.js +++ b/jstests/libs/override_methods/read_and_write_concern_helpers.js @@ -37,7 +37,6 @@ var kCommandsSupportingWriteConcern = new Set([ "_configsvrCommitChunkSplit", "_configsvrCreateDatabase", "_configsvrMoveChunk", - "_configsvrMovePrimary", "_configsvrRemoveShard", "_configsvrRemoveShardFromZone", "_configsvrUpdateZoneKeyRange", diff --git a/jstests/replsets/db_reads_while_recovering_all_commands.js b/jstests/replsets/db_reads_while_recovering_all_commands.js index 74155c28dc1..691d476cb07 100644 --- a/jstests/replsets/db_reads_while_recovering_all_commands.js +++ b/jstests/replsets/db_reads_while_recovering_all_commands.js @@ -38,12 +38,10 @@ const allCommands = { _configsvrCommitChunksMerge: {skip: isPrimaryOnly}, _configsvrCommitChunkMigration: {skip: isPrimaryOnly}, _configsvrCommitChunkSplit: {skip: isPrimaryOnly}, - _configsvrCommitMovePrimary: {skip: isPrimaryOnly}, _configsvrCommitReshardCollection: {skip: isPrimaryOnly}, _configsvrCreateDatabase: {skip: isPrimaryOnly}, _configsvrEnsureChunkVersionIsGreaterThan: {skip: isPrimaryOnly}, _configsvrMoveChunk: {skip: isPrimaryOnly}, - _configsvrMovePrimary: {skip: isPrimaryOnly}, _configsvrRefineCollectionShardKey: {skip: isPrimaryOnly}, _configsvrRemoveChunks: {skip: isPrimaryOnly}, _configsvrRemoveShard: {skip: isPrimaryOnly}, diff --git a/jstests/replsets/tenant_migration_concurrent_writes_on_donor.js b/jstests/replsets/tenant_migration_concurrent_writes_on_donor.js index d6677e85b4c..5bd1b399057 100644 --- a/jstests/replsets/tenant_migration_concurrent_writes_on_donor.js +++ b/jstests/replsets/tenant_migration_concurrent_writes_on_donor.js @@ -461,10 +461,11 @@ const testCases = { _configsvrCommitChunksMerge: {skip: isNotRunOnUserDatabase}, _configsvrCommitChunkMigration: {skip: isNotRunOnUserDatabase}, _configsvrCommitChunkSplit: {skip: isNotRunOnUserDatabase}, - _configsvrCommitMovePrimary: {skip: isNotRunOnUserDatabase}, + _configsvrCommitMovePrimary: + {skip: isNotRunOnUserDatabase}, // Can be removed once 6.0 is last LTS _configsvrCreateDatabase: {skip: isNotRunOnUserDatabase}, _configsvrEnsureChunkVersionIsGreaterThan: {skip: isNotRunOnUserDatabase}, - _configsvrMoveChunk: {skip: isNotRunOnUserDatabase}, + _configsvrMoveChunk: {skip: isNotRunOnUserDatabase}, // Can be removed once 6.0 is last LTS _configsvrMovePrimary: {skip: isNotRunOnUserDatabase}, _configsvrRefineCollectionShardKey: {skip: isNotRunOnUserDatabase}, _configsvrRemoveShard: {skip: isNotRunOnUserDatabase}, diff --git a/jstests/sharding/configsvr_metadata_commands_require_majority_write_concern.js b/jstests/sharding/configsvr_metadata_commands_require_majority_write_concern.js index 24efb253106..c9d880aebe4 100644 --- a/jstests/sharding/configsvr_metadata_commands_require_majority_write_concern.js +++ b/jstests/sharding/configsvr_metadata_commands_require_majority_write_concern.js @@ -135,9 +135,6 @@ checkCommandMongos({enableSharding: dbName}, setupFuncs.noop, cleanupFuncs.dropD checkCommandMongos({movePrimary: dbName, to: st.shard0.name}, setupFuncs.createDatabase, cleanupFuncs.dropDatabase); -checkCommandConfigSvr({_configsvrMovePrimary: dbName, to: st.shard0.name}, - setupFuncs.createDatabase, - cleanupFuncs.dropDatabase); // shardCollection checkCommandMongos( diff --git a/jstests/sharding/read_write_concern_defaults_application.js b/jstests/sharding/read_write_concern_defaults_application.js index c14c8430dd1..c9f59651d9e 100644 --- a/jstests/sharding/read_write_concern_defaults_application.js +++ b/jstests/sharding/read_write_concern_defaults_application.js @@ -88,7 +88,7 @@ let testCases = { _configsvrCommitChunksMerge: {skip: "internal command"}, _configsvrCommitChunkMigration: {skip: "internal command"}, _configsvrCommitChunkSplit: {skip: "internal command"}, - _configsvrCommitMovePrimary: {skip: "internal command"}, + _configsvrCommitMovePrimary: {skip: "internal command"}, // Can be removed once 6.0 is last LTS _configsvrCommitReshardCollection: {skip: "internal command"}, _configsvrCreateDatabase: {skip: "internal command"}, _configsvrDropCollection: @@ -99,7 +99,7 @@ let testCases = { {skip: "internal command"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrEnsureChunkVersionIsGreaterThan: {skip: "internal command"}, _configsvrMoveChunk: {skip: "internal command"}, - _configsvrMovePrimary: {skip: "internal command"}, + _configsvrMovePrimary: {skip: "internal command"}, // Can be removed once 6.0 is last LTS _configsvrRefineCollectionShardKey: {skip: "internal command"}, _configsvrRemoveChunks: {skip: "internal command"}, _configsvrRemoveShard: {skip: "internal command"}, diff --git a/jstests/sharding/safe_secondary_reads_drop_recreate.js b/jstests/sharding/safe_secondary_reads_drop_recreate.js index dcf463650f8..34fa64ef167 100644 --- a/jstests/sharding/safe_secondary_reads_drop_recreate.js +++ b/jstests/sharding/safe_secondary_reads_drop_recreate.js @@ -55,13 +55,15 @@ let testCases = { _configsvrCommitChunksMerge: {skip: "primary only"}, _configsvrCommitChunkMigration: {skip: "primary only"}, _configsvrCommitChunkSplit: {skip: "primary only"}, - _configsvrCommitMovePrimary: {skip: "primary only"}, + _configsvrCommitMovePrimary: + {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrDropCollection: {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrDropDatabase: {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrMoveChunk: {skip: "primary only"}, - _configsvrMovePrimary: {skip: "primary only"}, + _configsvrMovePrimary: + {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrRemoveShardFromZone: {skip: "primary only"}, _configsvrReshardCollection: {skip: "primary only"}, _configsvrShardCollection: diff --git a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js index 86b80c6924f..6cd53fe5644 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js @@ -63,13 +63,15 @@ let testCases = { _configsvrCommitChunksMerge: {skip: "primary only"}, _configsvrCommitChunkMigration: {skip: "primary only"}, _configsvrCommitChunkSplit: {skip: "primary only"}, - _configsvrCommitMovePrimary: {skip: "primary only"}, + _configsvrCommitMovePrimary: + {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrDropCollection: {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrDropDatabase: {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrMoveChunk: {skip: "primary only"}, - _configsvrMovePrimary: {skip: "primary only"}, + _configsvrMovePrimary: + {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrRemoveChunks: {skip: "primary only"}, _configsvrRemoveShardFromZone: {skip: "primary only"}, _configsvrRemoveTags: {skip: "primary only"}, diff --git a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js index 1036b7df678..e5fa405f330 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js @@ -53,13 +53,15 @@ let testCases = { _configsvrCommitChunksMerge: {skip: "primary only"}, _configsvrCommitChunkMigration: {skip: "primary only"}, _configsvrCommitChunkSplit: {skip: "primary only"}, - _configsvrCommitMovePrimary: {skip: "primary only"}, + _configsvrCommitMovePrimary: + {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrDropCollection: {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrDropDatabase: {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrMoveChunk: {skip: "primary only"}, - _configsvrMovePrimary: {skip: "primary only"}, + _configsvrMovePrimary: + {skip: "primary only"}, // TODO SERVER-58843: Remove once 6.0 becomes last LTS _configsvrRemoveChunks: {skip: "primary only"}, _configsvrRemoveShardFromZone: {skip: "primary only"}, _configsvrRemoveTags: {skip: "primary only"}, diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 8057768e20d..3da2fcea030 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -34,7 +34,6 @@ env.Library( target='sharding_runtime_d', source=[ 'active_migrations_registry.cpp', - 'active_move_primaries_registry.cpp', 'auto_split_vector.cpp', 'chunk_move_write_concern_options.cpp', 'chunk_splitter.cpp', @@ -301,7 +300,6 @@ env.Library( 'config/configsvr_cleanup_reshard_collection_command.cpp', 'config/configsvr_clear_jumbo_flag_command.cpp', 'config/configsvr_commit_chunk_migration_command.cpp', - 'config/configsvr_commit_move_primary_command.cpp', 'config/configsvr_commit_reshard_collection_command.cpp', 'config/configsvr_control_balancer_command.cpp', 'config/configsvr_create_database_command.cpp', @@ -309,7 +307,6 @@ env.Library( 'config/configsvr_merge_chunk_command.cpp', 'config/configsvr_merge_chunks_command.cpp', 'config/configsvr_move_chunk_command.cpp', - 'config/configsvr_move_primary_command.cpp', 'config/configsvr_refine_collection_shard_key_command.cpp', 'config/configsvr_remove_chunks_command.cpp', 'config/configsvr_remove_shard_command.cpp', @@ -460,7 +457,6 @@ env.CppUnitTest( target='db_s_shard_server_test', source=[ 'active_migrations_registry_test.cpp', - 'active_move_primaries_registry_test.cpp', 'balancer/balance_stats_test.cpp', 'chunk_split_state_driver_test.cpp', 'collection_metadata_filtering_test.cpp', diff --git a/src/mongo/db/s/active_move_primaries_registry.cpp b/src/mongo/db/s/active_move_primaries_registry.cpp deleted file mode 100644 index 42aef0235eb..00000000000 --- a/src/mongo/db/s/active_move_primaries_registry.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Copyright (C) 2018-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/platform/basic.h" - -#include "mongo/db/s/active_move_primaries_registry.h" - -#include "mongo/db/service_context.h" - -namespace mongo { -namespace { - -const auto getRegistry = ServiceContext::declareDecoration<ActiveMovePrimariesRegistry>(); - -} // namespace - -ActiveMovePrimariesRegistry::ActiveMovePrimariesRegistry() = default; - -ActiveMovePrimariesRegistry::~ActiveMovePrimariesRegistry() { - invariant(!_activeMovePrimaryState); -} - -ActiveMovePrimariesRegistry& ActiveMovePrimariesRegistry::get(ServiceContext* service) { - return getRegistry(service); -} - -ActiveMovePrimariesRegistry& ActiveMovePrimariesRegistry::get(OperationContext* opCtx) { - return get(opCtx->getServiceContext()); -} - -StatusWith<ScopedMovePrimary> ActiveMovePrimariesRegistry::registerMovePrimary( - const ShardMovePrimary& requestArgs) { - stdx::lock_guard<Latch> lk(_mutex); - if (_activeMovePrimaryState) { - if (_activeMovePrimaryState->requestArgs == requestArgs) { - return {ScopedMovePrimary(nullptr, false, _activeMovePrimaryState->notification)}; - } - - return _activeMovePrimaryState->constructErrorStatus(); - } - - _activeMovePrimaryState.emplace(requestArgs); - - return {ScopedMovePrimary(this, true, _activeMovePrimaryState->notification)}; -} - -boost::optional<NamespaceString> ActiveMovePrimariesRegistry::getActiveMovePrimaryNss() { - stdx::lock_guard<Latch> lk(_mutex); - if (_activeMovePrimaryState) { - return _activeMovePrimaryState->requestArgs.get_shardsvrMovePrimary(); - } - - return boost::none; -} - -void ActiveMovePrimariesRegistry::_clearMovePrimary() { - stdx::lock_guard<Latch> lk(_mutex); - invariant(_activeMovePrimaryState); - _activeMovePrimaryState.reset(); -} - -Status ActiveMovePrimariesRegistry::ActiveMovePrimaryState::constructErrorStatus() const { - return {ErrorCodes::ConflictingOperationInProgress, - str::stream() - << "Unable to start new movePrimary operation because this shard is currently " - "moving its primary for namespace " - << requestArgs.get_shardsvrMovePrimary() << " to " << requestArgs.getTo()}; -} - -ScopedMovePrimary::ScopedMovePrimary(ActiveMovePrimariesRegistry* registry, - bool shouldExecute, - std::shared_ptr<Notification<Status>> completionNotification) - : _registry(registry), - _shouldExecute(shouldExecute), - _completionNotification(std::move(completionNotification)) {} - -ScopedMovePrimary::~ScopedMovePrimary() { - if (_registry) { - // If this is a movePrimary that didn't join an existing movePrimary, the caller must - // signal on completion. - invariant(_shouldExecute); - invariant(*_completionNotification); - _registry->_clearMovePrimary(); - } -} - -ScopedMovePrimary::ScopedMovePrimary(ScopedMovePrimary&& other) { - *this = std::move(other); -} - -ScopedMovePrimary& ScopedMovePrimary::operator=(ScopedMovePrimary&& other) { - if (&other != this) { - _registry = other._registry; - other._registry = nullptr; - _shouldExecute = other._shouldExecute; - _completionNotification = std::move(other._completionNotification); - } - - return *this; -} - -void ScopedMovePrimary::signalComplete(Status status) { - invariant(_shouldExecute); - _completionNotification->set(status); -} - -Status ScopedMovePrimary::waitForCompletion(OperationContext* opCtx) { - invariant(!_shouldExecute); - return _completionNotification->get(opCtx); -} - -} // namespace mongo diff --git a/src/mongo/db/s/active_move_primaries_registry.h b/src/mongo/db/s/active_move_primaries_registry.h deleted file mode 100644 index 94f55657cba..00000000000 --- a/src/mongo/db/s/active_move_primaries_registry.h +++ /dev/null @@ -1,162 +0,0 @@ -/** - * Copyright (C) 2018-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/s/request_types/move_primary_gen.h" -#include "mongo/util/concurrency/notification.h" - -namespace mongo { - -class ScopedMovePrimary; - -/** - * Thread-safe object that keeps track of active movePrimary commands running on a node and limits - * them to only one per shard. There is only one instance of this object per shard. - */ - -class ActiveMovePrimariesRegistry { - ActiveMovePrimariesRegistry(const ActiveMovePrimariesRegistry&) = delete; - ActiveMovePrimariesRegistry& operator=(const ActiveMovePrimariesRegistry&) = delete; - -public: - ActiveMovePrimariesRegistry(); - ~ActiveMovePrimariesRegistry(); - - static ActiveMovePrimariesRegistry& get(ServiceContext* service); - static ActiveMovePrimariesRegistry& get(OperationContext* opCtx); - - /** - * If there are no movePrimary operations running on this shard, registers an active - * movePrimary operation with the specified arguments. Returns a ScopedMovePrimary, which must - * be signaled by the caller before it goes out of scope. - * - * If there is an active movePrimary operation already running on this shard and it has the - * exact same arguments, returns a ScopedMovePrimary, which can be used to join the already - * running movePrimary command. - * - * Otherwise returns a ConflictingOperationInProgress error. - */ - StatusWith<ScopedMovePrimary> registerMovePrimary(const ShardMovePrimary& requestArgs); - - /** - * If a movePrimary command has been previously registered through a call to - * registerMovePrimary, returns that namespace. Otherwise returns boost::none. - */ - boost::optional<NamespaceString> getActiveMovePrimaryNss(); - -private: - friend class ScopedMovePrimary; - - // Describes the state of a current active movePrimary operation. - struct ActiveMovePrimaryState { - ActiveMovePrimaryState(ShardMovePrimary inRequestArgs) - : requestArgs(std::move(inRequestArgs)), - notification(std::make_shared<Notification<Status>>()) {} - - /** - * Constructs an error status to return in the case of conflicting operations. - */ - Status constructErrorStatus() const; - - // Exact arguments of the currently active operation - ShardMovePrimary requestArgs; - - // Notification event, which will be signaled when the currently active operation completes - std::shared_ptr<Notification<Status>> notification; - }; - - /** - * Unregisters a previously registered namespace with an ongoing movePrimary operation. Must - * only be called if a previous call to registerMovePrimary has succeeded. - */ - void _clearMovePrimary(); - - // Protects the state below - Mutex _mutex = MONGO_MAKE_LATCH("ActiveMovePrimariesRegistry::_mutex"); - - // If there is an active movePrimary operation going on, this field contains the request that - // initiated it. - boost::optional<ActiveMovePrimaryState> _activeMovePrimaryState; -}; - -/** - * An object of this class is returned from the registerMovePrimary call of the current active - * movePrimaries registry. It can exist in two modes - 'execute' and 'join.' See the comments for - * registerMovePrimary for more details. - */ -class ScopedMovePrimary { - ScopedMovePrimary(const ScopedMovePrimary&) = delete; - ScopedMovePrimary& operator=(const ScopedMovePrimary&) = delete; - -public: - ScopedMovePrimary(ActiveMovePrimariesRegistry* registry, - bool shouldExecute, - std::shared_ptr<Notification<Status>> completionNotification); - ~ScopedMovePrimary(); - - ScopedMovePrimary(ScopedMovePrimary&&); - ScopedMovePrimary& operator=(ScopedMovePrimary&&); - - /** - * Returns true if the registerMovePrimary object is in the 'execute' mode. This means that - * the registerMovePrimary object holder is next in line to execute the movePrimary command. - * The holder must execute the command and call signalComplete with a status. - */ - bool mustExecute() const { - return _shouldExecute; - } - - /** - * Must only be called if the object was in the 'execute' mode when the movePrimary command - * was invoked (the command immediately executed). Signals any callers that might be blocked in - * waitForCompletion. - */ - void signalComplete(Status status); - - /** - * Must only be called if the object is in the 'join' mode. Blocks until the main executor of - * the movePrimary command calls signalComplete. - */ - Status waitForCompletion(OperationContext* opCtx); - -private: - // Registry from which to unregister the movePrimary. Not owned. - ActiveMovePrimariesRegistry* _registry; - - /* Whether the holder is the first in line to call the movePrimary command (in which case the - * destructor must unregister) or the caller is joining on an already-running movePrimary - * operation (in which case the caller must block and wait for completion). - */ - bool _shouldExecute; - - // This is the future, which will be signaled at the end of a movePrimary command. - std::shared_ptr<Notification<Status>> _completionNotification; -}; -} // namespace mongo diff --git a/src/mongo/db/s/active_move_primaries_registry_test.cpp b/src/mongo/db/s/active_move_primaries_registry_test.cpp deleted file mode 100644 index 6b6541accf6..00000000000 --- a/src/mongo/db/s/active_move_primaries_registry_test.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/** - * Copyright (C) 2018-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/bson/bsonmisc.h" -#include "mongo/db/client.h" -#include "mongo/db/s/active_move_primaries_registry.h" -#include "mongo/db/service_context_d_test_fixture.h" -#include "mongo/s/request_types/move_primary_gen.h" -#include "mongo/unittest/unittest.h" - -namespace mongo { -namespace { - -using unittest::assertGet; - -class MovePrimaryRegistration : public ServiceContextMongoDTest { -protected: - ActiveMovePrimariesRegistry _registry; -}; - -ShardMovePrimary createMovePrimaryRequest(const NamespaceString& nss) { - ShardMovePrimary request; - request.set_shardsvrMovePrimary(std::move(nss)); - request.setTo("shard0001"); - - return request; -} - -TEST_F(MovePrimaryRegistration, ScopedPrimaryMoveConstructorAndAssignment) { - auto originalScopedMovePrimary = assertGet( - _registry.registerMovePrimary(createMovePrimaryRequest(NamespaceString("TestDB")))); - ASSERT(originalScopedMovePrimary.mustExecute()); - - ScopedMovePrimary movedScopedMovePrimary(std::move(originalScopedMovePrimary)); - ASSERT(movedScopedMovePrimary.mustExecute()); - - originalScopedMovePrimary = std::move(movedScopedMovePrimary); - ASSERT(originalScopedMovePrimary.mustExecute()); - - // Need to signal the registered migration so the destructor doesn't invariant - originalScopedMovePrimary.signalComplete(Status::OK()); -} - -TEST_F(MovePrimaryRegistration, GetActiveMovePrimaryNamespace) { - ASSERT(!_registry.getActiveMovePrimaryNss()); - - const NamespaceString nss("TestDB"); - - auto originalScopedMovePrimary = - assertGet(_registry.registerMovePrimary(createMovePrimaryRequest(nss))); - - ASSERT_EQ(nss.ns(), _registry.getActiveMovePrimaryNss()->ns()); - - // Need to signal the registered migration so the destructor doesn't invariant - originalScopedMovePrimary.signalComplete(Status::OK()); -} - -TEST_F(MovePrimaryRegistration, SecondMovePrimaryReturnsConflictingOperationInProgress) { - auto originalScopedMovePrimary = assertGet( - _registry.registerMovePrimary(createMovePrimaryRequest(NamespaceString("TestDB")))); - - auto secondScopedMovePrimaryStatus = - _registry.registerMovePrimary(createMovePrimaryRequest(NamespaceString("TestDB2"))); - ASSERT_EQ(ErrorCodes::ConflictingOperationInProgress, - secondScopedMovePrimaryStatus.getStatus()); - - originalScopedMovePrimary.signalComplete(Status::OK()); -} - -TEST_F(MovePrimaryRegistration, SecondMovePrimaryWithSameArgumentsJoinsFirst) { - auto originalScopedMovePrimary = assertGet( - _registry.registerMovePrimary(createMovePrimaryRequest(NamespaceString("TestDB")))); - ASSERT(originalScopedMovePrimary.mustExecute()); - - auto secondScopedMovePrimary = assertGet( - _registry.registerMovePrimary(createMovePrimaryRequest(NamespaceString("TestDB")))); - ASSERT(!secondScopedMovePrimary.mustExecute()); - - originalScopedMovePrimary.signalComplete({ErrorCodes::InternalError, "Test error"}); - auto opCtx = makeOperationContext(); - ASSERT_EQ(Status(ErrorCodes::InternalError, "Test error"), - secondScopedMovePrimary.waitForCompletion(opCtx.get())); -} - -} // namespace -} // namespace mongo diff --git a/src/mongo/db/s/config/configsvr_commit_move_primary_command.cpp b/src/mongo/db/s/config/configsvr_commit_move_primary_command.cpp deleted file mode 100644 index 5927cdac3fd..00000000000 --- a/src/mongo/db/s/config/configsvr_commit_move_primary_command.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Copyright (C) 2018-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. - */ - -#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding - -#include "mongo/platform/basic.h" - -#include "mongo/db/auth/authorization_session.h" -#include "mongo/db/commands.h" -#include "mongo/db/repl/read_concern_args.h" -#include "mongo/db/s/config/sharding_catalog_manager.h" -#include "mongo/s/request_types/move_primary_gen.h" - -// TODO SERVER-54879 throw out this file once 5.0 becomes last-LTS -namespace mongo { -namespace { - -class ConfigSvrCommitMovePrimaryCommand : public BasicCommand { -public: - ConfigSvrCommitMovePrimaryCommand() : BasicCommand("_configsvrCommitMovePrimary") {} - - std::string help() const override { - return "should not be calling this directly"; - } - - AllowedOnSecondary secondaryAllowed(ServiceContext*) const override { - return AllowedOnSecondary::kNever; - } - - bool adminOnly() const override { - return true; - } - - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { - return true; - } - - Status checkAuthForCommand(Client* client, - const std::string& dbname, - const BSONObj& cmdObj) const override { - if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( - ResourcePattern::forClusterResource(), ActionType::internal)) { - return Status(ErrorCodes::Unauthorized, "Unauthorized"); - } - return Status::OK(); - } - - bool run(OperationContext* opCtx, - const std::string& dbName_unused, - const BSONObj& cmdObj, - BSONObjBuilder& result) override { - uassert(ErrorCodes::IllegalOperation, - "_configsvrCommitMovePrimary can only be run on config servers", - serverGlobalParams.clusterRole == ClusterRole::ConfigServer); - - // Set the operation context read concern level to local for reads into the config database. - repl::ReadConcernArgs::get(opCtx) = - repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern); - - uassert(ErrorCodes::InvalidOptions, - str::stream() << "commitMovePrimary must be called with majority writeConcern, got " - << cmdObj, - opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority); - - const auto commitMovePrimaryRequest = ConfigsvrCommitMovePrimary::parse( - IDLParserErrorContext("_configSvrCommitMovePrimary"), cmdObj); - - const auto dbname = commitMovePrimaryRequest.get_configsvrCommitMovePrimary(); - - uassertStatusOK(ShardingCatalogManager::get(opCtx)->commitMovePrimary( - opCtx, dbname, commitMovePrimaryRequest.getTo().toString())); - - return true; - } - -} configsvrCommitMovePrimaryCommand; - -} // namespace -} // namespace mongo diff --git a/src/mongo/db/s/config/configsvr_move_primary_command.cpp b/src/mongo/db/s/config/configsvr_move_primary_command.cpp deleted file mode 100644 index 2977d9fe812..00000000000 --- a/src/mongo/db/s/config/configsvr_move_primary_command.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/** - * Copyright (C) 2018-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. - */ - -#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding - -#include "mongo/platform/basic.h" - -#include "mongo/client/connpool.h" -#include "mongo/db/auth/action_set.h" -#include "mongo/db/auth/action_type.h" -#include "mongo/db/auth/authorization_session.h" -#include "mongo/db/catalog/document_validation.h" -#include "mongo/db/client.h" -#include "mongo/db/commands.h" -#include "mongo/db/commands/feature_compatibility_version.h" -#include "mongo/db/operation_context.h" -#include "mongo/db/repl/read_concern_args.h" -#include "mongo/db/repl/repl_client_info.h" -#include "mongo/db/s/dist_lock_manager.h" -#include "mongo/db/server_options.h" -#include "mongo/logv2/log.h" -#include "mongo/s/catalog/type_database.h" -#include "mongo/s/catalog_cache.h" -#include "mongo/s/client/shard_registry.h" -#include "mongo/s/cluster_commands_helpers.h" -#include "mongo/s/grid.h" -#include "mongo/s/request_types/move_primary_gen.h" -#include "mongo/util/scopeguard.h" - -// TODO (SERVER-54879): Remove this command entirely after 5.0 branches -namespace mongo { -namespace { - -const WriteConcernOptions kMajorityWriteConcern(WriteConcernOptions::kMajority, - WriteConcernOptions::SyncMode::UNSET, - WriteConcernOptions::kWriteConcernTimeoutSharding); - -/** - * Internal sharding command run on config servers to change a database's primary shard. - */ -class ConfigSvrMovePrimaryCommand : public BasicCommand { -public: - ConfigSvrMovePrimaryCommand() : BasicCommand("_configsvrMovePrimary") {} - - AllowedOnSecondary secondaryAllowed(ServiceContext*) const override { - return AllowedOnSecondary::kNever; - } - - virtual bool adminOnly() const { - return true; - } - - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { - return true; - } - - std::string help() const override { - return "Internal command, which is exported by the sharding config server. Do not call " - "directly. Reassigns the primary shard of a database."; - } - - virtual Status checkAuthForCommand(Client* client, - const std::string& dbname, - const BSONObj& cmdObj) const override { - if (!AuthorizationSession::get(client)->isAuthorizedForActionsOnResource( - ResourcePattern::forClusterResource(), ActionType::internal)) { - return Status(ErrorCodes::Unauthorized, "Unauthorized"); - } - - return Status::OK(); - } - - virtual std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const { - const auto nsElt = cmdObj.firstElement(); - uassert(ErrorCodes::InvalidNamespace, - "'movePrimary' must be of type String", - nsElt.type() == BSONType::String); - return nsElt.str(); - } - - bool run(OperationContext* opCtx, - const std::string& dbname_unused, - const BSONObj& cmdObj, - BSONObjBuilder& result) override { - uassert(ErrorCodes::IllegalOperation, - "_configsvrMovePrimary can only be run on config servers", - serverGlobalParams.clusterRole == ClusterRole::ConfigServer); - - // Set the operation context read concern level to local for reads into the config database. - repl::ReadConcernArgs::get(opCtx) = - repl::ReadConcernArgs(repl::ReadConcernLevel::kLocalReadConcern); - - auto movePrimaryRequest = - MovePrimary::parse(IDLParserErrorContext("ConfigSvrMovePrimary"), cmdObj); - const auto dbname = parseNs("", cmdObj); - - uassert( - ErrorCodes::InvalidNamespace, - str::stream() << "invalid db name specified: " << dbname, - NamespaceString::validDBName(dbname, NamespaceString::DollarInDbNameBehavior::Allow)); - - if (dbname == NamespaceString::kAdminDb || dbname == NamespaceString::kConfigDb || - dbname == NamespaceString::kLocalDb) { - uasserted(ErrorCodes::InvalidOptions, - str::stream() << "Can't move primary for " << dbname << " database"); - } - - uassert(ErrorCodes::InvalidOptions, - str::stream() << "movePrimary must be called with majority writeConcern, got " - << cmdObj, - opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority); - - const std::string to = movePrimaryRequest.getTo().toString(); - - if (to.empty()) { - uasserted(ErrorCodes::InvalidOptions, - str::stream() << "you have to specify where you want to move it"); - } - - auto const catalogClient = Grid::get(opCtx)->catalogClient(); - auto const shardRegistry = Grid::get(opCtx)->shardRegistry(); - - auto dbDistLock = uassertStatusOK(DistLockManager::get(opCtx)->lock( - opCtx, dbname, "movePrimary", DistLockManager::kDefaultLockTimeout)); - - auto dbType = - catalogClient->getDatabase(opCtx, dbname, repl::ReadConcernArgs::get(opCtx).getLevel()); - const auto fromShard = uassertStatusOK(shardRegistry->getShard(opCtx, dbType.getPrimary())); - - const auto toShard = [&]() { - auto toShardStatus = shardRegistry->getShard(opCtx, to); - if (!toShardStatus.isOK()) { - LOGV2(21921, - "Could not move database {db} to shard {shardId}: {error}", - "Could not move database to shard", - "db"_attr = dbname, - "shardId"_attr = to, - "error"_attr = toShardStatus.getStatus()); - uassertStatusOKWithContext(toShardStatus.getStatus(), - str::stream() << "Could not move database '" << dbname - << "' to shard '" << to << "'"); - } - - return toShardStatus.getValue(); - }(); - - if (fromShard->getId() == toShard->getId()) { - // We did a local read of the database entry above and found that this movePrimary - // request was already satisfied. However, the data may not be majority committed (a - // previous movePrimary attempt may have failed with a write concern error). - // Since the current Client doesn't know the opTime of the last write to the database - // entry, make it wait for the last opTime in the system when we wait for writeConcern. - repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx); - result << "primary" << toShard->toString(); - return true; - } - - ShardMovePrimary shardMovePrimaryRequest; - shardMovePrimaryRequest.set_shardsvrMovePrimary(NamespaceString(dbname)); - shardMovePrimaryRequest.setTo(toShard->getId().toString()); - - auto cmdResponse = uassertStatusOK(fromShard->runCommandWithFixedRetryAttempts( - opCtx, - ReadPreferenceSetting(ReadPreference::PrimaryOnly), - "admin", - CommandHelpers::appendMajorityWriteConcern( - CommandHelpers::appendGenericCommandArgs(cmdObj, shardMovePrimaryRequest.toBSON())), - Shard::RetryPolicy::kIdempotent)); - - CommandHelpers::filterCommandReplyForPassthrough(cmdResponse.response, &result); - - return true; - } - -} configsvrMovePrimaryCmd; - -} // namespace -} // namespace mongo diff --git a/src/mongo/db/s/config/sharding_catalog_manager.h b/src/mongo/db/s/config/sharding_catalog_manager.h index 5c28a90a101..15142fc8b46 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.h +++ b/src/mongo/db/s/config/sharding_catalog_manager.h @@ -346,13 +346,6 @@ public: const boost::optional<ShardId>& optPrimaryShard, bool enableSharding); - /** - * Updates metadata in config.databases collection to show the given primary database on its - * new shard. - */ - // TODO SERVER-54879 throw out this method once 5.0 becomes last-LTS - Status commitMovePrimary(OperationContext* opCtx, const StringData nss, const ShardId& toShard); - // // Collection Operations // diff --git a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp index 622c414458d..0a0d1157987 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_database_operations.cpp @@ -260,81 +260,4 @@ DatabaseType ShardingCatalogManager::createDatabase(OperationContext* opCtx, return database; } -Status ShardingCatalogManager::commitMovePrimary(OperationContext* opCtx, - const StringData dbname, - const ShardId& toShard) { - - auto const configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard(); - - // TODO (SERVER-53283): Remove once version 5.0 has been released. - Lock::SharedLock lock(opCtx->lockState(), _kDatabaseOpLock); - - // Must use local read concern because we will perform subsequent writes. - auto findResponse = uassertStatusOK( - configShard->exhaustiveFindOnConfig(opCtx, - ReadPreferenceSetting{ReadPreference::PrimaryOnly}, - repl::ReadConcernLevel::kLocalReadConcern, - DatabaseType::ConfigNS, - BSON(DatabaseType::name << dbname), - BSON(DatabaseType::name << -1), - 1)); - - const auto databasesVector = std::move(findResponse.docs); - uassert(ErrorCodes::IncompatibleShardingMetadata, - str::stream() << "Tried to find max database version for database '" << dbname - << "', but found no databases", - !databasesVector.empty()); - - const auto dbType = uassertStatusOK(DatabaseType::fromBSON(databasesVector.front())); - - if (dbType.getPrimary() == toShard) { - // The primary has already been set to the destination shard. It's likely that there was a - // network error and the shard resent the command. - repl::ReplClientInfo::forClient(opCtx->getClient()).setLastOpToSystemLastOpTime(opCtx); - return Status::OK(); - } - - auto newDbType = dbType; - newDbType.setPrimary(toShard); - - auto const currentDatabaseVersion = dbType.getVersion(); - - newDbType.setVersion(currentDatabaseVersion.makeUpdated()); - - auto updateQueryBuilder = BSONObjBuilder(BSON(DatabaseType::name << dbname)); - updateQueryBuilder.append(DatabaseType::version.name(), currentDatabaseVersion.toBSON()); - - auto updateStatus = Grid::get(opCtx)->catalogClient()->updateConfigDocument( - opCtx, - DatabaseType::ConfigNS, - updateQueryBuilder.obj(), - newDbType.toBSON(), - false, - ShardingCatalogClient::kLocalWriteConcern); - - if (!updateStatus.isOK()) { - LOGV2(21940, - "Error committing movePrimary for {db}: {error}", - "Error committing movePrimary", - "db"_attr = dbname, - "error"_attr = redact(updateStatus.getStatus())); - return updateStatus.getStatus(); - } - - // If this assertion is tripped, it means that the request sent fine, but no documents were - // updated. This is likely because the database version was changed in between the query and - // the update, so no documents were found to change. This shouldn't happen however, because we - // are holding the dist lock during the movePrimary operation. - uassert(ErrorCodes::IncompatibleShardingMetadata, - str::stream() << "Tried to update primary shard for database '" << dbname - << " with version " << currentDatabaseVersion.getLastMod(), - updateStatus.getValue()); - - // Ensure the next attempt to retrieve the database or any of its collections will do a full - // reload - Grid::get(opCtx)->catalogCache()->purgeDatabase(dbname); - - return Status::OK(); -} - } // namespace mongo diff --git a/src/mongo/db/s/move_primary_coordinator.cpp b/src/mongo/db/s/move_primary_coordinator.cpp index 3157a23959e..03b04474a43 100644 --- a/src/mongo/db/s/move_primary_coordinator.cpp +++ b/src/mongo/db/s/move_primary_coordinator.cpp @@ -34,40 +34,14 @@ #include "mongo/db/s/move_primary_coordinator.h" #include "mongo/db/auth/authorization_session.h" -#include "mongo/db/catalog_raii.h" -#include "mongo/db/commands.h" -#include "mongo/db/db_raii.h" -#include "mongo/db/s/active_move_primaries_registry.h" -#include "mongo/db/s/collection_sharding_runtime.h" -#include "mongo/db/s/dist_lock_manager.h" #include "mongo/db/s/move_primary_source_manager.h" -#include "mongo/db/s/shard_metadata_util.h" -#include "mongo/db/s/sharding_ddl_util.h" #include "mongo/db/s/sharding_state.h" #include "mongo/logv2/log.h" #include "mongo/s/client/shard_registry.h" -#include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/grid.h" -#include "mongo/s/request_types/sharded_ddl_commands_gen.h" #include "mongo/s/shard_id.h" namespace mongo { -namespace { -/** - * If the specified status is not OK logs a warning and throws a DBException corresponding to the - * specified status. - */ -void uassertStatusOKWithWarning(const Status& status) { - if (!status.isOK()) { - LOGV2_WARNING(5275800, - "movePrimary failed: {error}", - "movePrimary failed", - "error"_attr = redact(status)); - uassertStatusOK(status); - } -} - -} // namespace MovePrimaryCoordinator::MovePrimaryCoordinator(ShardingDDLCoordinatorService* service, const BSONObj& initialState) @@ -126,10 +100,8 @@ ExecutorFuture<void> MovePrimaryCoordinator::_runImpl( shardRegistry->reload(opCtx); const auto& dbName = nss().db(); - const auto& toShard = uassertStatusOKWithContext( - shardRegistry->getShard(opCtx, _doc.getToShardId()), - str::stream() << "Could not move database '" << dbName << "' to shard '" - << _doc.getToShardId() << "'"); + const auto& toShard = + uassertStatusOK(shardRegistry->getShard(opCtx, _doc.getToShardId())); const auto& selfShardId = ShardingState::get(opCtx)->shardId(); if (selfShardId == toShard->getId()) { @@ -147,10 +119,10 @@ ExecutorFuture<void> MovePrimaryCoordinator::_runImpl( auto toId = toShard->getId(); MovePrimarySourceManager movePrimarySourceManager( opCtx, movePrimaryRequest, dbName, primaryId, toId); - uassertStatusOKWithWarning(movePrimarySourceManager.clone(opCtx)); - uassertStatusOKWithWarning(movePrimarySourceManager.enterCriticalSection(opCtx)); - uassertStatusOKWithWarning(movePrimarySourceManager.commitOnConfig(opCtx)); - uassertStatusOKWithWarning(movePrimarySourceManager.cleanStaleData(opCtx)); + uassertStatusOK(movePrimarySourceManager.clone(opCtx)); + uassertStatusOK(movePrimarySourceManager.enterCriticalSection(opCtx)); + uassertStatusOK(movePrimarySourceManager.commitOnConfig(opCtx)); + uassertStatusOK(movePrimarySourceManager.cleanStaleData(opCtx)); }) .onError([this, anchor = shared_from_this()](const Status& status) { LOGV2_ERROR(5275804, diff --git a/src/mongo/db/s/op_observer_sharding_impl.cpp b/src/mongo/db/s/op_observer_sharding_impl.cpp index 2154b380ae5..48178fa421a 100644 --- a/src/mongo/db/s/op_observer_sharding_impl.cpp +++ b/src/mongo/db/s/op_observer_sharding_impl.cpp @@ -35,7 +35,6 @@ #include "mongo/db/catalog_raii.h" #include "mongo/db/repl/oplog_entry.h" -#include "mongo/db/s/active_move_primaries_registry.h" #include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/db/s/database_sharding_state.h" #include "mongo/db/s/migration_chunk_cloner_source_legacy.h" diff --git a/src/mongo/db/s/shardsvr_move_primary_command.cpp b/src/mongo/db/s/shardsvr_move_primary_command.cpp index a6171b7164a..4abf7d7af5c 100644 --- a/src/mongo/db/s/shardsvr_move_primary_command.cpp +++ b/src/mongo/db/s/shardsvr_move_primary_command.cpp @@ -33,55 +33,14 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/commands.h" -#include "mongo/db/s/active_move_primaries_registry.h" -#include "mongo/db/s/dist_lock_manager.h" #include "mongo/db/s/move_primary_coordinator.h" -#include "mongo/db/s/move_primary_source_manager.h" #include "mongo/db/s/sharding_state.h" -#include "mongo/logv2/log.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/move_primary_gen.h" namespace mongo { namespace { -/** - * If the specified status is not OK logs a warning and throws a DBException corresponding to the - * specified status. - */ -void uassertStatusOKWithWarning(const Status& status) { - if (!status.isOK()) { - LOGV2_WARNING(23762, - "movePrimary failed: {error}", - "movePrimary failed", - "error"_attr = redact(status)); - uassertStatusOK(status); - } -} - -void newMovePrimaryFlow(OperationContext* opCtx, - const ShardMovePrimary& cmdObj, - const NamespaceString& dbNss, - const StringData& toShard) { - auto const shardingState = ShardingState::get(opCtx); - uassertStatusOK(shardingState->canAcceptShardedCommands()); - - uassert(ErrorCodes::InvalidOptions, - str::stream() << "Move primary must be called with majority writeConcern, got " - << opCtx->getWriteConcern().wMode, - opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority); - - auto coordinatorDoc = MovePrimaryCoordinatorDocument(); - coordinatorDoc.setShardingDDLCoordinatorMetadata( - {{dbNss, DDLCoordinatorTypeEnum::kMovePrimary}}); - coordinatorDoc.setToShardId(ShardId(cmdObj.getTo().toString())); - - auto service = ShardingDDLCoordinatorService::getService(opCtx); - auto movePrimaryCoordinator = checked_pointer_cast<MovePrimaryCoordinator>( - service->getOrCreateInstance(opCtx, coordinatorDoc.toBSON())); - movePrimaryCoordinator->getCompletionFuture().get(opCtx); -} - class MovePrimaryCommand : public BasicCommand { public: MovePrimaryCommand() : BasicCommand("_shardsvrMovePrimary") {} @@ -124,8 +83,7 @@ public: const std::string& dbname_unused, const BSONObj& cmdObj, BSONObjBuilder& result) override { - auto const shardingState = ShardingState::get(opCtx); - uassertStatusOK(shardingState->canAcceptShardedCommands()); + uassertStatusOK(ShardingState::get(opCtx)->canAcceptShardedCommands()); const auto movePrimaryRequest = ShardMovePrimary::parse(IDLParserErrorContext("_shardsvrMovePrimary"), cmdObj); @@ -156,53 +114,17 @@ public: ON_BLOCK_EXIT( [opCtx, dbNss] { Grid::get(opCtx)->catalogCache()->purgeDatabase(dbNss.db()); }); - if (movePrimaryRequest.getCommandIsFromRouter()) { - newMovePrimaryFlow(opCtx, movePrimaryRequest, dbNss, toShard); - return true; - } - - // Make sure we're as up-to-date as possible with shard information. This catches the case - // where we might have changed a shard's host by removing/adding a shard with the same name. - Grid::get(opCtx)->shardRegistry()->reload(opCtx); - - auto scopedMovePrimary = uassertStatusOK( - ActiveMovePrimariesRegistry::get(opCtx).registerMovePrimary(movePrimaryRequest)); - - // Check if there is an existing movePrimary running and if so, join it - if (scopedMovePrimary.mustExecute()) { - auto status = [&] { - try { - _runImpl(opCtx, movePrimaryRequest, dbname); - return Status::OK(); - } catch (const DBException& ex) { - return ex.toStatus(); - } - }(); - scopedMovePrimary.signalComplete(status); - uassertStatusOK(status); - } else { - uassertStatusOK(scopedMovePrimary.waitForCompletion(opCtx)); - } + auto coordinatorDoc = MovePrimaryCoordinatorDocument(); + coordinatorDoc.setShardingDDLCoordinatorMetadata( + {{dbNss, DDLCoordinatorTypeEnum::kMovePrimary}}); + coordinatorDoc.setToShardId(toShard.toString()); + auto service = ShardingDDLCoordinatorService::getService(opCtx); + auto movePrimaryCoordinator = checked_pointer_cast<MovePrimaryCoordinator>( + service->getOrCreateInstance(opCtx, coordinatorDoc.toBSON())); + movePrimaryCoordinator->getCompletionFuture().get(opCtx); return true; } - -private: - static void _runImpl(OperationContext* opCtx, - const ShardMovePrimary movePrimaryRequest, - const StringData dbname) { - ShardId fromShardId = ShardingState::get(opCtx)->shardId(); - ShardId toShardId = movePrimaryRequest.getTo().toString(); - - MovePrimarySourceManager movePrimarySourceManager( - opCtx, movePrimaryRequest, dbname, fromShardId, toShardId); - - uassertStatusOKWithWarning(movePrimarySourceManager.clone(opCtx)); - uassertStatusOKWithWarning(movePrimarySourceManager.enterCriticalSection(opCtx)); - uassertStatusOKWithWarning(movePrimarySourceManager.commitOnConfig(opCtx)); - uassertStatusOKWithWarning(movePrimarySourceManager.cleanStaleData(opCtx)); - } - } movePrimaryCmd; } // namespace diff --git a/src/mongo/s/commands/cluster_move_primary_cmd.cpp b/src/mongo/s/commands/cluster_move_primary_cmd.cpp index 19921e057a5..896db1fdf8a 100644 --- a/src/mongo/s/commands/cluster_move_primary_cmd.cpp +++ b/src/mongo/s/commands/cluster_move_primary_cmd.cpp @@ -31,17 +31,12 @@ #include "mongo/platform/basic.h" -#include "mongo/bson/util/bson_extract.h" -#include "mongo/db/audit.h" #include "mongo/db/auth/action_type.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/commands.h" #include "mongo/logv2/log.h" -#include "mongo/rpc/write_concern_error_detail.h" -#include "mongo/s/catalog/sharding_catalog_client.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog_cache.h" -#include "mongo/s/client/shard_registry.h" #include "mongo/s/cluster_commands_helpers.h" #include "mongo/s/grid.h" #include "mongo/s/request_types/move_primary_gen.h" @@ -108,7 +103,6 @@ public: ShardMovePrimary movePrimaryRequest; movePrimaryRequest.set_shardsvrMovePrimary(NamespaceString(db)); movePrimaryRequest.setTo(toShard); - movePrimaryRequest.setCommandIsFromRouter(true); auto catalogCache = Grid::get(opCtx)->catalogCache(); const auto dbInfo = uassertStatusOK(catalogCache->getDatabase(opCtx, db)); diff --git a/src/mongo/s/request_types/move_primary.idl b/src/mongo/s/request_types/move_primary.idl index 371a79aa99e..51d4a095b8a 100644 --- a/src/mongo/s/request_types/move_primary.idl +++ b/src/mongo/s/request_types/move_primary.idl @@ -62,32 +62,3 @@ structs: to: type: string description: "The shard serving as the destination for un-sharded collections." - # TODO SERVER-54879 remove the following field and adapt the code accordingly once 5.0 becomes last-LTS - commandIsFromRouter: - type: bool - description: "Indicates whether the command has been sent by a router" - default: false - - # TODO SERVER-54879 remove this parser once 5.0 becomes last-LTS - ConfigsvrMovePrimary: - description: "The internal movePrimary command on the config server" - strict: false - fields: - _configsvrMovePrimary: - type: namespacestring - description: "The namespace of the database whose primary shard is to be reassigned." - to: - type: string - description: "The shard serving as the destination for un-sharded collections." - - # TODO SERVER-54879 remove this parser once 5.0 becomes last-LTS - ConfigsvrCommitMovePrimary: - description: "The internal commitMovePrimary command on the config server" - strict: false - fields: - _configsvrCommitMovePrimary: - type: string - description: "The namespace of the database whose primary shard is to be reassigned." - to: - type: string - description: "The shard serving as the destination for un-sharded collections." |