diff options
author | Blake Oler <blake.oler@mongodb.com> | 2018-02-14 11:46:22 -0500 |
---|---|---|
committer | Blake Oler <blake.oler@mongodb.com> | 2018-02-21 12:27:14 -0500 |
commit | e126c24bdc87b79fb98905625c8c1c5b424679e6 (patch) | |
tree | f3b1cb343d2e6e69cae92cac9556f61955148a2d | |
parent | 788369eb773eede21ee0f492363bb7e64054ffd3 (diff) | |
download | mongo-e126c24bdc87b79fb98905625c8c1c5b424679e6.tar.gz |
SERVER-33195 create a movePrimary command for shards and _configsvrCommitMovePrimary command for config servers
8 files changed, 196 insertions, 4 deletions
diff --git a/jstests/core/views/views_all_commands.js b/jstests/core/views/views_all_commands.js index 03ff638550c..696e72fff80 100644 --- a/jstests/core/views/views_all_commands.js +++ b/jstests/core/views/views_all_commands.js @@ -69,6 +69,7 @@ _configsvrCommitChunkMerge: {skip: isAnInternalCommand}, _configsvrCommitChunkMigration: {skip: isAnInternalCommand}, _configsvrCommitChunkSplit: {skip: isAnInternalCommand}, + _configsvrCommitMovePrimary: {skip: isAnInternalCommand}, _configsvrCreateCollection: {skip: isAnInternalCommand}, _configsvrCreateDatabase: {skip: isAnInternalCommand}, _configsvrDropCollection: {skip: isAnInternalCommand}, @@ -87,6 +88,7 @@ _isSelf: {skip: isAnInternalCommand}, _mergeAuthzCollections: {skip: isAnInternalCommand}, _migrateClone: {skip: isAnInternalCommand}, + _movePrimary: {skip: isAnInternalCommand}, _recvChunkAbort: {skip: isAnInternalCommand}, _recvChunkCommit: {skip: isAnInternalCommand}, _recvChunkStart: {skip: isAnInternalCommand}, diff --git a/jstests/sharding/move_primary_basic.js b/jstests/sharding/move_primary_basic.js index ab4fa9e4761..e2e609fc866 100644 --- a/jstests/sharding/move_primary_basic.js +++ b/jstests/sharding/move_primary_basic.js @@ -18,10 +18,8 @@ st.ensurePrimaryShard(kDbName, shard0); assert.eq(shard0, mongos.getDB('config').databases.findOne({_id: kDbName}).primary); - // Can run only on mongos. - assert.commandFailedWithCode( - st.d0.getDB('admin').runCommand({movePrimary: kDbName, to: shard0}), - ErrorCodes.CommandNotFound); + // Can run on shards. + assert.commandWorked(st.d0.getDB('admin').runCommand({_movePrimary: kDbName, to: shard1})); // Can run only against the admin database. assert.commandFailedWithCode( diff --git a/jstests/sharding/safe_secondary_reads_drop_recreate.js b/jstests/sharding/safe_secondary_reads_drop_recreate.js index ed39354fb7c..35c794950d2 100644 --- a/jstests/sharding/safe_secondary_reads_drop_recreate.js +++ b/jstests/sharding/safe_secondary_reads_drop_recreate.js @@ -65,6 +65,7 @@ _configsvrCommitChunkMerge: {skip: "primary only"}, _configsvrCommitChunkMigration: {skip: "primary only"}, _configsvrCommitChunkSplit: {skip: "primary only"}, + _configsvrCommitMovePrimary: {skip: "primary only"}, _configsvrDropCollection: {skip: "primary only"}, _configsvrDropDatabase: {skip: "primary only"}, _configsvrMoveChunk: {skip: "primary only"}, @@ -78,6 +79,7 @@ _isSelf: {skip: "does not return user data"}, _mergeAuthzCollections: {skip: "primary only"}, _migrateClone: {skip: "primary only"}, + _movePrimary: {skip: "primary only"}, _recvChunkAbort: {skip: "primary only"}, _recvChunkCommit: {skip: "primary only"}, _recvChunkStart: {skip: "primary only"}, 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 a4ddc2b505a..06a9f152a52 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 @@ -72,6 +72,7 @@ _configsvrCommitChunkMerge: {skip: "primary only"}, _configsvrCommitChunkMigration: {skip: "primary only"}, _configsvrCommitChunkSplit: {skip: "primary only"}, + _configsvrCommitMovePrimary: {skip: "primary only"}, _configsvrDropCollection: {skip: "primary only"}, _configsvrDropDatabase: {skip: "primary only"}, _configsvrMoveChunk: {skip: "primary only"}, @@ -85,6 +86,7 @@ _isSelf: {skip: "does not return user data"}, _mergeAuthzCollections: {skip: "primary only"}, _migrateClone: {skip: "primary only"}, + _movePrimary: {skip: "primary only"}, _recvChunkAbort: {skip: "primary only"}, _recvChunkCommit: {skip: "primary only"}, _recvChunkStart: {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 03c65bc9b03..fab93b32a9f 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js @@ -65,6 +65,7 @@ _configsvrCommitChunkMerge: {skip: "primary only"}, _configsvrCommitChunkMigration: {skip: "primary only"}, _configsvrCommitChunkSplit: {skip: "primary only"}, + _configsvrCommitMovePrimary: {skip: "primary only"}, _configsvrDropCollection: {skip: "primary only"}, _configsvrDropDatabase: {skip: "primary only"}, _configsvrMoveChunk: {skip: "primary only"}, @@ -78,6 +79,7 @@ _isSelf: {skip: "does not return user data"}, _mergeAuthzCollections: {skip: "primary only"}, _migrateClone: {skip: "primary only"}, + _movePrimary: {skip: "primary only"}, _recvChunkAbort: {skip: "primary only"}, _recvChunkCommit: {skip: "primary only"}, _recvChunkStart: {skip: "primary only"}, diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 509d75f5e6b..45b90288a22 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -190,6 +190,7 @@ env.Library( 'config/configsvr_add_shard_command.cpp', 'config/configsvr_add_shard_to_zone_command.cpp', 'config/configsvr_commit_chunk_migration_command.cpp', + 'config/configsvr_commit_move_primary_command.cpp', 'config/configsvr_control_balancer_command.cpp', 'config/configsvr_create_collection_command.cpp', 'config/configsvr_create_database_command.cpp', @@ -210,6 +211,7 @@ env.Library( 'migration_chunk_cloner_source_legacy_commands.cpp', 'migration_destination_manager_legacy_commands.cpp', 'move_chunk_command.cpp', + 'move_primary_command.cpp', 'set_shard_version_command.cpp', 'sharding_server_status.cpp', 'sharding_state_command.cpp', 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 new file mode 100644 index 00000000000..d82b1bcc52b --- /dev/null +++ b/src/mongo/db/s/config/configsvr_commit_move_primary_command.cpp @@ -0,0 +1,97 @@ +/** + * Copyright (C) 2018 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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 + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * 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 GNU Affero General 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_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding + +#include "mongo/platform/basic.h" + +#include "mongo/db/auth/authorization_session.h" +#include "mongo/db/commands.h" +#include "mongo/util/log.h" + +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(); + } + + std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const override { + return CommandHelpers::parseNsFullyQualified(dbname, cmdObj); + } + + bool run(OperationContext* opCtx, + const std::string& dbName, + const BSONObj& cmdObj, + BSONObjBuilder& result) override { + + if (serverGlobalParams.clusterRole != ClusterRole::ConfigServer) { + return CommandHelpers::appendCommandStatus( + result, + Status(ErrorCodes::IllegalOperation, + "_configsvrCommitMovePrimary can only be run on config servers")); + } + + uassert(ErrorCodes::InvalidOptions, + str::stream() << "commitMovePrimary must be called with majority writeConcern, got " + << cmdObj, + opCtx->getWriteConcern().wMode == WriteConcernOptions::kMajority); + + return true; + } + +} configsvrCommitMovePrimaryCommand; + +} // namespace +} // namespace mongo diff --git a/src/mongo/db/s/move_primary_command.cpp b/src/mongo/db/s/move_primary_command.cpp new file mode 100644 index 00000000000..58ccf871748 --- /dev/null +++ b/src/mongo/db/s/move_primary_command.cpp @@ -0,0 +1,87 @@ +/** + * Copyright (C) 2018 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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 + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * 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 GNU Affero General 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_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding + +#include "mongo/platform/basic.h" + +#include "mongo/db/auth/authorization_session.h" +#include "mongo/db/commands.h" +#include "mongo/util/log.h" + +namespace mongo { +namespace { + +class MovePrimaryCommand : public BasicCommand { +public: + MovePrimaryCommand() : BasicCommand("_movePrimary") {} + + 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; + } + + 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, + const BSONObj& cmdObj, + BSONObjBuilder& result) override { + if (serverGlobalParams.clusterRole != ClusterRole::ShardServer) { + return CommandHelpers::appendCommandStatus( + result, + Status(ErrorCodes::IllegalOperation, + "_movePrimary can only be run on shard servers")); + } + + return true; + } + +} movePrimaryCmd; + +} // namespace +} // namespace mongo |