diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2018-01-30 19:40:46 -0500 |
---|---|---|
committer | Billy Donahue <billy.donahue@mongodb.com> | 2018-01-31 14:04:35 -0500 |
commit | be24b0323d3f2d424d9e22337f4221d39001ac31 (patch) | |
tree | 98577c05a24da852ec518699c4d039da5bbd7329 /src/mongo | |
parent | 0322da76ec976d240191b1ca8f70c2c732f9753a (diff) | |
download | mongo-be24b0323d3f2d424d9e22337f4221d39001ac31.tar.gz |
SERVER-32958 slaveOk,slaveOverrideOk replacement
declare read_preference dep. update service_entry_opint_embedded
Diffstat (limited to 'src/mongo')
169 files changed, 658 insertions, 660 deletions
diff --git a/src/mongo/client/embedded/SConscript b/src/mongo/client/embedded/SConscript index 57f9fd9cc48..16d45f9fba5 100644 --- a/src/mongo/client/embedded/SConscript +++ b/src/mongo/client/embedded/SConscript @@ -16,6 +16,7 @@ env.Library( LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/auth/authcore', '$BUILD_DIR/mongo/db/auth/authmongod', + '$BUILD_DIR/mongo/db/command_can_run_here', '$BUILD_DIR/mongo/db/ops/write_ops_exec', '$BUILD_DIR/mongo/db/rw_concern_d', '$BUILD_DIR/mongo/db/s/sharding', diff --git a/src/mongo/client/embedded/service_entry_point_embedded.cpp b/src/mongo/client/embedded/service_entry_point_embedded.cpp index 003c5ff95d3..dedf60c54c5 100644 --- a/src/mongo/client/embedded/service_entry_point_embedded.cpp +++ b/src/mongo/client/embedded/service_entry_point_embedded.cpp @@ -36,6 +36,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/auth/impersonation_session.h" #include "mongo/db/client.h" +#include "mongo/db/command_can_run_here.h" #include "mongo/db/commands.h" #include "mongo/db/commands/fsync.h" #include "mongo/db/concurrency/global_lock_acquisition_tracker.h" @@ -559,18 +560,13 @@ void execCommandDatabase(OperationContext* opCtx, if (!opCtx->getClient()->isInDirectClient() && !MONGO_FAIL_POINT(skipCheckingForNotMasterInCommandDispatch)) { - - bool commandCanRunOnSecondary = command->slaveOk(); - - bool commandIsOverriddenToRunOnSecondary = - command->slaveOverrideOk() && ReadPreferenceSetting::get(opCtx).canRunOnSecondary(); - - bool iAmStandalone = !opCtx->writesAreReplicated(); - bool canRunHere = iAmPrimary || commandCanRunOnSecondary || - commandIsOverriddenToRunOnSecondary || iAmStandalone; - - // This logic is clearer if we don't have to invert it. - if (!canRunHere && command->slaveOverrideOk()) { + auto allowed = command->secondaryAllowed(); + bool alwaysAllowed = allowed == Command::AllowedOnSecondary::kAlways; + bool couldHaveOptedIn = allowed == Command::AllowedOnSecondary::kOptIn; + bool optedIn = + couldHaveOptedIn && ReadPreferenceSetting::get(opCtx).canRunOnSecondary(); + bool canRunHere = commandCanRunHere(opCtx, dbname, command); + if (!canRunHere && couldHaveOptedIn) { uasserted(ErrorCodes::NotMasterNoSlaveOk, "not master and slaveOk=false"); } @@ -594,7 +590,7 @@ void execCommandDatabase(OperationContext* opCtx, // Check ticket SERVER-21432, slaveOk commands are allowed in drain mode uassert(ErrorCodes::NotMasterOrSecondary, "node is in drain mode", - commandIsOverriddenToRunOnSecondary || commandCanRunOnSecondary); + optedIn || alwaysAllowed); } } diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 6e9ac5f0aaa..3869a22a464 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -513,11 +513,26 @@ env.Library( 'auth/authcore', 'commands/server_status_core', 'commands/test_commands_enabled', + 'command_can_run_here', 'service_context', '$BUILD_DIR/mongo/db/catalog/uuid_catalog', ], ) +env.Library( + target='command_can_run_here', + source=[ + 'command_can_run_here.cpp', + ], + LIBDEPS=[ + '$BUILD_DIR/mongo/base', + '$BUILD_DIR/mongo/client/read_preference', + '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface', + 'service_context', + ], +) + + env.CppUnitTest( target="commands_test", source=[ @@ -597,6 +612,7 @@ env.Library( '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/transport/service_entry_point', 'auth/authmongod', + 'command_can_run_here', 'commands/dcommands_fsync', 'concurrency/lock_manager', 'curop', diff --git a/src/mongo/db/auth/sasl_commands.cpp b/src/mongo/db/auth/sasl_commands.cpp index 433439ad2b8..8a67b45879d 100644 --- a/src/mongo/db/auth/sasl_commands.cpp +++ b/src/mongo/db/auth/sasl_commands.cpp @@ -81,8 +81,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool requiresAuth() const override { return false; @@ -107,8 +107,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool requiresAuth() const override { return false; diff --git a/src/mongo/db/command_can_run_here.cpp b/src/mongo/db/command_can_run_here.cpp new file mode 100644 index 00000000000..c945380cc3e --- /dev/null +++ b/src/mongo/db/command_can_run_here.cpp @@ -0,0 +1,57 @@ +/** + * 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. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/command_can_run_here.h" + +#include "mongo/db/repl/replication_coordinator.h" +#include "mongo/client/read_preference.h" +#include "mongo/util/assert_util.h" + +namespace mongo { + +bool commandCanRunHere(OperationContext* opCtx, const std::string& dbname, const Command* command) { + auto replCoord = repl::ReplicationCoordinator::get(opCtx); + if (replCoord->canAcceptWritesForDatabase_UNSAFE(opCtx, dbname)) + return true; // primary: always ok + if (!opCtx->writesAreReplicated()) + return true; // standalone: always ok + switch (command->secondaryAllowed()) { + case Command::AllowedOnSecondary::kAlways: + return true; + case Command::AllowedOnSecondary::kNever: + return false; + case Command::AllowedOnSecondary::kOptIn: + // Did the user opt in? + return ReadPreferenceSetting::get(opCtx).canRunOnSecondary(); + } + MONGO_UNREACHABLE; +} + +} // namespace mongo diff --git a/src/mongo/db/command_can_run_here.h b/src/mongo/db/command_can_run_here.h new file mode 100644 index 00000000000..18ac4653593 --- /dev/null +++ b/src/mongo/db/command_can_run_here.h @@ -0,0 +1,40 @@ +/** + * 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. + */ + +#pragma once + +#include <string> + +#include "mongo/db/commands.h" +#include "mongo/db/operation_context.h" + +namespace mongo { + +bool commandCanRunHere(OperationContext* opCtx, const std::string& dbname, const Command* command); + +} // namespace mongo diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h index f1e580b69f8..58cadbfb3ef 100644 --- a/src/mongo/db/commands.h +++ b/src/mongo/db/commands.h @@ -188,6 +188,7 @@ struct CommandHelpers { class Command { public: using CommandMap = StringMap<Command*>; + enum class AllowedOnSecondary { kAlways, kNever, kOptIn }; /** * Constructs a new command and causes it to be registered with the global commands list. It is @@ -262,17 +263,7 @@ public: return false; } - /* Return true if slaves are allowed to execute the command - */ - virtual bool slaveOk() const = 0; - - /** - * Return true if the client force a command to be run on a slave by - * turning on the 'slaveOk' option in the command query. - */ - virtual bool slaveOverrideOk() const { - return false; - } + virtual AllowedOnSecondary secondaryAllowed() const = 0; /** * Override and return fales if the command opcounters should not be incremented on diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index 36107dce430..378e475dc44 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -212,6 +212,7 @@ env.Library( '$BUILD_DIR/mongo/db/catalog/collection', '$BUILD_DIR/mongo/db/catalog/index_key_validate', '$BUILD_DIR/mongo/db/cloner', + '$BUILD_DIR/mongo/db/command_can_run_here', '$BUILD_DIR/mongo/db/commands', '$BUILD_DIR/mongo/db/exec/stagedebug_cmd', '$BUILD_DIR/mongo/db/index/index_access_method', diff --git a/src/mongo/db/commands/apply_ops_cmd.cpp b/src/mongo/db/commands/apply_ops_cmd.cpp index f2b41250973..d0bce7a629e 100644 --- a/src/mongo/db/commands/apply_ops_cmd.cpp +++ b/src/mongo/db/commands/apply_ops_cmd.cpp @@ -202,8 +202,8 @@ class ApplyOpsCmd : public BasicCommand { public: ApplyOpsCmd() : BasicCommand("applyOps") {} - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/db/commands/authentication_commands.cpp b/src/mongo/db/commands/authentication_commands.cpp index 58e34b87f9d..0b925c3d84c 100644 --- a/src/mongo/db/commands/authentication_commands.cpp +++ b/src/mongo/db/commands/authentication_commands.cpp @@ -97,8 +97,8 @@ class CmdGetNonce : public BasicCommand { public: CmdGetNonce() : BasicCommand("getnonce"), _random(SecureRandom::create()) {} - bool slaveOk() const final { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const final { @@ -259,8 +259,8 @@ CmdAuthenticate cmdAuthenticate; class CmdLogout : public BasicCommand { public: - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, diff --git a/src/mongo/db/commands/authentication_commands.h b/src/mongo/db/commands/authentication_commands.h index a5123fb932b..5e886827256 100644 --- a/src/mongo/db/commands/authentication_commands.h +++ b/src/mongo/db/commands/authentication_commands.h @@ -40,8 +40,8 @@ class CmdAuthenticate : public BasicCommand { public: static void disableAuthMechanism(std::string authMechanism); - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { return "internal"; diff --git a/src/mongo/db/commands/clone.cpp b/src/mongo/db/commands/clone.cpp index e7ec4973221..0e50419a5df 100644 --- a/src/mongo/db/commands/clone.cpp +++ b/src/mongo/db/commands/clone.cpp @@ -56,11 +56,10 @@ class CmdClone : public BasicCommand { public: CmdClone() : BasicCommand("clone") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } diff --git a/src/mongo/db/commands/clone_collection.cpp b/src/mongo/db/commands/clone_collection.cpp index 0a8ddde8bea..493ea75d044 100644 --- a/src/mongo/db/commands/clone_collection.cpp +++ b/src/mongo/db/commands/clone_collection.cpp @@ -63,11 +63,10 @@ class CmdCloneCollection : public ErrmsgCommandDeprecated { public: CmdCloneCollection() : ErrmsgCommandDeprecated("cloneCollection") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp index 14a3bf3f00e..56dad067123 100644 --- a/src/mongo/db/commands/collection_to_capped.cpp +++ b/src/mongo/db/commands/collection_to_capped.cpp @@ -52,8 +52,8 @@ using std::stringstream; class CmdCloneCollectionAsCapped : public ErrmsgCommandDeprecated { public: CmdCloneCollectionAsCapped() : ErrmsgCommandDeprecated("cloneCollectionAsCapped") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; @@ -151,8 +151,8 @@ public: class CmdConvertToCapped : public ErrmsgCommandDeprecated { public: CmdConvertToCapped() : ErrmsgCommandDeprecated("convertToCapped") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp index e914d2f606d..4a52700118c 100644 --- a/src/mongo/db/commands/compact.cpp +++ b/src/mongo/db/commands/compact.cpp @@ -61,8 +61,8 @@ public: virtual bool adminOnly() const { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool maintenanceMode() const { return true; diff --git a/src/mongo/db/commands/conn_pool_stats.cpp b/src/mongo/db/commands/conn_pool_stats.cpp index 298bbda74d4..e799257d923 100644 --- a/src/mongo/db/commands/conn_pool_stats.cpp +++ b/src/mongo/db/commands/conn_pool_stats.cpp @@ -53,8 +53,8 @@ public: return "stats about connections between servers in a replica set or sharded cluster."; } - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/db/commands/conn_pool_sync.cpp b/src/mongo/db/commands/conn_pool_sync.cpp index 44893d621e6..ecf135bb7e6 100644 --- a/src/mongo/db/commands/conn_pool_sync.cpp +++ b/src/mongo/db/commands/conn_pool_sync.cpp @@ -62,8 +62,8 @@ public: globalConnPool.flush(); return true; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } } poolFlushCmd; diff --git a/src/mongo/db/commands/connection_status.cpp b/src/mongo/db/commands/connection_status.cpp index 14e6413014f..80b4fdd9e2c 100644 --- a/src/mongo/db/commands/connection_status.cpp +++ b/src/mongo/db/commands/connection_status.cpp @@ -41,8 +41,8 @@ using std::stringstream; class CmdConnectionStatus : public BasicCommand { public: CmdConnectionStatus() : BasicCommand("connectionStatus") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; diff --git a/src/mongo/db/commands/copydb.cpp b/src/mongo/db/commands/copydb.cpp index 297ec8f1c10..99178166050 100644 --- a/src/mongo/db/commands/copydb.cpp +++ b/src/mongo/db/commands/copydb.cpp @@ -95,8 +95,8 @@ public: return true; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/db/commands/copydb_start_commands.cpp b/src/mongo/db/commands/copydb_start_commands.cpp index 59c21a4fcd2..6f675971ea0 100644 --- a/src/mongo/db/commands/copydb_start_commands.cpp +++ b/src/mongo/db/commands/copydb_start_commands.cpp @@ -78,11 +78,10 @@ public: return true; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp index 639d842e1db..129af8c89de 100644 --- a/src/mongo/db/commands/count_cmd.cpp +++ b/src/mongo/db/commands/count_cmd.cpp @@ -63,13 +63,12 @@ public: return false; } - virtual bool slaveOk() const { - // ok on --slave setups - return repl::getGlobalReplicationCoordinator()->getSettings().isSlave(); - } - - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + if (repl::getGlobalReplicationCoordinator()->getSettings().isSlave()) { + // ok on --slave setups + return Command::AllowedOnSecondary::kAlways; + } + return Command::AllowedOnSecondary::kOptIn; } virtual bool maintenanceOk() const { diff --git a/src/mongo/db/commands/cpuload.cpp b/src/mongo/db/commands/cpuload.cpp index be297b83ed6..587ee0af693 100644 --- a/src/mongo/db/commands/cpuload.cpp +++ b/src/mongo/db/commands/cpuload.cpp @@ -42,8 +42,8 @@ using std::stringstream; class CPULoadCommand : public BasicCommand { public: CPULoadCommand() : BasicCommand("cpuload") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool isWriteCommandForConfigServer() const { return false; diff --git a/src/mongo/db/commands/cpuprofile.cpp b/src/mongo/db/commands/cpuprofile.cpp index 51cc7d8a205..396e396856d 100644 --- a/src/mongo/db/commands/cpuprofile.cpp +++ b/src/mongo/db/commands/cpuprofile.cpp @@ -71,8 +71,8 @@ namespace { class CpuProfilerCommand : public ErrmsgCommandDeprecated { public: CpuProfilerCommand(char const* name) : ErrmsgCommandDeprecated(name) {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { return true; diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 036e8dc5148..a38c935163c 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -216,9 +216,9 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } - virtual bool slaveOk() const { - return false; - } // TODO: this could be made true... + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; + } virtual Status checkAuthForCommand(Client* client, const std::string& dbname, diff --git a/src/mongo/db/commands/current_op_common.h b/src/mongo/db/commands/current_op_common.h index 517d494d851..367fb7f0ba8 100644 --- a/src/mongo/db/commands/current_op_common.h +++ b/src/mongo/db/commands/current_op_common.h @@ -51,8 +51,8 @@ public: return false; } - bool slaveOk() const final { - return true; + AllowedOnSecondary secondaryAllowed() const final { + return AllowedOnSecondary::kAlways; } bool adminOnly() const final { diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp index 15b6e6cd516..3cbc2abe362 100644 --- a/src/mongo/db/commands/dbcheck.cpp +++ b/src/mongo/db/commands/dbcheck.cpp @@ -489,8 +489,8 @@ class DbCheckCmd : public BasicCommand { public: DbCheckCmd() : BasicCommand("dbCheck") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp index b46512cd7e2..8f25ddcc13d 100644 --- a/src/mongo/db/commands/dbcommands.cpp +++ b/src/mongo/db/commands/dbcommands.cpp @@ -147,8 +147,8 @@ public: std::string help() const override { return "drop (delete) this database"; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual void addRequiredPrivileges(const std::string& dbname, @@ -210,8 +210,8 @@ public: class CmdRepairDatabase : public ErrmsgCommandDeprecated { public: - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool maintenanceMode() const { return true; @@ -295,8 +295,8 @@ public: */ class CmdProfile : public ErrmsgCommandDeprecated { public: - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { @@ -396,8 +396,8 @@ public: class CmdDrop : public ErrmsgCommandDeprecated { public: CmdDrop() : ErrmsgCommandDeprecated("drop") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { return false; @@ -452,8 +452,8 @@ public: class CmdCreate : public BasicCommand { public: CmdCreate() : BasicCommand("create") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { return false; @@ -570,8 +570,8 @@ class CmdFileMD5 : public BasicCommand { public: CmdFileMD5() : BasicCommand("filemd5") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { @@ -747,8 +747,8 @@ class CmdDatasize : public ErrmsgCommandDeprecated { public: CmdDatasize() : ErrmsgCommandDeprecated("dataSize", "datasize") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -897,8 +897,8 @@ class CollectionStats : public ErrmsgCommandDeprecated { public: CollectionStats() : ErrmsgCommandDeprecated("collStats", "collstats") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -944,8 +944,8 @@ class CollectionModCommand : public BasicCommand { public: CollectionModCommand() : BasicCommand("collMod") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; @@ -978,8 +978,8 @@ class DBStats : public ErrmsgCommandDeprecated { public: DBStats() : ErrmsgCommandDeprecated("dbStats", "dbstats") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -1074,8 +1074,8 @@ public: class CmdWhatsMyUri : public BasicCommand { public: CmdWhatsMyUri() : BasicCommand("whatsmyuri") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -1099,8 +1099,8 @@ class AvailableQueryOptions : public BasicCommand { public: AvailableQueryOptions() : BasicCommand("availableQueryOptions", "availablequeryoptions") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp index 1a006d41298..e16a3068d12 100644 --- a/src/mongo/db/commands/dbhash.cpp +++ b/src/mongo/db/commands/dbhash.cpp @@ -62,8 +62,8 @@ public: return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual void addRequiredPrivileges(const std::string& dbname, diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp index b12a485d68e..50b05986912 100644 --- a/src/mongo/db/commands/distinct.cpp +++ b/src/mongo/db/commands/distinct.cpp @@ -75,12 +75,8 @@ class DistinctCommand : public BasicCommand { public: DistinctCommand() : BasicCommand("distinct") {} - virtual bool slaveOk() const { - return false; - } - - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/db/commands/do_txn_cmd.cpp b/src/mongo/db/commands/do_txn_cmd.cpp index 3193b5ba30d..806d282aa79 100644 --- a/src/mongo/db/commands/do_txn_cmd.cpp +++ b/src/mongo/db/commands/do_txn_cmd.cpp @@ -131,8 +131,8 @@ class DoTxnCmd : public BasicCommand { public: DoTxnCmd() : BasicCommand("doTxn") {} - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/db/commands/driverHelpers.cpp b/src/mongo/db/commands/driverHelpers.cpp index 2f1e688aa15..9caef43f7b1 100644 --- a/src/mongo/db/commands/driverHelpers.cpp +++ b/src/mongo/db/commands/driverHelpers.cpp @@ -59,11 +59,9 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; - } - virtual bool slaveOverrideOk() const { - return true; + + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } }; diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index 8f311a94295..11cbed2f00c 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -66,8 +66,8 @@ using std::vector; /* "dropIndexes" is now the preferred form - "deleteIndexes" deprecated */ class CmdDropIndexes : public BasicCommand { public: - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; @@ -96,9 +96,9 @@ public: class CmdReIndex : public ErrmsgCommandDeprecated { public: - virtual bool slaveOk() const { - return true; - } // can reindex on a secondary + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; // can reindex on a secondary + } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } diff --git a/src/mongo/db/commands/end_sessions_command.cpp b/src/mongo/db/commands/end_sessions_command.cpp index 39383f8e58d..9397d39f841 100644 --- a/src/mongo/db/commands/end_sessions_command.cpp +++ b/src/mongo/db/commands/end_sessions_command.cpp @@ -44,8 +44,8 @@ class EndSessionsCommand final : public BasicCommand { public: EndSessionsCommand() : BasicCommand("endSessions") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { return false; diff --git a/src/mongo/db/commands/eval.cpp b/src/mongo/db/commands/eval.cpp index 36153a54181..0ae44555037 100644 --- a/src/mongo/db/commands/eval.cpp +++ b/src/mongo/db/commands/eval.cpp @@ -154,8 +154,8 @@ bool dbEval(OperationContext* opCtx, class CmdEval : public ErrmsgCommandDeprecated { public: - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } std::string help() const override { diff --git a/src/mongo/db/commands/explain_cmd.cpp b/src/mongo/db/commands/explain_cmd.cpp index 08463e626df..0c5ffb15a06 100644 --- a/src/mongo/db/commands/explain_cmd.cpp +++ b/src/mongo/db/commands/explain_cmd.cpp @@ -28,6 +28,7 @@ #include "mongo/platform/basic.h" +#include "mongo/db/command_can_run_here.h" #include "mongo/db/commands.h" #include "mongo/db/query/explain.h" #include "mongo/db/repl/replication_coordinator_global.h" @@ -62,12 +63,8 @@ public: /** * Running an explain on a secondary requires explicitly setting slaveOk. */ - virtual bool slaveOk() const { - return false; - } - - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } virtual bool maintenanceOk() const { @@ -149,21 +146,7 @@ public: return CommandHelpers::appendCommandStatus(result, explainStatus); } - // Check whether the child command is allowed to run here. TODO: this logic is - // copied from Command::execCommand and should be abstracted. Until then, make - // sure to keep it up to date. - repl::ReplicationCoordinator* replCoord = repl::ReplicationCoordinator::get(opCtx); - bool iAmPrimary = replCoord->canAcceptWritesForDatabase_UNSAFE(opCtx, dbname); - bool commandCanRunOnSecondary = commToExplain->slaveOk(); - - bool commandIsOverriddenToRunOnSecondary = commToExplain->slaveOverrideOk() && - ReadPreferenceSetting::get(opCtx).canRunOnSecondary(); - bool iAmStandalone = !opCtx->writesAreReplicated(); - - const bool canRunHere = iAmPrimary || commandCanRunOnSecondary || - commandIsOverriddenToRunOnSecondary || iAmStandalone; - - if (!canRunHere) { + if (!commandCanRunHere(opCtx, dbname, commToExplain)) { mongoutils::str::stream ss; ss << "Explain's child command cannot run on this node. " << "Are you explaining a write command on a secondary?"; diff --git a/src/mongo/db/commands/fail_point_cmd.cpp b/src/mongo/db/commands/fail_point_cmd.cpp index efb705a7bff..940bc33e6a4 100644 --- a/src/mongo/db/commands/fail_point_cmd.cpp +++ b/src/mongo/db/commands/fail_point_cmd.cpp @@ -68,11 +68,10 @@ class FaultInjectCmd : public ErrmsgCommandDeprecated { public: FaultInjectCmd() : ErrmsgCommandDeprecated("configureFailPoint") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index 1e8193ce4c9..d5ebaf935c5 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -220,8 +220,8 @@ public: "Output is in the \"value\" field\n"; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool supportsReadConcern(const std::string& dbName, diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp index 1ce3f931e5b..7139f52175f 100644 --- a/src/mongo/db/commands/find_cmd.cpp +++ b/src/mongo/db/commands/find_cmd.cpp @@ -69,12 +69,8 @@ public: return false; } - bool slaveOk() const override { - return false; - } - - bool slaveOverrideOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } bool maintenanceOk() const override { diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp index eb2b2d375c7..7c4a3799007 100644 --- a/src/mongo/db/commands/fsync.cpp +++ b/src/mongo/db/commands/fsync.cpp @@ -101,8 +101,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { return true; @@ -273,8 +273,8 @@ public: return false; } - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/db/commands/generic.cpp b/src/mongo/db/commands/generic.cpp index 28394239931..7164b951586 100644 --- a/src/mongo/db/commands/generic.cpp +++ b/src/mongo/db/commands/generic.cpp @@ -73,9 +73,11 @@ using std::vector; class CmdBuildInfo : public BasicCommand { public: CmdBuildInfo() : BasicCommand("buildInfo", "buildinfo") {} - virtual bool slaveOk() const { - return true; + + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } + virtual bool adminOnly() const { return false; } @@ -104,8 +106,9 @@ public: class PingCommand : public BasicCommand { public: PingCommand() : BasicCommand("ping") {} - virtual bool slaveOk() const { - return true; + + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { return "a way to check that the server is alive. responds immediately even if server is " @@ -138,8 +141,8 @@ public: std::string help() const override { return "return build level feature settings"; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -169,10 +172,10 @@ public: class HostInfoCmd : public BasicCommand { public: HostInfoCmd() : BasicCommand("hostInfo") {} - virtual bool slaveOk() const { - return true; - } + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; + } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -221,11 +224,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; - } - virtual bool adminOnly() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, @@ -255,8 +255,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { return false; @@ -283,11 +283,11 @@ public: for (const auto& c : commands) { BSONObjBuilder temp(b.subobjStart(c->getName())); temp.append("help", c->help()); - temp.append("slaveOk", c->slaveOk()); + temp.append("slaveOk", c->secondaryAllowed() == Command::AllowedOnSecondary::kAlways); temp.append("adminOnly", c->adminOnly()); // optionally indicates that the command can be forced to run on a slave/secondary - if (c->slaveOverrideOk()) - temp.append("slaveOverrideOk", c->slaveOverrideOk()); + if (c->secondaryAllowed() == Command::AllowedOnSecondary::kOptIn) + temp.append("slaveOverrideOk", true); temp.done(); } b.done(); @@ -297,12 +297,37 @@ public: } listCommandsCmd; +/* for testing purposes only */ +class CmdForceError : public BasicCommand { +public: + std::string help() const override { + return "for testing purposes only. forces a user assertion exception"; + } + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; + } + virtual bool supportsWriteConcern(const BSONObj& cmd) const override { + return false; + } + virtual void addRequiredPrivileges(const std::string& dbname, + const BSONObj& cmdObj, + std::vector<Privilege>* out) {} // No auth required + CmdForceError() : BasicCommand("forceerror") {} + bool run(OperationContext* opCtx, + const string& dbnamne, + const BSONObj& cmdObj, + BSONObjBuilder& result) { + LastError::get(cc()).setLastError(10038, "forced error"); + return false; + } +} cmdForceError; + class GetLogCmd : public ErrmsgCommandDeprecated { public: GetLogCmd() : ErrmsgCommandDeprecated("getLog") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -372,8 +397,8 @@ class ClearLogCmd : public BasicCommand { public: ClearLogCmd() : BasicCommand("clearLog") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -433,8 +458,8 @@ public: virtual bool adminOnly() const { return true; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, diff --git a/src/mongo/db/commands/geo_near_cmd.cpp b/src/mongo/db/commands/geo_near_cmd.cpp index ac1d839100b..7cf8a3b7e02 100644 --- a/src/mongo/db/commands/geo_near_cmd.cpp +++ b/src/mongo/db/commands/geo_near_cmd.cpp @@ -74,11 +74,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - bool slaveOk() const { - return true; - } - bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool supportsReadConcern(const std::string& dbName, const BSONObj& cmdObj, diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index 3d2d6d414c1..0eb1a9939a0 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -60,8 +60,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, @@ -90,8 +90,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, @@ -313,8 +313,8 @@ public: std::string help() const override { return "check for errors since last reseterror commandcal"; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool requiresAuth() const override { return false; diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp index 594a2886d08..16e5261dbde 100644 --- a/src/mongo/db/commands/getmore_cmd.cpp +++ b/src/mongo/db/commands/getmore_cmd.cpp @@ -89,8 +89,8 @@ public: return false; } - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool maintenanceOk() const override { diff --git a/src/mongo/db/commands/group_cmd.cpp b/src/mongo/db/commands/group_cmd.cpp index 85b93ec071a..62f9ee7bbb3 100644 --- a/src/mongo/db/commands/group_cmd.cpp +++ b/src/mongo/db/commands/group_cmd.cpp @@ -71,12 +71,8 @@ private: return false; } - virtual bool slaveOk() const { - return false; - } - - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } bool supportsReadConcern(const std::string& dbName, diff --git a/src/mongo/db/commands/hashcmd.cpp b/src/mongo/db/commands/hashcmd.cpp index f65fda66d84..021ccfd573a 100644 --- a/src/mongo/db/commands/hashcmd.cpp +++ b/src/mongo/db/commands/hashcmd.cpp @@ -56,8 +56,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } // No auth needed because it only works when enabled via command line. virtual void addRequiredPrivileges(const std::string& dbname, diff --git a/src/mongo/db/commands/haystack.cpp b/src/mongo/db/commands/haystack.cpp index 18f3b1d1edc..61ccbbb00bc 100644 --- a/src/mongo/db/commands/haystack.cpp +++ b/src/mongo/db/commands/haystack.cpp @@ -68,12 +68,8 @@ public: return false; } - bool slaveOk() const { - return true; - } - - bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool supportsReadConcern(const std::string& dbName, diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp index 1eaeadcd656..5bbae6c6de0 100644 --- a/src/mongo/db/commands/index_filter_commands.cpp +++ b/src/mongo/db/commands/index_filter_commands.cpp @@ -129,12 +129,8 @@ bool IndexFilterCommand::supportsWriteConcern(const BSONObj& cmd) const { return false; } -bool IndexFilterCommand::slaveOk() const { - return false; -} - -bool IndexFilterCommand::slaveOverrideOk() const { - return true; +Command::AllowedOnSecondary IndexFilterCommand::secondaryAllowed() const { + return AllowedOnSecondary::kOptIn; } std::string IndexFilterCommand::help() const { diff --git a/src/mongo/db/commands/index_filter_commands.h b/src/mongo/db/commands/index_filter_commands.h index aaa785c0d6b..72f758806c5 100644 --- a/src/mongo/db/commands/index_filter_commands.h +++ b/src/mongo/db/commands/index_filter_commands.h @@ -70,9 +70,7 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override; - virtual bool slaveOk() const; - - virtual bool slaveOverrideOk() const; + AllowedOnSecondary secondaryAllowed() const override; std::string help() const override; diff --git a/src/mongo/db/commands/isself.cpp b/src/mongo/db/commands/isself.cpp index 841dfde9e54..e3c7d077aae 100644 --- a/src/mongo/db/commands/isself.cpp +++ b/src/mongo/db/commands/isself.cpp @@ -42,8 +42,8 @@ using std::stringstream; class IsSelfCommand : public BasicCommand { public: IsSelfCommand() : BasicCommand("_isSelf") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; diff --git a/src/mongo/db/commands/kill_all_sessions_by_pattern_command.cpp b/src/mongo/db/commands/kill_all_sessions_by_pattern_command.cpp index 708cb67d34b..645c5e83c2c 100644 --- a/src/mongo/db/commands/kill_all_sessions_by_pattern_command.cpp +++ b/src/mongo/db/commands/kill_all_sessions_by_pattern_command.cpp @@ -57,8 +57,8 @@ class KillAllSessionsByPatternCommand final : public BasicCommand { public: KillAllSessionsByPatternCommand() : BasicCommand("killAllSessionsByPattern") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { return false; diff --git a/src/mongo/db/commands/kill_all_sessions_command.cpp b/src/mongo/db/commands/kill_all_sessions_command.cpp index 86f0a629249..4605a5f1964 100644 --- a/src/mongo/db/commands/kill_all_sessions_command.cpp +++ b/src/mongo/db/commands/kill_all_sessions_command.cpp @@ -57,8 +57,8 @@ class KillAllSessionsCommand final : public BasicCommand { public: KillAllSessionsCommand() : BasicCommand("killAllSessions") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { return false; diff --git a/src/mongo/db/commands/kill_op.cpp b/src/mongo/db/commands/kill_op.cpp index 7b07c87f7ba..8cc2754e919 100644 --- a/src/mongo/db/commands/kill_op.cpp +++ b/src/mongo/db/commands/kill_op.cpp @@ -55,8 +55,8 @@ public: return false; } - bool slaveOk() const final { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const final { diff --git a/src/mongo/db/commands/kill_sessions_command.cpp b/src/mongo/db/commands/kill_sessions_command.cpp index 0be33339f25..55f8dfc1a2d 100644 --- a/src/mongo/db/commands/kill_sessions_command.cpp +++ b/src/mongo/db/commands/kill_sessions_command.cpp @@ -84,8 +84,8 @@ class KillSessionsCommand final : public BasicCommand { public: KillSessionsCommand() : BasicCommand("killSessions") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { return false; diff --git a/src/mongo/db/commands/killcursors_common.h b/src/mongo/db/commands/killcursors_common.h index 6991a4a0da7..90541adc709 100644 --- a/src/mongo/db/commands/killcursors_common.h +++ b/src/mongo/db/commands/killcursors_common.h @@ -45,8 +45,8 @@ public: return false; } - bool slaveOk() const final { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool maintenanceOk() const final { diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp index b21c0f959a1..b92c59034ba 100644 --- a/src/mongo/db/commands/list_collections.cpp +++ b/src/mongo/db/commands/list_collections.cpp @@ -197,11 +197,8 @@ BSONObj buildCollectionBson(OperationContext* opCtx, class CmdListCollections : public BasicCommand { public: - virtual bool slaveOk() const { - return false; - } - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } virtual bool adminOnly() const { return false; diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp index f91cb10f680..99bc8166021 100644 --- a/src/mongo/db/commands/list_databases.cpp +++ b/src/mongo/db/commands/list_databases.cpp @@ -57,11 +57,8 @@ intmax_t dbSize(const string& database); class CmdListDatabases : public BasicCommand { public: - bool slaveOk() const final { - return false; - } - bool slaveOverrideOk() const final { - return true; + AllowedOnSecondary secondaryAllowed() const final { + return AllowedOnSecondary::kOptIn; } bool adminOnly() const final { return true; diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp index 5c23ea9f1c6..cef7130a20c 100644 --- a/src/mongo/db/commands/list_indexes.cpp +++ b/src/mongo/db/commands/list_indexes.cpp @@ -76,11 +76,8 @@ namespace { */ class CmdListIndexes : public BasicCommand { public: - virtual bool slaveOk() const { - return false; - } - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } virtual bool adminOnly() const { return false; diff --git a/src/mongo/db/commands/lock_info.cpp b/src/mongo/db/commands/lock_info.cpp index 6bd6aeb3258..3e16e220e39 100644 --- a/src/mongo/db/commands/lock_info.cpp +++ b/src/mongo/db/commands/lock_info.cpp @@ -49,12 +49,8 @@ using std::stringstream; */ class CmdLockInfo : public BasicCommand { public: - virtual bool slaveOk() const { - return true; - } - - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index ef9043fd78a..ce7d144bfcc 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -1351,13 +1351,12 @@ class MapReduceCommand : public ErrmsgCommandDeprecated { public: MapReduceCommand() : ErrmsgCommandDeprecated("mapReduce", "mapreduce") {} - virtual bool slaveOk() const { - return repl::getGlobalReplicationCoordinator()->getReplicationMode() != - repl::ReplicationCoordinator::modeReplSet; - } - - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + if (repl::getGlobalReplicationCoordinator()->getReplicationMode() != + repl::ReplicationCoordinator::modeReplSet) { + return AllowedOnSecondary::kAlways; + } + return AllowedOnSecondary::kOptIn; } std::size_t reserveBytesForReply() const override { @@ -1689,13 +1688,15 @@ public: return "internal"; } MapReduceFinishCommand() : BasicCommand("mapreduce.shardedfinish") {} - virtual bool slaveOk() const { - return repl::getGlobalReplicationCoordinator()->getReplicationMode() != - repl::ReplicationCoordinator::modeReplSet; - } - virtual bool slaveOverrideOk() const { - return true; + + AllowedOnSecondary secondaryAllowed() const override { + if (repl::getGlobalReplicationCoordinator()->getReplicationMode() != + repl::ReplicationCoordinator::modeReplSet) { + return AllowedOnSecondary::kAlways; + } + return AllowedOnSecondary::kOptIn; } + virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } diff --git a/src/mongo/db/commands/oplog_note.cpp b/src/mongo/db/commands/oplog_note.cpp index 9b26b979ba6..2f1d06b79b5 100644 --- a/src/mongo/db/commands/oplog_note.cpp +++ b/src/mongo/db/commands/oplog_note.cpp @@ -87,8 +87,8 @@ class AppendOplogNoteCmd : public BasicCommand { public: AppendOplogNoteCmd() : BasicCommand("appendOplogNote") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { diff --git a/src/mongo/db/commands/parallel_collection_scan.cpp b/src/mongo/db/commands/parallel_collection_scan.cpp index 783e74be716..c9f36a820e4 100644 --- a/src/mongo/db/commands/parallel_collection_scan.cpp +++ b/src/mongo/db/commands/parallel_collection_scan.cpp @@ -62,8 +62,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool supportsReadConcern(const std::string& dbName, diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp index 7e03b90985b..391a1ffded8 100644 --- a/src/mongo/db/commands/parameters.cpp +++ b/src/mongo/db/commands/parameters.cpp @@ -67,8 +67,8 @@ void appendParameterNames(std::string* help) { class CmdGet : public ErrmsgCommandDeprecated { public: CmdGet() : ErrmsgCommandDeprecated("getParameter") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { return true; @@ -118,8 +118,8 @@ public: class CmdSet : public ErrmsgCommandDeprecated { public: CmdSet() : ErrmsgCommandDeprecated("setParameter") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { return true; diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp index 8ec12102c35..ae607f2713f 100644 --- a/src/mongo/db/commands/pipeline_command.cpp +++ b/src/mongo/db/commands/pipeline_command.cpp @@ -57,12 +57,8 @@ public: return Pipeline::aggSupportsWriteConcern(cmd); } - bool slaveOk() const override { - return false; - } - - bool slaveOverrideOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } bool supportsReadConcern(const std::string& dbName, diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp index 0cd3593f5c1..a76100a90c7 100644 --- a/src/mongo/db/commands/plan_cache_commands.cpp +++ b/src/mongo/db/commands/plan_cache_commands.cpp @@ -124,12 +124,8 @@ bool PlanCacheCommand::supportsWriteConcern(const BSONObj& cmd) const { return false; } -bool PlanCacheCommand::slaveOk() const { - return false; -} - -bool PlanCacheCommand::slaveOverrideOk() const { - return true; +Command::AllowedOnSecondary PlanCacheCommand::secondaryAllowed() const { + return AllowedOnSecondary::kOptIn; } std::string PlanCacheCommand::help() const { diff --git a/src/mongo/db/commands/plan_cache_commands.h b/src/mongo/db/commands/plan_cache_commands.h index 0b0a680b2da..c883a189820 100644 --- a/src/mongo/db/commands/plan_cache_commands.h +++ b/src/mongo/db/commands/plan_cache_commands.h @@ -64,9 +64,7 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override; - virtual bool slaveOk() const; - - virtual bool slaveOverrideOk() const; + AllowedOnSecondary secondaryAllowed() const override; std::string help() const override; diff --git a/src/mongo/db/commands/reap_logical_session_cache_now.cpp b/src/mongo/db/commands/reap_logical_session_cache_now.cpp index 879952791fc..f04ee086359 100644 --- a/src/mongo/db/commands/reap_logical_session_cache_now.cpp +++ b/src/mongo/db/commands/reap_logical_session_cache_now.cpp @@ -44,8 +44,8 @@ class ReapLogicalSessionCacheNowCommand final : public BasicCommand { public: ReapLogicalSessionCacheNowCommand() : BasicCommand("reapLogicalSessionCacheNow") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/db/commands/refresh_logical_session_cache_now.cpp b/src/mongo/db/commands/refresh_logical_session_cache_now.cpp index 5dcbe213eaa..ff3e018eede 100644 --- a/src/mongo/db/commands/refresh_logical_session_cache_now.cpp +++ b/src/mongo/db/commands/refresh_logical_session_cache_now.cpp @@ -45,8 +45,8 @@ class RefreshLogicalSessionCacheNowCommand final : public BasicCommand { public: RefreshLogicalSessionCacheNowCommand() : BasicCommand("refreshLogicalSessionCacheNow") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/db/commands/refresh_sessions_command.cpp b/src/mongo/db/commands/refresh_sessions_command.cpp index 4db76567261..0570821ca1e 100644 --- a/src/mongo/db/commands/refresh_sessions_command.cpp +++ b/src/mongo/db/commands/refresh_sessions_command.cpp @@ -46,8 +46,8 @@ class RefreshSessionsCommand final : public BasicCommand { public: RefreshSessionsCommand() : BasicCommand("refreshSessions") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { return false; diff --git a/src/mongo/db/commands/refresh_sessions_command_internal.cpp b/src/mongo/db/commands/refresh_sessions_command_internal.cpp index 1cfbf7deeb0..fa52de2caec 100644 --- a/src/mongo/db/commands/refresh_sessions_command_internal.cpp +++ b/src/mongo/db/commands/refresh_sessions_command_internal.cpp @@ -46,8 +46,8 @@ class RefreshSessionsCommandInternal final : public BasicCommand { public: RefreshSessionsCommandInternal() : BasicCommand("refreshSessionsInternal") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { return false; diff --git a/src/mongo/db/commands/rename_collection_cmd.cpp b/src/mongo/db/commands/rename_collection_cmd.cpp index 144ecbf847e..01cba8c386a 100644 --- a/src/mongo/db/commands/rename_collection_cmd.cpp +++ b/src/mongo/db/commands/rename_collection_cmd.cpp @@ -62,8 +62,8 @@ public: virtual bool adminOnly() const { return true; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; diff --git a/src/mongo/db/commands/repair_cursor.cpp b/src/mongo/db/commands/repair_cursor.cpp index 51567abbabc..12c4cfa3528 100644 --- a/src/mongo/db/commands/repair_cursor.cpp +++ b/src/mongo/db/commands/repair_cursor.cpp @@ -52,8 +52,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual Status checkAuthForCommand(Client* client, diff --git a/src/mongo/db/commands/resize_oplog.cpp b/src/mongo/db/commands/resize_oplog.cpp index 4373c9c9dd5..ef853e9bb17 100644 --- a/src/mongo/db/commands/resize_oplog.cpp +++ b/src/mongo/db/commands/resize_oplog.cpp @@ -54,8 +54,8 @@ class CmdReplSetResizeOplog : public BasicCommand { public: CmdReplSetResizeOplog() : BasicCommand("replSetResizeOplog") {} - virtual bool slaveOk() const final { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const final { diff --git a/src/mongo/db/commands/server_status.cpp b/src/mongo/db/commands/server_status.cpp index a4b63e778f2..98aefce2f62 100644 --- a/src/mongo/db/commands/server_status.cpp +++ b/src/mongo/db/commands/server_status.cpp @@ -72,8 +72,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool allowsAfterClusterTime(const BSONObj& cmdObj) const override { return false; diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp index 31e28b6a5b5..b4f58018eaa 100644 --- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp +++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp @@ -69,8 +69,8 @@ public: SetFeatureCompatibilityVersionCommand() : BasicCommand(FeatureCompatibilityVersion::kCommandName) {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { diff --git a/src/mongo/db/commands/shutdown.h b/src/mongo/db/commands/shutdown.h index 655d25b367f..e89aa301261 100644 --- a/src/mongo/db/commands/shutdown.h +++ b/src/mongo/db/commands/shutdown.h @@ -48,8 +48,8 @@ public: virtual bool localHostOnlyIfNoAuth() { return true; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual void addRequiredPrivileges(const std::string& dbname, const BSONObj& cmdObj, diff --git a/src/mongo/db/commands/snapshot_management.cpp b/src/mongo/db/commands/snapshot_management.cpp index 3661447d224..096cdbf2582 100644 --- a/src/mongo/db/commands/snapshot_management.cpp +++ b/src/mongo/db/commands/snapshot_management.cpp @@ -44,8 +44,8 @@ class CmdMakeSnapshot final : public BasicCommand { public: CmdMakeSnapshot() : BasicCommand("makeSnapshot") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; @@ -92,8 +92,8 @@ class CmdSetCommittedSnapshot final : public BasicCommand { public: CmdSetCommittedSnapshot() : BasicCommand("setCommittedSnapshot") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; diff --git a/src/mongo/db/commands/start_session_command.cpp b/src/mongo/db/commands/start_session_command.cpp index b621ca02237..a577cc01cb7 100644 --- a/src/mongo/db/commands/start_session_command.cpp +++ b/src/mongo/db/commands/start_session_command.cpp @@ -51,8 +51,8 @@ class StartSessionCommand final : public BasicCommand { public: StartSessionCommand() : BasicCommand("startSession") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { return false; diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp index 1615117783e..c7c7c5db1a4 100644 --- a/src/mongo/db/commands/test_commands.cpp +++ b/src/mongo/db/commands/test_commands.cpp @@ -62,8 +62,8 @@ public: virtual bool adminOnly() const { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; @@ -118,8 +118,8 @@ public: return true; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { @@ -201,8 +201,8 @@ public: class CapTrunc : public BasicCommand { public: CapTrunc() : BasicCommand("captrunc") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; @@ -276,8 +276,8 @@ public: class EmptyCapped : public BasicCommand { public: EmptyCapped() : BasicCommand("emptycapped") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; diff --git a/src/mongo/db/commands/top_command.cpp b/src/mongo/db/commands/top_command.cpp index 241c44e5702..d7691005285 100644 --- a/src/mongo/db/commands/top_command.cpp +++ b/src/mongo/db/commands/top_command.cpp @@ -46,8 +46,8 @@ class TopCommand : public BasicCommand { public: TopCommand() : BasicCommand("top") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { return true; diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp index d9c2651f34d..2423c3ae6bd 100644 --- a/src/mongo/db/commands/touch.cpp +++ b/src/mongo/db/commands/touch.cpp @@ -61,8 +61,8 @@ public: virtual bool adminOnly() const { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool maintenanceMode() const { return true; diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp index 9ccf077f479..7aafdce777b 100644 --- a/src/mongo/db/commands/user_management_commands.cpp +++ b/src/mongo/db/commands/user_management_commands.cpp @@ -611,8 +611,8 @@ class CmdCreateUser : public BasicCommand { public: CmdCreateUser() : BasicCommand("createUser") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -758,8 +758,8 @@ class CmdUpdateUser : public BasicCommand { public: CmdUpdateUser() : BasicCommand("updateUser") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -892,8 +892,8 @@ class CmdDropUser : public BasicCommand { public: CmdDropUser() : BasicCommand("dropUser") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -959,8 +959,8 @@ class CmdDropAllUsersFromDatabase : public BasicCommand { public: CmdDropAllUsersFromDatabase() : BasicCommand("dropAllUsersFromDatabase") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -1015,8 +1015,8 @@ class CmdGrantRolesToUser : public BasicCommand { public: CmdGrantRolesToUser() : BasicCommand("grantRolesToUser") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -1087,8 +1087,8 @@ class CmdRevokeRolesFromUser : public BasicCommand { public: CmdRevokeRolesFromUser() : BasicCommand("revokeRolesFromUser") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -1157,12 +1157,8 @@ public: class CmdUsersInfo : public BasicCommand { public: - virtual bool slaveOk() const { - return false; - } - - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -1285,8 +1281,8 @@ class CmdCreateRole : public BasicCommand { public: CmdCreateRole() : BasicCommand("createRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -1406,8 +1402,8 @@ class CmdUpdateRole : public BasicCommand { public: CmdUpdateRole() : BasicCommand("updateRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -1523,8 +1519,8 @@ class CmdGrantPrivilegesToRole : public BasicCommand { public: CmdGrantPrivilegesToRole() : BasicCommand("grantPrivilegesToRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -1633,8 +1629,8 @@ class CmdRevokePrivilegesFromRole : public BasicCommand { public: CmdRevokePrivilegesFromRole() : BasicCommand("revokePrivilegesFromRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -1745,8 +1741,8 @@ class CmdGrantRolesToRole : public BasicCommand { public: CmdGrantRolesToRole() : BasicCommand("grantRolesToRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -1834,8 +1830,8 @@ class CmdRevokeRolesFromRole : public BasicCommand { public: CmdRevokeRolesFromRole() : BasicCommand("revokeRolesFromRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -1918,8 +1914,8 @@ class CmdDropRole : public BasicCommand { public: CmdDropRole() : BasicCommand("dropRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -2060,8 +2056,8 @@ class CmdDropAllRolesFromDatabase : public BasicCommand { public: CmdDropAllRolesFromDatabase() : BasicCommand("dropAllRolesFromDatabase") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -2191,12 +2187,8 @@ public: class CmdRolesInfo : public BasicCommand { public: - virtual bool slaveOk() const { - return false; - } - - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { @@ -2280,8 +2272,8 @@ public: class CmdInvalidateUserCache : public BasicCommand { public: - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { @@ -2317,8 +2309,8 @@ public: class CmdGetCacheGeneration : public BasicCommand { public: - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { @@ -2366,8 +2358,8 @@ class CmdMergeAuthzCollections : public BasicCommand { public: CmdMergeAuthzCollections() : BasicCommand("_mergeAuthzCollections") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp index f3d04650286..1ef643d87cf 100644 --- a/src/mongo/db/commands/validate.cpp +++ b/src/mongo/db/commands/validate.cpp @@ -67,8 +67,8 @@ class ValidateCmd : public BasicCommand { public: ValidateCmd() : BasicCommand("validate") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp index 922c5a57652..ac0a73dee89 100644 --- a/src/mongo/db/commands/write_commands/write_commands.cpp +++ b/src/mongo/db/commands/write_commands/write_commands.cpp @@ -198,8 +198,8 @@ class WriteCommand : public Command { public: explicit WriteCommand(StringData name) : Command(name) {} - bool slaveOk() const final { - return false; + AllowedOnSecondary secondaryAllowed() const final { + return AllowedOnSecondary::kNever; } bool shouldAffectCommandCounter() const final { diff --git a/src/mongo/db/exec/stagedebug_cmd.cpp b/src/mongo/db/exec/stagedebug_cmd.cpp index df3e78671df..642bdf4f5b1 100644 --- a/src/mongo/db/exec/stagedebug_cmd.cpp +++ b/src/mongo/db/exec/stagedebug_cmd.cpp @@ -123,11 +123,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - bool slaveOk() const { - return false; - } - bool slaveOverrideOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } std::string help() const override { return {}; diff --git a/src/mongo/db/ftdc/ftdc_commands.cpp b/src/mongo/db/ftdc/ftdc_commands.cpp index 3bd4a75e256..c4067f6ca44 100644 --- a/src/mongo/db/ftdc/ftdc_commands.cpp +++ b/src/mongo/db/ftdc/ftdc_commands.cpp @@ -57,8 +57,8 @@ public: return "get latest diagnostic data collection snapshot"; } - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp index c0e22a2221a..131bc3b21c9 100644 --- a/src/mongo/db/repl/master_slave.cpp +++ b/src/mongo/db/repl/master_slave.cpp @@ -368,8 +368,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { return false; diff --git a/src/mongo/db/repl/repl_set_command.h b/src/mongo/db/repl/repl_set_command.h index fd43ad1c8b2..ad97ff5e8b9 100644 --- a/src/mongo/db/repl/repl_set_command.h +++ b/src/mongo/db/repl/repl_set_command.h @@ -47,8 +47,8 @@ class ReplSetCommand : public BasicCommand { protected: ReplSetCommand(const char* s) : BasicCommand(s) {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index 69c969231ce..0911a180d36 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -216,8 +216,8 @@ public: bool requiresAuth() const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { return "Check if this server is primary for a replica pair/set; also if it is --master or " diff --git a/src/mongo/db/repl/resync.cpp b/src/mongo/db/repl/resync.cpp index ccc566d63c3..9b3fab10d2b 100644 --- a/src/mongo/db/repl/resync.cpp +++ b/src/mongo/db/repl/resync.cpp @@ -49,8 +49,8 @@ constexpr StringData kWaitFieldName = "wait"_sd; // operator requested resynchronization of replication (on a slave or secondary). {resync: 1} class CmdResync : public ErrmsgCommandDeprecated { public: - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { return true; diff --git a/src/mongo/db/s/check_sharding_index_command.cpp b/src/mongo/db/s/check_sharding_index_command.cpp index 9d3afd68c8e..04414dc9051 100644 --- a/src/mongo/db/s/check_sharding_index_command.cpp +++ b/src/mongo/db/s/check_sharding_index_command.cpp @@ -67,8 +67,8 @@ public: return false; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual void addRequiredPrivileges(const std::string& dbname, diff --git a/src/mongo/db/s/cleanup_orphaned_cmd.cpp b/src/mongo/db/s/cleanup_orphaned_cmd.cpp index afadefadbd4..9b338b0731e 100644 --- a/src/mongo/db/s/cleanup_orphaned_cmd.cpp +++ b/src/mongo/db/s/cleanup_orphaned_cmd.cpp @@ -164,8 +164,8 @@ class CleanupOrphanedCommand : public ErrmsgCommandDeprecated { public: CleanupOrphanedCommand() : ErrmsgCommandDeprecated("cleanupOrphaned") {} - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_add_shard_command.cpp b/src/mongo/db/s/config/configsvr_add_shard_command.cpp index c6354590788..834aa73ca74 100644 --- a/src/mongo/db/s/config/configsvr_add_shard_command.cpp +++ b/src/mongo/db/s/config/configsvr_add_shard_command.cpp @@ -65,8 +65,8 @@ public: "directly. Validates and adds a new shard to the cluster."; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_add_shard_to_zone_command.cpp b/src/mongo/db/s/config/configsvr_add_shard_to_zone_command.cpp index 391aa557867..00c1af987cf 100644 --- a/src/mongo/db/s/config/configsvr_add_shard_to_zone_command.cpp +++ b/src/mongo/db/s/config/configsvr_add_shard_to_zone_command.cpp @@ -65,8 +65,8 @@ public: "directly. Validates and adds a new zone to the shard."; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp b/src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp index 134032e61c4..4e9b80d82ea 100644 --- a/src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp +++ b/src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp @@ -91,8 +91,8 @@ public: return "should not be calling this directly"; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_control_balancer_command.cpp b/src/mongo/db/s/config/configsvr_control_balancer_command.cpp index 19b1fb0f263..1dc8c20f2c1 100644 --- a/src/mongo/db/s/config/configsvr_control_balancer_command.cpp +++ b/src/mongo/db/s/config/configsvr_control_balancer_command.cpp @@ -50,8 +50,8 @@ public: "directly. Controls the balancer state."; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_create_database_command.cpp b/src/mongo/db/s/config/configsvr_create_database_command.cpp index 556c6b5e0a2..797f76f5720 100644 --- a/src/mongo/db/s/config/configsvr_create_database_command.cpp +++ b/src/mongo/db/s/config/configsvr_create_database_command.cpp @@ -63,8 +63,8 @@ class ConfigSvrCreateDatabaseCommand : public BasicCommand { public: ConfigSvrCreateDatabaseCommand() : BasicCommand("_configsvrCreateDatabase") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { diff --git a/src/mongo/db/s/config/configsvr_drop_collection_command.cpp b/src/mongo/db/s/config/configsvr_drop_collection_command.cpp index 7bd0bdbd541..fd2c5ca9b93 100644 --- a/src/mongo/db/s/config/configsvr_drop_collection_command.cpp +++ b/src/mongo/db/s/config/configsvr_drop_collection_command.cpp @@ -60,8 +60,8 @@ class ConfigSvrDropCollectionCommand : public BasicCommand { public: ConfigSvrDropCollectionCommand() : BasicCommand("_configsvrDropCollection") {} - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_drop_database_command.cpp b/src/mongo/db/s/config/configsvr_drop_database_command.cpp index cef41aa0d57..8a9d35df9e8 100644 --- a/src/mongo/db/s/config/configsvr_drop_database_command.cpp +++ b/src/mongo/db/s/config/configsvr_drop_database_command.cpp @@ -54,8 +54,8 @@ class ConfigSvrDropDatabaseCommand : public BasicCommand { public: ConfigSvrDropDatabaseCommand() : BasicCommand("_configsvrDropDatabase") {} - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_enable_sharding_command.cpp b/src/mongo/db/s/config/configsvr_enable_sharding_command.cpp index 2cb4670595f..9bdbd5c5669 100644 --- a/src/mongo/db/s/config/configsvr_enable_sharding_command.cpp +++ b/src/mongo/db/s/config/configsvr_enable_sharding_command.cpp @@ -61,8 +61,8 @@ class ConfigSvrEnableShardingCommand : public BasicCommand { public: ConfigSvrEnableShardingCommand() : BasicCommand("_configsvrEnableSharding") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { diff --git a/src/mongo/db/s/config/configsvr_merge_chunk_command.cpp b/src/mongo/db/s/config/configsvr_merge_chunk_command.cpp index 3fb76ac3056..37c32c6781a 100644 --- a/src/mongo/db/s/config/configsvr_merge_chunk_command.cpp +++ b/src/mongo/db/s/config/configsvr_merge_chunk_command.cpp @@ -72,8 +72,8 @@ public: "not call directly. Receives, validates, and processes a MergeChunkRequest"; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_move_chunk_command.cpp b/src/mongo/db/s/config/configsvr_move_chunk_command.cpp index 904185e754a..f64994fcfba 100644 --- a/src/mongo/db/s/config/configsvr_move_chunk_command.cpp +++ b/src/mongo/db/s/config/configsvr_move_chunk_command.cpp @@ -56,8 +56,8 @@ public: "directly. Requests the balancer to move or rebalance a single chunk."; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_move_primary_command.cpp b/src/mongo/db/s/config/configsvr_move_primary_command.cpp index 7f5b3a4169d..3ff60940242 100644 --- a/src/mongo/db/s/config/configsvr_move_primary_command.cpp +++ b/src/mongo/db/s/config/configsvr_move_primary_command.cpp @@ -68,8 +68,8 @@ class ConfigSvrMovePrimaryCommand : public BasicCommand { public: ConfigSvrMovePrimaryCommand() : BasicCommand("_configsvrMovePrimary") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { diff --git a/src/mongo/db/s/config/configsvr_remove_shard_command.cpp b/src/mongo/db/s/config/configsvr_remove_shard_command.cpp index e8d089c9370..d55e81b4ba9 100644 --- a/src/mongo/db/s/config/configsvr_remove_shard_command.cpp +++ b/src/mongo/db/s/config/configsvr_remove_shard_command.cpp @@ -62,8 +62,8 @@ public: "directly. Removes a shard from the cluster."; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_remove_shard_from_zone_command.cpp b/src/mongo/db/s/config/configsvr_remove_shard_from_zone_command.cpp index 7656550edff..9aa7f9285e2 100644 --- a/src/mongo/db/s/config/configsvr_remove_shard_from_zone_command.cpp +++ b/src/mongo/db/s/config/configsvr_remove_shard_from_zone_command.cpp @@ -65,8 +65,8 @@ public: "directly. Validates and removes the shard from the zone."; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp index b602fed5350..63b6f00a48d 100644 --- a/src/mongo/db/s/config/configsvr_shard_collection_command.cpp +++ b/src/mongo/db/s/config/configsvr_shard_collection_command.cpp @@ -706,8 +706,8 @@ public: return Status::OK(); } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_split_chunk_command.cpp b/src/mongo/db/s/config/configsvr_split_chunk_command.cpp index b3f536871e5..4d66c7ffa8b 100644 --- a/src/mongo/db/s/config/configsvr_split_chunk_command.cpp +++ b/src/mongo/db/s/config/configsvr_split_chunk_command.cpp @@ -70,8 +70,8 @@ public: "not call directly. Receives, validates, and processes a SplitChunkRequest."; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/config/configsvr_update_zone_key_range_command.cpp b/src/mongo/db/s/config/configsvr_update_zone_key_range_command.cpp index ed83028907d..1742699b038 100644 --- a/src/mongo/db/s/config/configsvr_update_zone_key_range_command.cpp +++ b/src/mongo/db/s/config/configsvr_update_zone_key_range_command.cpp @@ -67,8 +67,8 @@ public: "directly. Validates and assigns a new range to a zone."; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp index 8c4732c1dea..36ea067ab63 100644 --- a/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp +++ b/src/mongo/db/s/flush_routing_table_cache_updates_command.cpp @@ -70,8 +70,8 @@ public: return true; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/db/s/get_shard_version_command.cpp b/src/mongo/db/s/get_shard_version_command.cpp index 4ce02d070a6..2e580a669f8 100644 --- a/src/mongo/db/s/get_shard_version_command.cpp +++ b/src/mongo/db/s/get_shard_version_command.cpp @@ -58,8 +58,8 @@ public: return false; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/merge_chunks_command.cpp b/src/mongo/db/s/merge_chunks_command.cpp index 5b7e68fda56..d7a355e5f95 100644 --- a/src/mongo/db/s/merge_chunks_command.cpp +++ b/src/mongo/db/s/merge_chunks_command.cpp @@ -333,8 +333,8 @@ public: return true; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy_commands.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy_commands.cpp index 785a3309d22..a6f9b86e501 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy_commands.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy_commands.cpp @@ -125,8 +125,8 @@ public: return false; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { @@ -187,8 +187,8 @@ public: return false; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { @@ -236,8 +236,8 @@ public: return false; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { diff --git a/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp b/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp index d4b235f251f..36122f38c4f 100644 --- a/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp +++ b/src/mongo/db/s/migration_destination_manager_legacy_commands.cpp @@ -63,8 +63,8 @@ public: return "internal"; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { @@ -163,8 +163,8 @@ public: return "internal"; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { @@ -201,8 +201,8 @@ public: return "internal"; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { @@ -247,8 +247,8 @@ public: return "internal"; } - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { diff --git a/src/mongo/db/s/move_chunk_command.cpp b/src/mongo/db/s/move_chunk_command.cpp index 5233290efc2..e1cb32cf925 100644 --- a/src/mongo/db/s/move_chunk_command.cpp +++ b/src/mongo/db/s/move_chunk_command.cpp @@ -80,8 +80,8 @@ public: return "should not be calling this directly"; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp index 7ddd6d2f6a1..1e4f734b16c 100644 --- a/src/mongo/db/s/set_shard_version_command.cpp +++ b/src/mongo/db/s/set_shard_version_command.cpp @@ -70,8 +70,8 @@ public: return true; } - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/db/s/sharding_state_command.cpp b/src/mongo/db/s/sharding_state_command.cpp index 0e3aea8b652..6fc0887021a 100644 --- a/src/mongo/db/s/sharding_state_command.cpp +++ b/src/mongo/db/s/sharding_state_command.cpp @@ -48,8 +48,8 @@ public: return false; } - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/db/s/split_chunk_command.cpp b/src/mongo/db/s/split_chunk_command.cpp index 8de8e6dc966..3c61c3b1498 100644 --- a/src/mongo/db/s/split_chunk_command.cpp +++ b/src/mongo/db/s/split_chunk_command.cpp @@ -68,8 +68,8 @@ public: return false; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/db/s/split_vector_command.cpp b/src/mongo/db/s/split_vector_command.cpp index 4ac78111bf7..2ee8ad88d7c 100644 --- a/src/mongo/db/s/split_vector_command.cpp +++ b/src/mongo/db/s/split_vector_command.cpp @@ -49,8 +49,8 @@ public: return false; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } std::string help() const override { diff --git a/src/mongo/db/s/unset_sharding_command.cpp b/src/mongo/db/s/unset_sharding_command.cpp index 5aae6e00a94..a6e6e61d970 100644 --- a/src/mongo/db/s/unset_sharding_command.cpp +++ b/src/mongo/db/s/unset_sharding_command.cpp @@ -60,8 +60,8 @@ public: return true; } - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } void addRequiredPrivileges(const std::string& dbname, diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp index 1d6d69d257b..2b27ec8b22c 100644 --- a/src/mongo/db/service_entry_point_mongod.cpp +++ b/src/mongo/db/service_entry_point_mongod.cpp @@ -37,6 +37,7 @@ #include "mongo/db/auth/authorization_session.h" #include "mongo/db/auth/impersonation_session.h" #include "mongo/db/client.h" +#include "mongo/db/command_can_run_here.h" #include "mongo/db/commands.h" #include "mongo/db/commands/fsync.h" #include "mongo/db/concurrency/global_lock_acquisition_tracker.h" @@ -609,18 +610,13 @@ void execCommandDatabase(OperationContext* opCtx, if (!opCtx->getClient()->isInDirectClient() && !MONGO_FAIL_POINT(skipCheckingForNotMasterInCommandDispatch)) { - - bool commandCanRunOnSecondary = command->slaveOk(); - - bool commandIsOverriddenToRunOnSecondary = - command->slaveOverrideOk() && ReadPreferenceSetting::get(opCtx).canRunOnSecondary(); - - bool iAmStandalone = !opCtx->writesAreReplicated(); - bool canRunHere = iAmPrimary || commandCanRunOnSecondary || - commandIsOverriddenToRunOnSecondary || iAmStandalone; - - // This logic is clearer if we don't have to invert it. - if (!canRunHere && command->slaveOverrideOk()) { + auto allowed = command->secondaryAllowed(); + bool alwaysAllowed = allowed == Command::AllowedOnSecondary::kAlways; + bool couldHaveOptedIn = allowed == Command::AllowedOnSecondary::kOptIn; + bool optedIn = + couldHaveOptedIn && ReadPreferenceSetting::get(opCtx).canRunOnSecondary(); + bool canRunHere = commandCanRunHere(opCtx, dbname, command); + if (!canRunHere && couldHaveOptedIn) { uasserted(ErrorCodes::NotMasterNoSlaveOk, "not master and slaveOk=false"); } @@ -644,7 +640,7 @@ void execCommandDatabase(OperationContext* opCtx, // Check ticket SERVER-21432, slaveOk commands are allowed in drain mode uassert(ErrorCodes::NotMasterOrSecondary, "node is in drain mode", - commandIsOverriddenToRunOnSecondary || commandCanRunOnSecondary); + optedIn || alwaysAllowed); } } diff --git a/src/mongo/db/storage/mmap_v1/journal_latency_test_cmd.cpp b/src/mongo/db/storage/mmap_v1/journal_latency_test_cmd.cpp index 4f90ba1c6d0..b8707efd3d1 100644 --- a/src/mongo/db/storage/mmap_v1/journal_latency_test_cmd.cpp +++ b/src/mongo/db/storage/mmap_v1/journal_latency_test_cmd.cpp @@ -68,8 +68,8 @@ class JournalLatencyTestCmd : public BasicCommand { public: JournalLatencyTestCmd() : BasicCommand("journalLatencyTest") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; diff --git a/src/mongo/s/client/shard_connection.cpp b/src/mongo/s/client/shard_connection.cpp index d79611871e4..fcb033b1025 100644 --- a/src/mongo/s/client/shard_connection.cpp +++ b/src/mongo/s/client/shard_connection.cpp @@ -98,8 +98,8 @@ public: virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } // Same privs as connPoolStats diff --git a/src/mongo/s/commands/cluster_add_shard_cmd.cpp b/src/mongo/s/commands/cluster_add_shard_cmd.cpp index 56cdf9650ab..df13a652f37 100644 --- a/src/mongo/s/commands/cluster_add_shard_cmd.cpp +++ b/src/mongo/s/commands/cluster_add_shard_cmd.cpp @@ -56,8 +56,8 @@ class AddShardCmd : public BasicCommand { public: AddShardCmd() : BasicCommand("addShard", "addshard") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_add_shard_to_zone_cmd.cpp b/src/mongo/s/commands/cluster_add_shard_to_zone_cmd.cpp index e82e6bc0817..419ca7e2a0e 100644 --- a/src/mongo/s/commands/cluster_add_shard_to_zone_cmd.cpp +++ b/src/mongo/s/commands/cluster_add_shard_to_zone_cmd.cpp @@ -69,8 +69,8 @@ class AddShardToZoneCmd : public BasicCommand { public: AddShardToZoneCmd() : BasicCommand("addShardToZone", "addshardtozone") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_available_query_options_cmd.cpp b/src/mongo/s/commands/cluster_available_query_options_cmd.cpp index d209c2ace34..8eccb031358 100644 --- a/src/mongo/s/commands/cluster_available_query_options_cmd.cpp +++ b/src/mongo/s/commands/cluster_available_query_options_cmd.cpp @@ -39,8 +39,8 @@ class AvailableQueryOptions : public BasicCommand { public: AvailableQueryOptions() : BasicCommand("availableQueryOptions", "availablequeryoptions") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/s/commands/cluster_compact_cmd.cpp b/src/mongo/s/commands/cluster_compact_cmd.cpp index 3d933804c49..d5fd03ae39a 100644 --- a/src/mongo/s/commands/cluster_compact_cmd.cpp +++ b/src/mongo/s/commands/cluster_compact_cmd.cpp @@ -37,8 +37,8 @@ class CompactCmd : public BasicCommand { public: CompactCmd() : BasicCommand("compact") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_control_balancer_cmd.cpp b/src/mongo/s/commands/cluster_control_balancer_cmd.cpp index 11e05a559d0..5a60b6bb8d8 100644 --- a/src/mongo/s/commands/cluster_control_balancer_cmd.cpp +++ b/src/mongo/s/commands/cluster_control_balancer_cmd.cpp @@ -50,8 +50,8 @@ public: _configsvrCommandName(configsvrCommandName), _authorizationAction(authorizationAction) {} - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_count_cmd.cpp b/src/mongo/s/commands/cluster_count_cmd.cpp index f05f349982c..2c407b61005 100644 --- a/src/mongo/s/commands/cluster_count_cmd.cpp +++ b/src/mongo/s/commands/cluster_count_cmd.cpp @@ -51,8 +51,8 @@ class ClusterCountCmd : public ErrmsgCommandDeprecated { public: ClusterCountCmd() : ErrmsgCommandDeprecated("count") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_db_stats_cmd.cpp b/src/mongo/s/commands/cluster_db_stats_cmd.cpp index 1d74af4d1e7..35a24f7d81d 100644 --- a/src/mongo/s/commands/cluster_db_stats_cmd.cpp +++ b/src/mongo/s/commands/cluster_db_stats_cmd.cpp @@ -44,8 +44,8 @@ class DBStatsCmd : public ErrmsgCommandDeprecated { public: DBStatsCmd() : ErrmsgCommandDeprecated("dbStats", "dbstats") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { return false; diff --git a/src/mongo/s/commands/cluster_drop_cmd.cpp b/src/mongo/s/commands/cluster_drop_cmd.cpp index 6a8081c20c2..a77abe079a6 100644 --- a/src/mongo/s/commands/cluster_drop_cmd.cpp +++ b/src/mongo/s/commands/cluster_drop_cmd.cpp @@ -45,8 +45,8 @@ class DropCmd : public BasicCommand { public: DropCmd() : BasicCommand("drop") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_drop_database_cmd.cpp b/src/mongo/s/commands/cluster_drop_database_cmd.cpp index da0380565eb..207db3d3c0d 100644 --- a/src/mongo/s/commands/cluster_drop_database_cmd.cpp +++ b/src/mongo/s/commands/cluster_drop_database_cmd.cpp @@ -46,8 +46,8 @@ class DropDatabaseCmd : public BasicCommand { public: DropDatabaseCmd() : BasicCommand("dropDatabase") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp b/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp index 77bdbbb6681..1869632ef68 100644 --- a/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp +++ b/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp @@ -52,8 +52,8 @@ class EnableShardingCmd : public ErrmsgCommandDeprecated { public: EnableShardingCmd() : ErrmsgCommandDeprecated("enableSharding", "enablesharding") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_explain_cmd.cpp b/src/mongo/s/commands/cluster_explain_cmd.cpp index b734501ab36..3f435329d75 100644 --- a/src/mongo/s/commands/cluster_explain_cmd.cpp +++ b/src/mongo/s/commands/cluster_explain_cmd.cpp @@ -61,12 +61,8 @@ public: /** * Running an explain on a secondary requires explicitly setting slaveOk. */ - virtual bool slaveOk() const { - return false; - } - - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } virtual bool maintenanceOk() const { diff --git a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp index 90b5665e6a0..922d271e870 100644 --- a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp @@ -78,8 +78,8 @@ class FindAndModifyCmd : public BasicCommand { public: FindAndModifyCmd() : BasicCommand("findAndModify", "findandmodify") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_find_cmd.cpp b/src/mongo/s/commands/cluster_find_cmd.cpp index 9c8adb1a64b..8b53c5b6f6b 100644 --- a/src/mongo/s/commands/cluster_find_cmd.cpp +++ b/src/mongo/s/commands/cluster_find_cmd.cpp @@ -65,12 +65,8 @@ public: return false; } - bool slaveOk() const final { - return false; - } - - bool slaveOverrideOk() const final { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } bool maintenanceOk() const final { diff --git a/src/mongo/s/commands/cluster_flush_router_config_cmd.cpp b/src/mongo/s/commands/cluster_flush_router_config_cmd.cpp index 61f0f9d640a..2b76f374342 100644 --- a/src/mongo/s/commands/cluster_flush_router_config_cmd.cpp +++ b/src/mongo/s/commands/cluster_flush_router_config_cmd.cpp @@ -39,8 +39,8 @@ class FlushRouterConfigCmd : public BasicCommand { public: FlushRouterConfigCmd() : BasicCommand("flushRouterConfig", "flushrouterconfig") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_fsync_cmd.cpp b/src/mongo/s/commands/cluster_fsync_cmd.cpp index fa6363ed9fb..3f578bc9ddb 100644 --- a/src/mongo/s/commands/cluster_fsync_cmd.cpp +++ b/src/mongo/s/commands/cluster_fsync_cmd.cpp @@ -42,8 +42,8 @@ class FsyncCommand : public ErrmsgCommandDeprecated { public: FsyncCommand() : ErrmsgCommandDeprecated("fsync") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_ftdc_commands.cpp b/src/mongo/s/commands/cluster_ftdc_commands.cpp index c6c30cebf95..6942bec0bdb 100644 --- a/src/mongo/s/commands/cluster_ftdc_commands.cpp +++ b/src/mongo/s/commands/cluster_ftdc_commands.cpp @@ -56,8 +56,8 @@ public: return "get latest diagnostic data collection snapshot"; } - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp index 9665072154d..3134fbb22c3 100644 --- a/src/mongo/s/commands/cluster_get_last_error_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_last_error_cmd.cpp @@ -195,8 +195,8 @@ public: return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { diff --git a/src/mongo/s/commands/cluster_get_prev_error_cmd.cpp b/src/mongo/s/commands/cluster_get_prev_error_cmd.cpp index 399eccc6684..d36e91916b8 100644 --- a/src/mongo/s/commands/cluster_get_prev_error_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_prev_error_cmd.cpp @@ -47,8 +47,8 @@ public: return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { diff --git a/src/mongo/s/commands/cluster_get_shard_map_cmd.cpp b/src/mongo/s/commands/cluster_get_shard_map_cmd.cpp index 3b70cf27d94..6672c597a39 100644 --- a/src/mongo/s/commands/cluster_get_shard_map_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_shard_map_cmd.cpp @@ -47,8 +47,8 @@ public: return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { diff --git a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp index c55c77ef3f8..05f04d9249a 100644 --- a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp @@ -47,8 +47,8 @@ class GetShardVersion : public BasicCommand { public: GetShardVersion() : BasicCommand("getShardVersion", "getshardversion") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_getmore_cmd.cpp b/src/mongo/s/commands/cluster_getmore_cmd.cpp index 00784d5c55c..4274efb7089 100644 --- a/src/mongo/s/commands/cluster_getmore_cmd.cpp +++ b/src/mongo/s/commands/cluster_getmore_cmd.cpp @@ -55,8 +55,8 @@ public: return false; } - bool slaveOk() const final { - return true; + AllowedOnSecondary secondaryAllowed() const final { + return AllowedOnSecondary::kAlways; } bool maintenanceOk() const final { diff --git a/src/mongo/s/commands/cluster_index_filter_cmd.cpp b/src/mongo/s/commands/cluster_index_filter_cmd.cpp index c06c42f2ce0..ba61748779f 100644 --- a/src/mongo/s/commands/cluster_index_filter_cmd.cpp +++ b/src/mongo/s/commands/cluster_index_filter_cmd.cpp @@ -61,15 +61,10 @@ public: virtual ~ClusterIndexFilterCmd() {} - bool slaveOk() const { - return false; - } - - bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } diff --git a/src/mongo/s/commands/cluster_is_db_grid_cmd.cpp b/src/mongo/s/commands/cluster_is_db_grid_cmd.cpp index 3304202e4a7..297e4403c2f 100644 --- a/src/mongo/s/commands/cluster_is_db_grid_cmd.cpp +++ b/src/mongo/s/commands/cluster_is_db_grid_cmd.cpp @@ -43,8 +43,8 @@ public: return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual void addRequiredPrivileges(const std::string& dbname, diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp index 8caf0cde2c4..220d97e9e36 100644 --- a/src/mongo/s/commands/cluster_is_master_cmd.cpp +++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp @@ -53,8 +53,8 @@ public: return false; } - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } std::string help() const override { diff --git a/src/mongo/s/commands/cluster_kill_op.cpp b/src/mongo/s/commands/cluster_kill_op.cpp index bfeb02ea493..3418d4049be 100644 --- a/src/mongo/s/commands/cluster_kill_op.cpp +++ b/src/mongo/s/commands/cluster_kill_op.cpp @@ -60,8 +60,8 @@ public: return false; } - bool slaveOk() const final { - return true; + AllowedOnSecondary secondaryAllowed() const final { + return AllowedOnSecondary::kAlways; } bool adminOnly() const final { diff --git a/src/mongo/s/commands/cluster_list_databases_cmd.cpp b/src/mongo/s/commands/cluster_list_databases_cmd.cpp index 5a6d8a16552..064b89d3ca4 100644 --- a/src/mongo/s/commands/cluster_list_databases_cmd.cpp +++ b/src/mongo/s/commands/cluster_list_databases_cmd.cpp @@ -56,12 +56,8 @@ class ListDatabasesCmd : public BasicCommand { public: ListDatabasesCmd() : BasicCommand("listDatabases", "listdatabases") {} - bool slaveOk() const final { - return true; - } - - bool slaveOverrideOk() const final { - return true; + AllowedOnSecondary secondaryAllowed() const final { + return AllowedOnSecondary::kAlways; } bool adminOnly() const final { diff --git a/src/mongo/s/commands/cluster_list_shards_cmd.cpp b/src/mongo/s/commands/cluster_list_shards_cmd.cpp index 309c45a3be2..59ceb90f106 100644 --- a/src/mongo/s/commands/cluster_list_shards_cmd.cpp +++ b/src/mongo/s/commands/cluster_list_shards_cmd.cpp @@ -50,8 +50,8 @@ public: return true; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp index 8787beefc09..5e58c1c0e68 100644 --- a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp +++ b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp @@ -151,8 +151,8 @@ class MRCmd : public ErrmsgCommandDeprecated { public: MRCmd() : ErrmsgCommandDeprecated("mapReduce", "mapreduce") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp index abfe8fe2f08..ecdfa931cd4 100644 --- a/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp +++ b/src/mongo/s/commands/cluster_merge_chunks_cmd.cpp @@ -80,8 +80,8 @@ public: return true; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp index d1a3ef74e84..e251376c920 100644 --- a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp +++ b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp @@ -55,10 +55,9 @@ class MoveChunkCmd : public ErrmsgCommandDeprecated { public: MoveChunkCmd() : ErrmsgCommandDeprecated("moveChunk", "movechunk") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } - bool adminOnly() const override { return true; } diff --git a/src/mongo/s/commands/cluster_move_primary_cmd.cpp b/src/mongo/s/commands/cluster_move_primary_cmd.cpp index 181c3a3b8fd..34540a60b69 100644 --- a/src/mongo/s/commands/cluster_move_primary_cmd.cpp +++ b/src/mongo/s/commands/cluster_move_primary_cmd.cpp @@ -57,8 +57,8 @@ class MoveDatabasePrimaryCommand : public BasicCommand { public: MoveDatabasePrimaryCommand() : BasicCommand("movePrimary", "moveprimary") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_multicast.cpp b/src/mongo/s/commands/cluster_multicast.cpp index d0d8d11c607..b26bdbe4e88 100644 --- a/src/mongo/s/commands/cluster_multicast.cpp +++ b/src/mongo/s/commands/cluster_multicast.cpp @@ -66,10 +66,9 @@ class MulticastCmd : public BasicCommand { public: MulticastCmd() : BasicCommand("multicast") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } - bool adminOnly() const override { return true; } diff --git a/src/mongo/s/commands/cluster_netstat_cmd.cpp b/src/mongo/s/commands/cluster_netstat_cmd.cpp index b8ffa72b530..5dd1e0b1a1a 100644 --- a/src/mongo/s/commands/cluster_netstat_cmd.cpp +++ b/src/mongo/s/commands/cluster_netstat_cmd.cpp @@ -40,8 +40,8 @@ class NetStatCmd : public BasicCommand { public: NetStatCmd() : BasicCommand("netstat") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_pipeline_cmd.cpp b/src/mongo/s/commands/cluster_pipeline_cmd.cpp index f9d972d4771..5983c0aa9c6 100644 --- a/src/mongo/s/commands/cluster_pipeline_cmd.cpp +++ b/src/mongo/s/commands/cluster_pipeline_cmd.cpp @@ -47,8 +47,8 @@ public: "http://dochub.mongodb.org/core/aggregation for more details."; } - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_plan_cache_cmd.cpp b/src/mongo/s/commands/cluster_plan_cache_cmd.cpp index 2e1b63653cd..8fa4c1edfc2 100644 --- a/src/mongo/s/commands/cluster_plan_cache_cmd.cpp +++ b/src/mongo/s/commands/cluster_plan_cache_cmd.cpp @@ -54,12 +54,8 @@ class ClusterPlanCacheCmd : public BasicCommand { public: virtual ~ClusterPlanCacheCmd() {} - bool slaveOk() const { - return false; - } - - bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } bool supportsWriteConcern(const BSONObj& cmd) const override { diff --git a/src/mongo/s/commands/cluster_profile_cmd.cpp b/src/mongo/s/commands/cluster_profile_cmd.cpp index cab007638d9..5129922d3a5 100644 --- a/src/mongo/s/commands/cluster_profile_cmd.cpp +++ b/src/mongo/s/commands/cluster_profile_cmd.cpp @@ -37,8 +37,8 @@ class ProfileCmd : public ErrmsgCommandDeprecated { public: ProfileCmd() : ErrmsgCommandDeprecated("profile") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_remove_shard_cmd.cpp b/src/mongo/s/commands/cluster_remove_shard_cmd.cpp index 51d863cc668..336f51d0437 100644 --- a/src/mongo/s/commands/cluster_remove_shard_cmd.cpp +++ b/src/mongo/s/commands/cluster_remove_shard_cmd.cpp @@ -49,8 +49,8 @@ public: return "remove a shard from the system."; } - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_remove_shard_from_zone_cmd.cpp b/src/mongo/s/commands/cluster_remove_shard_from_zone_cmd.cpp index 0118f75ee14..bc35d3c573c 100644 --- a/src/mongo/s/commands/cluster_remove_shard_from_zone_cmd.cpp +++ b/src/mongo/s/commands/cluster_remove_shard_from_zone_cmd.cpp @@ -69,8 +69,8 @@ class RemoveShardFromZoneCmd : public BasicCommand { public: RemoveShardFromZoneCmd() : BasicCommand("removeShardFromZone", "removeshardfromzone") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_repl_set_get_status_cmd.cpp b/src/mongo/s/commands/cluster_repl_set_get_status_cmd.cpp index 913d7248d11..0c70fdac88c 100644 --- a/src/mongo/s/commands/cluster_repl_set_get_status_cmd.cpp +++ b/src/mongo/s/commands/cluster_repl_set_get_status_cmd.cpp @@ -40,8 +40,8 @@ class CmdReplSetGetStatus : public ErrmsgCommandDeprecated { public: CmdReplSetGetStatus() : ErrmsgCommandDeprecated("replSetGetStatus") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_reset_error_cmd.cpp b/src/mongo/s/commands/cluster_reset_error_cmd.cpp index 50ba801ba37..6df637aaf76 100644 --- a/src/mongo/s/commands/cluster_reset_error_cmd.cpp +++ b/src/mongo/s/commands/cluster_reset_error_cmd.cpp @@ -49,8 +49,8 @@ public: return false; } - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual void addRequiredPrivileges(const std::string& dbname, diff --git a/src/mongo/s/commands/cluster_set_feature_compatibility_version_cmd.cpp b/src/mongo/s/commands/cluster_set_feature_compatibility_version_cmd.cpp index 04502b0e214..2e519bc73f9 100644 --- a/src/mongo/s/commands/cluster_set_feature_compatibility_version_cmd.cpp +++ b/src/mongo/s/commands/cluster_set_feature_compatibility_version_cmd.cpp @@ -55,8 +55,8 @@ class SetFeatureCompatibilityVersionCmd : public BasicCommand { public: SetFeatureCompatibilityVersionCmd() : BasicCommand("setFeatureCompatibilityVersion") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp index 31d230f117f..f9fc5442099 100644 --- a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp +++ b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp @@ -70,8 +70,8 @@ class ShardCollectionCmd : public BasicCommand { public: ShardCollectionCmd() : BasicCommand("shardCollection", "shardcollection") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_split_cmd.cpp b/src/mongo/s/commands/cluster_split_cmd.cpp index 1b709cf9f95..ec5fbe58d37 100644 --- a/src/mongo/s/commands/cluster_split_cmd.cpp +++ b/src/mongo/s/commands/cluster_split_cmd.cpp @@ -88,8 +88,8 @@ class SplitCollectionCmd : public ErrmsgCommandDeprecated { public: SplitCollectionCmd() : ErrmsgCommandDeprecated("split") {} - bool slaveOk() const override { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } bool adminOnly() const override { diff --git a/src/mongo/s/commands/cluster_update_zone_key_range_cmd.cpp b/src/mongo/s/commands/cluster_update_zone_key_range_cmd.cpp index 0abb42b3a22..f286abc6a6b 100644 --- a/src/mongo/s/commands/cluster_update_zone_key_range_cmd.cpp +++ b/src/mongo/s/commands/cluster_update_zone_key_range_cmd.cpp @@ -72,8 +72,8 @@ class UpdateZoneKeyRangeCmd : public BasicCommand { public: UpdateZoneKeyRangeCmd() : BasicCommand("updateZoneKeyRange", "updatezonekeyRange") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { diff --git a/src/mongo/s/commands/cluster_user_management_commands.cpp b/src/mongo/s/commands/cluster_user_management_commands.cpp index a9d6230b8cc..f908b1e98e1 100644 --- a/src/mongo/s/commands/cluster_user_management_commands.cpp +++ b/src/mongo/s/commands/cluster_user_management_commands.cpp @@ -67,11 +67,10 @@ class CmdCreateUser : public BasicCommand { public: CmdCreateUser() : BasicCommand("createUser") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } @@ -108,11 +107,10 @@ class CmdUpdateUser : public BasicCommand { public: CmdUpdateUser() : BasicCommand("updateUser") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } @@ -160,8 +158,8 @@ class CmdDropUser : public BasicCommand { public: CmdDropUser() : BasicCommand("dropUser") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } @@ -208,11 +206,10 @@ class CmdDropAllUsersFromDatabase : public BasicCommand { public: CmdDropAllUsersFromDatabase() : BasicCommand("dropAllUsersFromDatabase") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } @@ -251,8 +248,8 @@ class CmdGrantRolesToUser : public BasicCommand { public: CmdGrantRolesToUser() : BasicCommand("grantRolesToUser") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } @@ -301,8 +298,8 @@ class CmdRevokeRolesFromUser : public BasicCommand { public: CmdRevokeRolesFromUser() : BasicCommand("revokeRolesFromUser") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } @@ -349,15 +346,10 @@ public: class CmdUsersInfo : public BasicCommand { public: - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } - virtual bool slaveOverrideOk() const { - return true; - } - - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } @@ -388,11 +380,10 @@ class CmdCreateRole : public BasicCommand { public: CmdCreateRole() : BasicCommand("createRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } @@ -425,11 +416,10 @@ class CmdUpdateRole : public BasicCommand { public: CmdUpdateRole() : BasicCommand("updateRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } @@ -468,8 +458,8 @@ class CmdGrantPrivilegesToRole : public BasicCommand { public: CmdGrantPrivilegesToRole() : BasicCommand("grantPrivilegesToRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } @@ -511,11 +501,10 @@ class CmdRevokePrivilegesFromRole : public BasicCommand { public: CmdRevokePrivilegesFromRole() : BasicCommand("revokePrivilegesFromRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } @@ -554,11 +543,10 @@ class CmdGrantRolesToRole : public BasicCommand { public: CmdGrantRolesToRole() : BasicCommand("grantRolesToRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } @@ -597,11 +585,10 @@ class CmdRevokeRolesFromRole : public BasicCommand { public: CmdRevokeRolesFromRole() : BasicCommand("revokeRolesFromRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } @@ -640,11 +627,10 @@ class CmdDropRole : public BasicCommand { public: CmdDropRole() : BasicCommand("dropRole") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } @@ -686,8 +672,8 @@ class CmdDropAllRolesFromDatabase : public BasicCommand { public: CmdDropAllRolesFromDatabase() : BasicCommand("dropAllRolesFromDatabase") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } @@ -733,15 +719,10 @@ class CmdRolesInfo : public BasicCommand { public: CmdRolesInfo() : BasicCommand("rolesInfo") {} - virtual bool slaveOk() const { - return false; - } - - virtual bool slaveOverrideOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kOptIn; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } @@ -770,8 +751,8 @@ class CmdInvalidateUserCache : public BasicCommand { public: CmdInvalidateUserCache() : BasicCommand("invalidateUserCache") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { @@ -819,11 +800,10 @@ class CmdMergeAuthzCollections : public BasicCommand { public: CmdMergeAuthzCollections() : BasicCommand("_mergeAuthzCollections") {} - virtual bool slaveOk() const { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { return true; } diff --git a/src/mongo/s/commands/cluster_whats_my_uri_cmd.cpp b/src/mongo/s/commands/cluster_whats_my_uri_cmd.cpp index a44d6fbb8c1..7cd621302ba 100644 --- a/src/mongo/s/commands/cluster_whats_my_uri_cmd.cpp +++ b/src/mongo/s/commands/cluster_whats_my_uri_cmd.cpp @@ -38,8 +38,8 @@ class WhatsMyUriCmd : public BasicCommand { public: WhatsMyUriCmd() : BasicCommand("whatsmyuri") {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp index bf1949d73c8..779b3993c99 100644 --- a/src/mongo/s/commands/cluster_write_cmd.cpp +++ b/src/mongo/s/commands/cluster_write_cmd.cpp @@ -139,8 +139,8 @@ class ClusterWriteCmd : public Command { public: virtual ~ClusterWriteCmd() {} - bool slaveOk() const final { - return false; + AllowedOnSecondary secondaryAllowed() const final { + return AllowedOnSecondary::kNever; } bool supportsWriteConcern(const BSONObj& cmd) const final { diff --git a/src/mongo/s/commands/commands_public.cpp b/src/mongo/s/commands/commands_public.cpp index 4c153831450..c5e0ecb358d 100644 --- a/src/mongo/s/commands/commands_public.cpp +++ b/src/mongo/s/commands/commands_public.cpp @@ -151,8 +151,8 @@ class PublicGridCommand : public BasicCommand { protected: PublicGridCommand(const char* n, const char* oldname = NULL) : BasicCommand(n, oldname) {} - virtual bool slaveOk() const { - return true; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kAlways; } virtual bool adminOnly() const { @@ -247,8 +247,8 @@ class DropIndexesCmd : public ErrmsgCommandDeprecated { public: DropIndexesCmd() : ErrmsgCommandDeprecated("dropIndexes", "deleteIndexes") {} - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { @@ -291,8 +291,8 @@ class CreateIndexesCmd : public ErrmsgCommandDeprecated { public: CreateIndexesCmd() : ErrmsgCommandDeprecated("createIndexes") {} - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { @@ -340,8 +340,8 @@ class ReIndexCmd : public ErrmsgCommandDeprecated { public: ReIndexCmd() : ErrmsgCommandDeprecated("reIndex") {} - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { @@ -384,8 +384,8 @@ class CollectionModCmd : public ErrmsgCommandDeprecated { public: CollectionModCmd() : ErrmsgCommandDeprecated("collMod") {} - bool slaveOk() const override { - return false; + AllowedOnSecondary secondaryAllowed() const override { + return AllowedOnSecondary::kNever; } bool adminOnly() const override { |