summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2018-01-31 14:30:51 -0500
committerJudah Schvimer <judah@mongodb.com>2018-01-31 14:30:51 -0500
commitd75cb425fbc3cf4b569eb1722c3f8abec45654a2 (patch)
tree95f285d0be51aeafbb22d1ac37bb615df28f20b7
parentbe24b0323d3f2d424d9e22337f4221d39001ac31 (diff)
downloadmongo-d75cb425fbc3cf4b569eb1722c3f8abec45654a2.tar.gz
Revert "SERVER-32958 slaveOk,slaveOverrideOk replacement"
This reverts commit be24b0323d3f2d424d9e22337f4221d39001ac31.
-rw-r--r--src/mongo/client/embedded/SConscript1
-rw-r--r--src/mongo/client/embedded/service_entry_point_embedded.cpp22
-rw-r--r--src/mongo/db/SConscript16
-rw-r--r--src/mongo/db/auth/sasl_commands.cpp8
-rw-r--r--src/mongo/db/command_can_run_here.cpp57
-rw-r--r--src/mongo/db/command_can_run_here.h40
-rw-r--r--src/mongo/db/commands.h13
-rw-r--r--src/mongo/db/commands/SConscript1
-rw-r--r--src/mongo/db/commands/apply_ops_cmd.cpp4
-rw-r--r--src/mongo/db/commands/authentication_commands.cpp8
-rw-r--r--src/mongo/db/commands/authentication_commands.h4
-rw-r--r--src/mongo/db/commands/clone.cpp5
-rw-r--r--src/mongo/db/commands/clone_collection.cpp5
-rw-r--r--src/mongo/db/commands/collection_to_capped.cpp8
-rw-r--r--src/mongo/db/commands/compact.cpp4
-rw-r--r--src/mongo/db/commands/conn_pool_stats.cpp4
-rw-r--r--src/mongo/db/commands/conn_pool_sync.cpp4
-rw-r--r--src/mongo/db/commands/connection_status.cpp4
-rw-r--r--src/mongo/db/commands/copydb.cpp4
-rw-r--r--src/mongo/db/commands/copydb_start_commands.cpp5
-rw-r--r--src/mongo/db/commands/count_cmd.cpp13
-rw-r--r--src/mongo/db/commands/cpuload.cpp4
-rw-r--r--src/mongo/db/commands/cpuprofile.cpp4
-rw-r--r--src/mongo/db/commands/create_indexes.cpp6
-rw-r--r--src/mongo/db/commands/current_op_common.h4
-rw-r--r--src/mongo/db/commands/dbcheck.cpp4
-rw-r--r--src/mongo/db/commands/dbcommands.cpp48
-rw-r--r--src/mongo/db/commands/dbhash.cpp4
-rw-r--r--src/mongo/db/commands/distinct.cpp8
-rw-r--r--src/mongo/db/commands/do_txn_cmd.cpp4
-rw-r--r--src/mongo/db/commands/driverHelpers.cpp8
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp10
-rw-r--r--src/mongo/db/commands/end_sessions_command.cpp4
-rw-r--r--src/mongo/db/commands/eval.cpp4
-rw-r--r--src/mongo/db/commands/explain_cmd.cpp25
-rw-r--r--src/mongo/db/commands/fail_point_cmd.cpp5
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp4
-rw-r--r--src/mongo/db/commands/find_cmd.cpp8
-rw-r--r--src/mongo/db/commands/fsync.cpp8
-rw-r--r--src/mongo/db/commands/generic.cpp75
-rw-r--r--src/mongo/db/commands/geo_near_cmd.cpp7
-rw-r--r--src/mongo/db/commands/get_last_error.cpp12
-rw-r--r--src/mongo/db/commands/getmore_cmd.cpp4
-rw-r--r--src/mongo/db/commands/group_cmd.cpp8
-rw-r--r--src/mongo/db/commands/hashcmd.cpp4
-rw-r--r--src/mongo/db/commands/haystack.cpp8
-rw-r--r--src/mongo/db/commands/index_filter_commands.cpp8
-rw-r--r--src/mongo/db/commands/index_filter_commands.h4
-rw-r--r--src/mongo/db/commands/isself.cpp4
-rw-r--r--src/mongo/db/commands/kill_all_sessions_by_pattern_command.cpp4
-rw-r--r--src/mongo/db/commands/kill_all_sessions_command.cpp4
-rw-r--r--src/mongo/db/commands/kill_op.cpp4
-rw-r--r--src/mongo/db/commands/kill_sessions_command.cpp4
-rw-r--r--src/mongo/db/commands/killcursors_common.h4
-rw-r--r--src/mongo/db/commands/list_collections.cpp7
-rw-r--r--src/mongo/db/commands/list_databases.cpp7
-rw-r--r--src/mongo/db/commands/list_indexes.cpp7
-rw-r--r--src/mongo/db/commands/lock_info.cpp8
-rw-r--r--src/mongo/db/commands/mr.cpp27
-rw-r--r--src/mongo/db/commands/oplog_note.cpp4
-rw-r--r--src/mongo/db/commands/parallel_collection_scan.cpp4
-rw-r--r--src/mongo/db/commands/parameters.cpp8
-rw-r--r--src/mongo/db/commands/pipeline_command.cpp8
-rw-r--r--src/mongo/db/commands/plan_cache_commands.cpp8
-rw-r--r--src/mongo/db/commands/plan_cache_commands.h4
-rw-r--r--src/mongo/db/commands/reap_logical_session_cache_now.cpp4
-rw-r--r--src/mongo/db/commands/refresh_logical_session_cache_now.cpp4
-rw-r--r--src/mongo/db/commands/refresh_sessions_command.cpp4
-rw-r--r--src/mongo/db/commands/refresh_sessions_command_internal.cpp4
-rw-r--r--src/mongo/db/commands/rename_collection_cmd.cpp4
-rw-r--r--src/mongo/db/commands/repair_cursor.cpp4
-rw-r--r--src/mongo/db/commands/resize_oplog.cpp4
-rw-r--r--src/mongo/db/commands/server_status.cpp4
-rw-r--r--src/mongo/db/commands/set_feature_compatibility_version_command.cpp4
-rw-r--r--src/mongo/db/commands/shutdown.h4
-rw-r--r--src/mongo/db/commands/snapshot_management.cpp8
-rw-r--r--src/mongo/db/commands/start_session_command.cpp4
-rw-r--r--src/mongo/db/commands/test_commands.cpp16
-rw-r--r--src/mongo/db/commands/top_command.cpp4
-rw-r--r--src/mongo/db/commands/touch.cpp4
-rw-r--r--src/mongo/db/commands/user_management_commands.cpp84
-rw-r--r--src/mongo/db/commands/validate.cpp4
-rw-r--r--src/mongo/db/commands/write_commands/write_commands.cpp4
-rw-r--r--src/mongo/db/exec/stagedebug_cmd.cpp7
-rw-r--r--src/mongo/db/ftdc/ftdc_commands.cpp4
-rw-r--r--src/mongo/db/repl/master_slave.cpp4
-rw-r--r--src/mongo/db/repl/repl_set_command.h4
-rw-r--r--src/mongo/db/repl/replication_info.cpp4
-rw-r--r--src/mongo/db/repl/resync.cpp4
-rw-r--r--src/mongo/db/s/check_sharding_index_command.cpp4
-rw-r--r--src/mongo/db/s/cleanup_orphaned_cmd.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_add_shard_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_add_shard_to_zone_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_commit_chunk_migration_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_control_balancer_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_create_database_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_drop_collection_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_drop_database_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_enable_sharding_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_merge_chunk_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_move_chunk_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_move_primary_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_remove_shard_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_remove_shard_from_zone_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_shard_collection_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_split_chunk_command.cpp4
-rw-r--r--src/mongo/db/s/config/configsvr_update_zone_key_range_command.cpp4
-rw-r--r--src/mongo/db/s/flush_routing_table_cache_updates_command.cpp4
-rw-r--r--src/mongo/db/s/get_shard_version_command.cpp4
-rw-r--r--src/mongo/db/s/merge_chunks_command.cpp4
-rw-r--r--src/mongo/db/s/migration_chunk_cloner_source_legacy_commands.cpp12
-rw-r--r--src/mongo/db/s/migration_destination_manager_legacy_commands.cpp16
-rw-r--r--src/mongo/db/s/move_chunk_command.cpp4
-rw-r--r--src/mongo/db/s/set_shard_version_command.cpp4
-rw-r--r--src/mongo/db/s/sharding_state_command.cpp4
-rw-r--r--src/mongo/db/s/split_chunk_command.cpp4
-rw-r--r--src/mongo/db/s/split_vector_command.cpp4
-rw-r--r--src/mongo/db/s/unset_sharding_command.cpp4
-rw-r--r--src/mongo/db/service_entry_point_mongod.cpp22
-rw-r--r--src/mongo/db/storage/mmap_v1/journal_latency_test_cmd.cpp4
-rw-r--r--src/mongo/s/client/shard_connection.cpp4
-rw-r--r--src/mongo/s/commands/cluster_add_shard_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_add_shard_to_zone_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_available_query_options_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_compact_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_control_balancer_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_count_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_db_stats_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_drop_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_drop_database_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_enable_sharding_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_explain_cmd.cpp8
-rw-r--r--src/mongo/s/commands/cluster_find_and_modify_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_find_cmd.cpp8
-rw-r--r--src/mongo/s/commands/cluster_flush_router_config_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_fsync_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_ftdc_commands.cpp4
-rw-r--r--src/mongo/s/commands/cluster_get_last_error_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_get_prev_error_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_get_shard_map_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_get_shard_version_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_getmore_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_index_filter_cmd.cpp9
-rw-r--r--src/mongo/s/commands/cluster_is_db_grid_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_is_master_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_kill_op.cpp4
-rw-r--r--src/mongo/s/commands/cluster_list_databases_cmd.cpp8
-rw-r--r--src/mongo/s/commands/cluster_list_shards_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_map_reduce_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_merge_chunks_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_move_chunk_cmd.cpp5
-rw-r--r--src/mongo/s/commands/cluster_move_primary_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_multicast.cpp5
-rw-r--r--src/mongo/s/commands/cluster_netstat_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_pipeline_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_plan_cache_cmd.cpp8
-rw-r--r--src/mongo/s/commands/cluster_profile_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_remove_shard_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_remove_shard_from_zone_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_repl_set_get_status_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_reset_error_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_set_feature_compatibility_version_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_shard_collection_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_split_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_update_zone_key_range_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_user_management_commands.cpp92
-rw-r--r--src/mongo/s/commands/cluster_whats_my_uri_cmd.cpp4
-rw-r--r--src/mongo/s/commands/cluster_write_cmd.cpp4
-rw-r--r--src/mongo/s/commands/commands_public.cpp20
169 files changed, 660 insertions, 658 deletions
diff --git a/src/mongo/client/embedded/SConscript b/src/mongo/client/embedded/SConscript
index 16d45f9fba5..57f9fd9cc48 100644
--- a/src/mongo/client/embedded/SConscript
+++ b/src/mongo/client/embedded/SConscript
@@ -16,7 +16,6 @@ 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 dedf60c54c5..003c5ff95d3 100644
--- a/src/mongo/client/embedded/service_entry_point_embedded.cpp
+++ b/src/mongo/client/embedded/service_entry_point_embedded.cpp
@@ -36,7 +36,6 @@
#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"
@@ -560,13 +559,18 @@ void execCommandDatabase(OperationContext* opCtx,
if (!opCtx->getClient()->isInDirectClient() &&
!MONGO_FAIL_POINT(skipCheckingForNotMasterInCommandDispatch)) {
- 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) {
+
+ 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()) {
uasserted(ErrorCodes::NotMasterNoSlaveOk, "not master and slaveOk=false");
}
@@ -590,7 +594,7 @@ void execCommandDatabase(OperationContext* opCtx,
// Check ticket SERVER-21432, slaveOk commands are allowed in drain mode
uassert(ErrorCodes::NotMasterOrSecondary,
"node is in drain mode",
- optedIn || alwaysAllowed);
+ commandIsOverriddenToRunOnSecondary || commandCanRunOnSecondary);
}
}
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 3869a22a464..6e9ac5f0aaa 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -513,26 +513,11 @@ 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=[
@@ -612,7 +597,6 @@ 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 8a67b45879d..433439ad2b8 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
bool requiresAuth() const override {
return false;
@@ -107,8 +107,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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
deleted file mode 100644
index c945380cc3e..00000000000
--- a/src/mongo/db/command_can_run_here.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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
deleted file mode 100644
index 18ac4653593..00000000000
--- a/src/mongo/db/command_can_run_here.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * 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 58cadbfb3ef..f1e580b69f8 100644
--- a/src/mongo/db/commands.h
+++ b/src/mongo/db/commands.h
@@ -188,7 +188,6 @@ 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
@@ -263,7 +262,17 @@ public:
return false;
}
- virtual AllowedOnSecondary secondaryAllowed() const = 0;
+ /* 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;
+ }
/**
* 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 378e475dc44..36107dce430 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -212,7 +212,6 @@ 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 d0bce7a629e..f2b41250973 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 0b925c3d84c..58e34b87f9d 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()) {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const final {
+ return true;
}
std::string help() const final {
@@ -259,8 +259,8 @@ CmdAuthenticate cmdAuthenticate;
class CmdLogout : public BasicCommand {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 5e886827256..a5123fb932b 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);
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
std::string help() const override {
return "internal";
diff --git a/src/mongo/db/commands/clone.cpp b/src/mongo/db/commands/clone.cpp
index 0e50419a5df..e7ec4973221 100644
--- a/src/mongo/db/commands/clone.cpp
+++ b/src/mongo/db/commands/clone.cpp
@@ -56,10 +56,11 @@ class CmdClone : public BasicCommand {
public:
CmdClone() : BasicCommand("clone") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
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 493ea75d044..0a8ddde8bea 100644
--- a/src/mongo/db/commands/clone_collection.cpp
+++ b/src/mongo/db/commands/clone_collection.cpp
@@ -63,10 +63,11 @@ class CmdCloneCollection : public ErrmsgCommandDeprecated {
public:
CmdCloneCollection() : ErrmsgCommandDeprecated("cloneCollection") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
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 56dad067123..14a3bf3f00e 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
@@ -151,8 +151,8 @@ public:
class CmdConvertToCapped : public ErrmsgCommandDeprecated {
public:
CmdConvertToCapped() : ErrmsgCommandDeprecated("convertToCapped") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 4a52700118c..e914d2f606d 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 e799257d923..298bbda74d4 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 ecf135bb7e6..44893d621e6 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
} poolFlushCmd;
diff --git a/src/mongo/db/commands/connection_status.cpp b/src/mongo/db/commands/connection_status.cpp
index 80b4fdd9e2c..14e6413014f 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 99178166050..297ec8f1c10 100644
--- a/src/mongo/db/commands/copydb.cpp
+++ b/src/mongo/db/commands/copydb.cpp
@@ -95,8 +95,8 @@ public:
return true;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 6f675971ea0..59c21a4fcd2 100644
--- a/src/mongo/db/commands/copydb_start_commands.cpp
+++ b/src/mongo/db/commands/copydb_start_commands.cpp
@@ -78,10 +78,11 @@ public:
return true;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
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 129af8c89de..639d842e1db 100644
--- a/src/mongo/db/commands/count_cmd.cpp
+++ b/src/mongo/db/commands/count_cmd.cpp
@@ -63,12 +63,13 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- if (repl::getGlobalReplicationCoordinator()->getSettings().isSlave()) {
- // ok on --slave setups
- return Command::AllowedOnSecondary::kAlways;
- }
- return Command::AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ // ok on --slave setups
+ return repl::getGlobalReplicationCoordinator()->getSettings().isSlave();
+ }
+
+ virtual bool slaveOverrideOk() const {
+ return true;
}
virtual bool maintenanceOk() const {
diff --git a/src/mongo/db/commands/cpuload.cpp b/src/mongo/db/commands/cpuload.cpp
index 587ee0af693..be297b83ed6 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool isWriteCommandForConfigServer() const {
return false;
diff --git a/src/mongo/db/commands/cpuprofile.cpp b/src/mongo/db/commands/cpuprofile.cpp
index 396e396856d..51cc7d8a205 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) {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 a38c935163c..036e8dc5148 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
- }
+ virtual bool slaveOk() const {
+ return false;
+ } // TODO: this could be made true...
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 367fb7f0ba8..517d494d851 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;
}
- AllowedOnSecondary secondaryAllowed() const final {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const final {
+ return true;
}
bool adminOnly() const final {
diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp
index 3cbc2abe362..15b6e6cd516 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool adminOnly() const {
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index 8f25ddcc13d..b46512cd7e2 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";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual void addRequiredPrivileges(const std::string& dbname,
@@ -210,8 +210,8 @@ public:
class CmdRepairDatabase : public ErrmsgCommandDeprecated {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool maintenanceMode() const {
return true;
@@ -295,8 +295,8 @@ public:
*/
class CmdProfile : public ErrmsgCommandDeprecated {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
std::string help() const override {
@@ -396,8 +396,8 @@ public:
class CmdDrop : public ErrmsgCommandDeprecated {
public:
CmdDrop() : ErrmsgCommandDeprecated("drop") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool adminOnly() const {
return false;
@@ -452,8 +452,8 @@ public:
class CmdCreate : public BasicCommand {
public:
CmdCreate() : BasicCommand("create") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool adminOnly() const {
return false;
@@ -570,8 +570,8 @@ class CmdFileMD5 : public BasicCommand {
public:
CmdFileMD5() : BasicCommand("filemd5") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
std::string help() const override {
@@ -747,8 +747,8 @@ class CmdDatasize : public ErrmsgCommandDeprecated {
public:
CmdDatasize() : ErrmsgCommandDeprecated("dataSize", "datasize") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -897,8 +897,8 @@ class CollectionStats : public ErrmsgCommandDeprecated {
public:
CollectionStats() : ErrmsgCommandDeprecated("collStats", "collstats") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -944,8 +944,8 @@ class CollectionModCommand : public BasicCommand {
public:
CollectionModCommand() : BasicCommand("collMod") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
@@ -978,8 +978,8 @@ class DBStats : public ErrmsgCommandDeprecated {
public:
DBStats() : ErrmsgCommandDeprecated("dbStats", "dbstats") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -1074,8 +1074,8 @@ public:
class CmdWhatsMyUri : public BasicCommand {
public:
CmdWhatsMyUri() : BasicCommand("whatsmyuri") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -1099,8 +1099,8 @@ class AvailableQueryOptions : public BasicCommand {
public:
AvailableQueryOptions() : BasicCommand("availableQueryOptions", "availablequeryoptions") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 e16a3068d12..1a006d41298 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -62,8 +62,8 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual void addRequiredPrivileges(const std::string& dbname,
diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp
index 50b05986912..b12a485d68e 100644
--- a/src/mongo/db/commands/distinct.cpp
+++ b/src/mongo/db/commands/distinct.cpp
@@ -75,8 +75,12 @@ class DistinctCommand : public BasicCommand {
public:
DistinctCommand() : BasicCommand("distinct") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return false;
+ }
+
+ virtual bool slaveOverrideOk() const {
+ return true;
}
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 806d282aa79..3193b5ba30d 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
bool supportsWriteConcern(const BSONObj& cmd) const override {
diff --git a/src/mongo/db/commands/driverHelpers.cpp b/src/mongo/db/commands/driverHelpers.cpp
index 9caef43f7b1..2f1e688aa15 100644
--- a/src/mongo/db/commands/driverHelpers.cpp
+++ b/src/mongo/db/commands/driverHelpers.cpp
@@ -59,9 +59,11 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
-
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
+ }
+ virtual bool slaveOverrideOk() const {
+ return true;
}
};
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index 11cbed2f00c..8f311a94295 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:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
@@ -96,9 +96,9 @@ public:
class CmdReIndex : public ErrmsgCommandDeprecated {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways; // can reindex on a secondary
- }
+ virtual bool slaveOk() const {
+ return true;
+ } // 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 9397d39f841..39383f8e58d 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
bool adminOnly() const override {
return false;
diff --git a/src/mongo/db/commands/eval.cpp b/src/mongo/db/commands/eval.cpp
index 0ae44555037..36153a54181 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:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
std::string help() const override {
diff --git a/src/mongo/db/commands/explain_cmd.cpp b/src/mongo/db/commands/explain_cmd.cpp
index 0c5ffb15a06..08463e626df 100644
--- a/src/mongo/db/commands/explain_cmd.cpp
+++ b/src/mongo/db/commands/explain_cmd.cpp
@@ -28,7 +28,6 @@
#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"
@@ -63,8 +62,12 @@ public:
/**
* Running an explain on a secondary requires explicitly setting slaveOk.
*/
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return false;
+ }
+
+ virtual bool slaveOverrideOk() const {
+ return true;
}
virtual bool maintenanceOk() const {
@@ -146,7 +149,21 @@ public:
return CommandHelpers::appendCommandStatus(result, explainStatus);
}
- if (!commandCanRunHere(opCtx, dbname, commToExplain)) {
+ // 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) {
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 940bc33e6a4..efb705a7bff 100644
--- a/src/mongo/db/commands/fail_point_cmd.cpp
+++ b/src/mongo/db/commands/fail_point_cmd.cpp
@@ -68,10 +68,11 @@ class FaultInjectCmd : public ErrmsgCommandDeprecated {
public:
FaultInjectCmd() : ErrmsgCommandDeprecated("configureFailPoint") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
+
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 d5ebaf935c5..1e8193ce4c9 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";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 7139f52175f..1ce3f931e5b 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -69,8 +69,12 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ bool slaveOk() const override {
+ return false;
+ }
+
+ bool slaveOverrideOk() const override {
+ return true;
}
bool maintenanceOk() const override {
diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp
index 7c4a3799007..eb2b2d375c7 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool adminOnly() const {
return true;
@@ -273,8 +273,8 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
bool adminOnly() const override {
diff --git a/src/mongo/db/commands/generic.cpp b/src/mongo/db/commands/generic.cpp
index 7164b951586..28394239931 100644
--- a/src/mongo/db/commands/generic.cpp
+++ b/src/mongo/db/commands/generic.cpp
@@ -73,11 +73,9 @@ using std::vector;
class CmdBuildInfo : public BasicCommand {
public:
CmdBuildInfo() : BasicCommand("buildInfo", "buildinfo") {}
-
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
-
virtual bool adminOnly() const {
return false;
}
@@ -106,9 +104,8 @@ public:
class PingCommand : public BasicCommand {
public:
PingCommand() : BasicCommand("ping") {}
-
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
std::string help() const override {
return "a way to check that the server is alive. responds immediately even if server is "
@@ -141,8 +138,8 @@ public:
std::string help() const override {
return "return build level feature settings";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -172,11 +169,11 @@ public:
class HostInfoCmd : public BasicCommand {
public:
HostInfoCmd() : BasicCommand("hostInfo") {}
-
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
@@ -224,8 +221,11 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
+ }
+ virtual bool adminOnly() const {
+ return true;
}
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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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->secondaryAllowed() == Command::AllowedOnSecondary::kAlways);
+ temp.append("slaveOk", c->slaveOk());
temp.append("adminOnly", c->adminOnly());
// optionally indicates that the command can be forced to run on a slave/secondary
- if (c->secondaryAllowed() == Command::AllowedOnSecondary::kOptIn)
- temp.append("slaveOverrideOk", true);
+ if (c->slaveOverrideOk())
+ temp.append("slaveOverrideOk", c->slaveOverrideOk());
temp.done();
}
b.done();
@@ -297,37 +297,12 @@ 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -397,8 +372,8 @@ class ClearLogCmd : public BasicCommand {
public:
ClearLogCmd() : BasicCommand("clearLog") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -458,8 +433,8 @@ public:
virtual bool adminOnly() const {
return true;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 7cf8a3b7e02..ac1d839100b 100644
--- a/src/mongo/db/commands/geo_near_cmd.cpp
+++ b/src/mongo/db/commands/geo_near_cmd.cpp
@@ -74,8 +74,11 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const {
+ return true;
+ }
+ bool slaveOverrideOk() const {
+ return true;
}
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 0eb1a9939a0..3d2d6d414c1 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 16e5261dbde..594a2886d08 100644
--- a/src/mongo/db/commands/getmore_cmd.cpp
+++ b/src/mongo/db/commands/getmore_cmd.cpp
@@ -89,8 +89,8 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
bool maintenanceOk() const override {
diff --git a/src/mongo/db/commands/group_cmd.cpp b/src/mongo/db/commands/group_cmd.cpp
index 62f9ee7bbb3..85b93ec071a 100644
--- a/src/mongo/db/commands/group_cmd.cpp
+++ b/src/mongo/db/commands/group_cmd.cpp
@@ -71,8 +71,12 @@ private:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return false;
+ }
+
+ virtual bool slaveOverrideOk() const {
+ return true;
}
bool supportsReadConcern(const std::string& dbName,
diff --git a/src/mongo/db/commands/hashcmd.cpp b/src/mongo/db/commands/hashcmd.cpp
index 021ccfd573a..f65fda66d84 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
// 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 61ccbbb00bc..18f3b1d1edc 100644
--- a/src/mongo/db/commands/haystack.cpp
+++ b/src/mongo/db/commands/haystack.cpp
@@ -68,8 +68,12 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const {
+ return true;
+ }
+
+ bool slaveOverrideOk() const {
+ return true;
}
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 5bbae6c6de0..1eaeadcd656 100644
--- a/src/mongo/db/commands/index_filter_commands.cpp
+++ b/src/mongo/db/commands/index_filter_commands.cpp
@@ -129,8 +129,12 @@ bool IndexFilterCommand::supportsWriteConcern(const BSONObj& cmd) const {
return false;
}
-Command::AllowedOnSecondary IndexFilterCommand::secondaryAllowed() const {
- return AllowedOnSecondary::kOptIn;
+bool IndexFilterCommand::slaveOk() const {
+ return false;
+}
+
+bool IndexFilterCommand::slaveOverrideOk() const {
+ return true;
}
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 72f758806c5..aaa785c0d6b 100644
--- a/src/mongo/db/commands/index_filter_commands.h
+++ b/src/mongo/db/commands/index_filter_commands.h
@@ -70,7 +70,9 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override;
- AllowedOnSecondary secondaryAllowed() const override;
+ virtual bool slaveOk() const;
+
+ virtual bool slaveOverrideOk() const;
std::string help() const override;
diff --git a/src/mongo/db/commands/isself.cpp b/src/mongo/db/commands/isself.cpp
index e3c7d077aae..841dfde9e54 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 645c5e83c2c..708cb67d34b 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 4605a5f1964..86f0a629249 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 8cc2754e919..7b07c87f7ba 100644
--- a/src/mongo/db/commands/kill_op.cpp
+++ b/src/mongo/db/commands/kill_op.cpp
@@ -55,8 +55,8 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const final {
+ return true;
}
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 55f8dfc1a2d..0be33339f25 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 90541adc709..6991a4a0da7 100644
--- a/src/mongo/db/commands/killcursors_common.h
+++ b/src/mongo/db/commands/killcursors_common.h
@@ -45,8 +45,8 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const final {
+ return true;
}
bool maintenanceOk() const final {
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index b92c59034ba..b21c0f959a1 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -197,8 +197,11 @@ BSONObj buildCollectionBson(OperationContext* opCtx,
class CmdListCollections : public BasicCommand {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return false;
+ }
+ virtual bool slaveOverrideOk() const {
+ return true;
}
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 99bc8166021..f91cb10f680 100644
--- a/src/mongo/db/commands/list_databases.cpp
+++ b/src/mongo/db/commands/list_databases.cpp
@@ -57,8 +57,11 @@ intmax_t dbSize(const string& database);
class CmdListDatabases : public BasicCommand {
public:
- AllowedOnSecondary secondaryAllowed() const final {
- return AllowedOnSecondary::kOptIn;
+ bool slaveOk() const final {
+ return false;
+ }
+ bool slaveOverrideOk() const final {
+ return true;
}
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 cef7130a20c..5c23ea9f1c6 100644
--- a/src/mongo/db/commands/list_indexes.cpp
+++ b/src/mongo/db/commands/list_indexes.cpp
@@ -76,8 +76,11 @@ namespace {
*/
class CmdListIndexes : public BasicCommand {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return false;
+ }
+ virtual bool slaveOverrideOk() const {
+ return true;
}
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 3e16e220e39..6bd6aeb3258 100644
--- a/src/mongo/db/commands/lock_info.cpp
+++ b/src/mongo/db/commands/lock_info.cpp
@@ -49,8 +49,12 @@ using std::stringstream;
*/
class CmdLockInfo : public BasicCommand {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
+ }
+
+ virtual bool slaveOverrideOk() const {
+ return true;
}
virtual bool adminOnly() const {
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index ce7d144bfcc..ef9043fd78a 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -1351,12 +1351,13 @@ class MapReduceCommand : public ErrmsgCommandDeprecated {
public:
MapReduceCommand() : ErrmsgCommandDeprecated("mapReduce", "mapreduce") {}
- AllowedOnSecondary secondaryAllowed() const override {
- if (repl::getGlobalReplicationCoordinator()->getReplicationMode() !=
- repl::ReplicationCoordinator::modeReplSet) {
- return AllowedOnSecondary::kAlways;
- }
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return repl::getGlobalReplicationCoordinator()->getReplicationMode() !=
+ repl::ReplicationCoordinator::modeReplSet;
+ }
+
+ virtual bool slaveOverrideOk() const {
+ return true;
}
std::size_t reserveBytesForReply() const override {
@@ -1688,15 +1689,13 @@ public:
return "internal";
}
MapReduceFinishCommand() : BasicCommand("mapreduce.shardedfinish") {}
-
- AllowedOnSecondary secondaryAllowed() const override {
- if (repl::getGlobalReplicationCoordinator()->getReplicationMode() !=
- repl::ReplicationCoordinator::modeReplSet) {
- return AllowedOnSecondary::kAlways;
- }
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return repl::getGlobalReplicationCoordinator()->getReplicationMode() !=
+ repl::ReplicationCoordinator::modeReplSet;
+ }
+ virtual bool slaveOverrideOk() const {
+ return true;
}
-
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 2f1d06b79b5..9b26b979ba6 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 c9f36a820e4..783e74be716 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
bool supportsReadConcern(const std::string& dbName,
diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp
index 391a1ffded8..7e03b90985b 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool adminOnly() const {
return true;
@@ -118,8 +118,8 @@ public:
class CmdSet : public ErrmsgCommandDeprecated {
public:
CmdSet() : ErrmsgCommandDeprecated("setParameter") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 ae607f2713f..8ec12102c35 100644
--- a/src/mongo/db/commands/pipeline_command.cpp
+++ b/src/mongo/db/commands/pipeline_command.cpp
@@ -57,8 +57,12 @@ public:
return Pipeline::aggSupportsWriteConcern(cmd);
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ bool slaveOk() const override {
+ return false;
+ }
+
+ bool slaveOverrideOk() const override {
+ return true;
}
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 a76100a90c7..0cd3593f5c1 100644
--- a/src/mongo/db/commands/plan_cache_commands.cpp
+++ b/src/mongo/db/commands/plan_cache_commands.cpp
@@ -124,8 +124,12 @@ bool PlanCacheCommand::supportsWriteConcern(const BSONObj& cmd) const {
return false;
}
-Command::AllowedOnSecondary PlanCacheCommand::secondaryAllowed() const {
- return AllowedOnSecondary::kOptIn;
+bool PlanCacheCommand::slaveOk() const {
+ return false;
+}
+
+bool PlanCacheCommand::slaveOverrideOk() const {
+ return true;
}
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 c883a189820..0b0a680b2da 100644
--- a/src/mongo/db/commands/plan_cache_commands.h
+++ b/src/mongo/db/commands/plan_cache_commands.h
@@ -64,7 +64,9 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override;
- AllowedOnSecondary secondaryAllowed() const override;
+ virtual bool slaveOk() const;
+
+ virtual bool slaveOverrideOk() const;
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 f04ee086359..879952791fc 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 ff3e018eede..5dcbe213eaa 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 0570821ca1e..4db76567261 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 fa52de2caec..1cfbf7deeb0 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 01cba8c386a..144ecbf847e 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 12c4cfa3528..51567abbabc 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual Status checkAuthForCommand(Client* client,
diff --git a/src/mongo/db/commands/resize_oplog.cpp b/src/mongo/db/commands/resize_oplog.cpp
index ef853e9bb17..4373c9c9dd5 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const final {
+ return true;
}
bool adminOnly() const final {
diff --git a/src/mongo/db/commands/server_status.cpp b/src/mongo/db/commands/server_status.cpp
index 98aefce2f62..a4b63e778f2 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 b4f58018eaa..31e28b6a5b5 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) {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool adminOnly() const {
diff --git a/src/mongo/db/commands/shutdown.h b/src/mongo/db/commands/shutdown.h
index e89aa301261..655d25b367f 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 096cdbf2582..3661447d224 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -92,8 +92,8 @@ class CmdSetCommittedSnapshot final : public BasicCommand {
public:
CmdSetCommittedSnapshot() : BasicCommand("setCommittedSnapshot") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 a577cc01cb7..b621ca02237 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 c7c7c5db1a4..1615117783e 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
@@ -118,8 +118,8 @@ public:
return true;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
std::string help() const override {
@@ -201,8 +201,8 @@ public:
class CapTrunc : public BasicCommand {
public:
CapTrunc() : BasicCommand("captrunc") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
@@ -276,8 +276,8 @@ public:
class EmptyCapped : public BasicCommand {
public:
EmptyCapped() : BasicCommand("emptycapped") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 d7691005285..241c44e5702 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool adminOnly() const {
return true;
diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp
index 2423c3ae6bd..d9c2651f34d 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 7aafdce777b..9ccf077f479 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -758,8 +758,8 @@ class CmdUpdateUser : public BasicCommand {
public:
CmdUpdateUser() : BasicCommand("updateUser") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -892,8 +892,8 @@ class CmdDropUser : public BasicCommand {
public:
CmdDropUser() : BasicCommand("dropUser") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -959,8 +959,8 @@ class CmdDropAllUsersFromDatabase : public BasicCommand {
public:
CmdDropAllUsersFromDatabase() : BasicCommand("dropAllUsersFromDatabase") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1015,8 +1015,8 @@ class CmdGrantRolesToUser : public BasicCommand {
public:
CmdGrantRolesToUser() : BasicCommand("grantRolesToUser") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1087,8 +1087,8 @@ class CmdRevokeRolesFromUser : public BasicCommand {
public:
CmdRevokeRolesFromUser() : BasicCommand("revokeRolesFromUser") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1157,8 +1157,12 @@ public:
class CmdUsersInfo : public BasicCommand {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return false;
+ }
+
+ virtual bool slaveOverrideOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1281,8 +1285,8 @@ class CmdCreateRole : public BasicCommand {
public:
CmdCreateRole() : BasicCommand("createRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1402,8 +1406,8 @@ class CmdUpdateRole : public BasicCommand {
public:
CmdUpdateRole() : BasicCommand("updateRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1519,8 +1523,8 @@ class CmdGrantPrivilegesToRole : public BasicCommand {
public:
CmdGrantPrivilegesToRole() : BasicCommand("grantPrivilegesToRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1629,8 +1633,8 @@ class CmdRevokePrivilegesFromRole : public BasicCommand {
public:
CmdRevokePrivilegesFromRole() : BasicCommand("revokePrivilegesFromRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1741,8 +1745,8 @@ class CmdGrantRolesToRole : public BasicCommand {
public:
CmdGrantRolesToRole() : BasicCommand("grantRolesToRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1830,8 +1834,8 @@ class CmdRevokeRolesFromRole : public BasicCommand {
public:
CmdRevokeRolesFromRole() : BasicCommand("revokeRolesFromRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1914,8 +1918,8 @@ class CmdDropRole : public BasicCommand {
public:
CmdDropRole() : BasicCommand("dropRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -2056,8 +2060,8 @@ class CmdDropAllRolesFromDatabase : public BasicCommand {
public:
CmdDropAllRolesFromDatabase() : BasicCommand("dropAllRolesFromDatabase") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -2187,8 +2191,12 @@ public:
class CmdRolesInfo : public BasicCommand {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return false;
+ }
+
+ virtual bool slaveOverrideOk() const {
+ return true;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -2272,8 +2280,8 @@ public:
class CmdInvalidateUserCache : public BasicCommand {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool adminOnly() const {
@@ -2309,8 +2317,8 @@ public:
class CmdGetCacheGeneration : public BasicCommand {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool adminOnly() const {
@@ -2358,8 +2366,8 @@ class CmdMergeAuthzCollections : public BasicCommand {
public:
CmdMergeAuthzCollections() : BasicCommand("_mergeAuthzCollections") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 1ef643d87cf..f3d04650286 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 ac0a73dee89..922c5a57652 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) {}
- AllowedOnSecondary secondaryAllowed() const final {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const final {
+ return false;
}
bool shouldAffectCommandCounter() const final {
diff --git a/src/mongo/db/exec/stagedebug_cmd.cpp b/src/mongo/db/exec/stagedebug_cmd.cpp
index 642bdf4f5b1..df3e78671df 100644
--- a/src/mongo/db/exec/stagedebug_cmd.cpp
+++ b/src/mongo/db/exec/stagedebug_cmd.cpp
@@ -123,8 +123,11 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const {
+ return false;
+ }
+ bool slaveOverrideOk() const {
+ return false;
}
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 c4067f6ca44..3bd4a75e256 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";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 131bc3b21c9..c0e22a2221a 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 ad97ff5e8b9..fd43ad1c8b2 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) {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
bool adminOnly() const override {
diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp
index 0911a180d36..69c969231ce 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 9b3fab10d2b..ccc566d63c3 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:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 04414dc9051..9d3afd68c8e 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 9b338b0731e..afadefadbd4 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 834aa73ca74..c6354590788 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 00c1af987cf..391aa557867 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 4e9b80d82ea..134032e61c4 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";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 1dc8c20f2c1..19b1fb0f263 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 797f76f5720..556c6b5e0a2 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 fd2c5ca9b93..7bd0bdbd541 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 8a9d35df9e8..cef41aa0d57 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 9bdbd5c5669..2cb4670595f 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 37c32c6781a..3fb76ac3056 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";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 f64994fcfba..904185e754a 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 3ff60940242..7f5b3a4169d 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 d55e81b4ba9..e8d089c9370 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 9aa7f9285e2..7656550edff 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 63b6f00a48d..b602fed5350 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();
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 4d66c7ffa8b..b3f536871e5 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 1742699b038..ed83028907d 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 36ea067ab63..8c4732c1dea 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 2e580a669f8..4ce02d070a6 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 d7a355e5f95..5b7e68fda56 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 a6f9b86e501..785a3309d22 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool adminOnly() const {
@@ -187,8 +187,8 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool adminOnly() const {
@@ -236,8 +236,8 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 36122f38c4f..d4b235f251f 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";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool adminOnly() const {
@@ -163,8 +163,8 @@ public:
return "internal";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool adminOnly() const {
@@ -201,8 +201,8 @@ public:
return "internal";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
virtual bool adminOnly() const {
@@ -247,8 +247,8 @@ public:
return "internal";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 e1cb32cf925..5233290efc2 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";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 1e4f734b16c..7ddd6d2f6a1 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 6fc0887021a..0e3aea8b652 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 3c61c3b1498..8de8e6dc966 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 2ee8ad88d7c..4ac78111bf7 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 a6e6e61d970..5aae6e00a94 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 2b27ec8b22c..1d6d69d257b 100644
--- a/src/mongo/db/service_entry_point_mongod.cpp
+++ b/src/mongo/db/service_entry_point_mongod.cpp
@@ -37,7 +37,6 @@
#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"
@@ -610,13 +609,18 @@ void execCommandDatabase(OperationContext* opCtx,
if (!opCtx->getClient()->isInDirectClient() &&
!MONGO_FAIL_POINT(skipCheckingForNotMasterInCommandDispatch)) {
- 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) {
+
+ 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()) {
uasserted(ErrorCodes::NotMasterNoSlaveOk, "not master and slaveOk=false");
}
@@ -640,7 +644,7 @@ void execCommandDatabase(OperationContext* opCtx,
// Check ticket SERVER-21432, slaveOk commands are allowed in drain mode
uassert(ErrorCodes::NotMasterOrSecondary,
"node is in drain mode",
- optedIn || alwaysAllowed);
+ commandIsOverriddenToRunOnSecondary || commandCanRunOnSecondary);
}
}
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 b8707efd3d1..4f90ba1c6d0 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 fcb033b1025..d79611871e4 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
// 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 df13a652f37..56cdf9650ab 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 419ca7e2a0e..e82e6bc0817 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 8eccb031358..d209c2ace34 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 d5fd03ae39a..3d933804c49 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 5a60b6bb8d8..11e05a559d0 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) {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 2c407b61005..f05f349982c 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 35a24f7d81d..1d74af4d1e7 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 a77abe079a6..6a8081c20c2 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 207db3d3c0d..da0380565eb 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 1869632ef68..77bdbbb6681 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 3f435329d75..b734501ab36 100644
--- a/src/mongo/s/commands/cluster_explain_cmd.cpp
+++ b/src/mongo/s/commands/cluster_explain_cmd.cpp
@@ -61,8 +61,12 @@ public:
/**
* Running an explain on a secondary requires explicitly setting slaveOk.
*/
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return false;
+ }
+
+ virtual bool slaveOverrideOk() const {
+ return true;
}
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 922d271e870..90b5665e6a0 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 8b53c5b6f6b..9c8adb1a64b 100644
--- a/src/mongo/s/commands/cluster_find_cmd.cpp
+++ b/src/mongo/s/commands/cluster_find_cmd.cpp
@@ -65,8 +65,12 @@ public:
return false;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ bool slaveOk() const final {
+ return false;
+ }
+
+ bool slaveOverrideOk() const final {
+ return true;
}
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 2b76f374342..61f0f9d640a 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 3f578bc9ddb..fa6363ed9fb 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 6942bec0bdb..c6c30cebf95 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";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 3134fbb22c3..9665072154d 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 d36e91916b8..399eccc6684 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 6672c597a39..3b70cf27d94 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 05f04d9249a..c55c77ef3f8 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 4274efb7089..00784d5c55c 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;
}
- AllowedOnSecondary secondaryAllowed() const final {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const final {
+ return true;
}
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 ba61748779f..c06c42f2ce0 100644
--- a/src/mongo/s/commands/cluster_index_filter_cmd.cpp
+++ b/src/mongo/s/commands/cluster_index_filter_cmd.cpp
@@ -61,10 +61,15 @@ public:
virtual ~ClusterIndexFilterCmd() {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ bool slaveOk() const {
+ return false;
+ }
+
+ bool slaveOverrideOk() const {
+ return true;
}
+
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 297e4403c2f..3304202e4a7 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 220d97e9e36..8caf0cde2c4 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 3418d4049be..bfeb02ea493 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;
}
- AllowedOnSecondary secondaryAllowed() const final {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const final {
+ return true;
}
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 064b89d3ca4..5a6d8a16552 100644
--- a/src/mongo/s/commands/cluster_list_databases_cmd.cpp
+++ b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
@@ -56,8 +56,12 @@ class ListDatabasesCmd : public BasicCommand {
public:
ListDatabasesCmd() : BasicCommand("listDatabases", "listdatabases") {}
- AllowedOnSecondary secondaryAllowed() const final {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const final {
+ return true;
+ }
+
+ bool slaveOverrideOk() const final {
+ return true;
}
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 59ceb90f106..309c45a3be2 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 5e58c1c0e68..8787beefc09 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 ecdfa931cd4..abfe8fe2f08 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 e251376c920..d1a3ef74e84 100644
--- a/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
+++ b/src/mongo/s/commands/cluster_move_chunk_cmd.cpp
@@ -55,9 +55,10 @@ class MoveChunkCmd : public ErrmsgCommandDeprecated {
public:
MoveChunkCmd() : ErrmsgCommandDeprecated("moveChunk", "movechunk") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
+
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 34540a60b69..181c3a3b8fd 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool adminOnly() const {
diff --git a/src/mongo/s/commands/cluster_multicast.cpp b/src/mongo/s/commands/cluster_multicast.cpp
index b26bdbe4e88..d0d8d11c607 100644
--- a/src/mongo/s/commands/cluster_multicast.cpp
+++ b/src/mongo/s/commands/cluster_multicast.cpp
@@ -66,9 +66,10 @@ class MulticastCmd : public BasicCommand {
public:
MulticastCmd() : BasicCommand("multicast") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
+
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 5dd1e0b1a1a..b8ffa72b530 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 5983c0aa9c6..f9d972d4771 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 8fa4c1edfc2..2e1b63653cd 100644
--- a/src/mongo/s/commands/cluster_plan_cache_cmd.cpp
+++ b/src/mongo/s/commands/cluster_plan_cache_cmd.cpp
@@ -54,8 +54,12 @@ class ClusterPlanCacheCmd : public BasicCommand {
public:
virtual ~ClusterPlanCacheCmd() {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ bool slaveOk() const {
+ return false;
+ }
+
+ bool slaveOverrideOk() const {
+ return true;
}
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 5129922d3a5..cab007638d9 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 336f51d0437..51d863cc668 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.";
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
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 bc35d3c573c..0118f75ee14 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 0c70fdac88c..913d7248d11 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 6df637aaf76..50ba801ba37 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;
}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 2e519bc73f9..04502b0e214 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
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 f9fc5442099..31d230f117f 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 ec5fbe58d37..1b709cf9f95 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ bool slaveOk() const override {
+ return true;
}
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 f286abc6a6b..0abb42b3a22 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
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 f908b1e98e1..a9d6230b8cc 100644
--- a/src/mongo/s/commands/cluster_user_management_commands.cpp
+++ b/src/mongo/s/commands/cluster_user_management_commands.cpp
@@ -67,10 +67,11 @@ class CmdCreateUser : public BasicCommand {
public:
CmdCreateUser() : BasicCommand("createUser") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
@@ -107,10 +108,11 @@ class CmdUpdateUser : public BasicCommand {
public:
CmdUpdateUser() : BasicCommand("updateUser") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
@@ -158,8 +160,8 @@ class CmdDropUser : public BasicCommand {
public:
CmdDropUser() : BasicCommand("dropUser") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
@@ -206,10 +208,11 @@ class CmdDropAllUsersFromDatabase : public BasicCommand {
public:
CmdDropAllUsersFromDatabase() : BasicCommand("dropAllUsersFromDatabase") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
@@ -248,8 +251,8 @@ class CmdGrantRolesToUser : public BasicCommand {
public:
CmdGrantRolesToUser() : BasicCommand("grantRolesToUser") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
@@ -298,8 +301,8 @@ class CmdRevokeRolesFromUser : public BasicCommand {
public:
CmdRevokeRolesFromUser() : BasicCommand("revokeRolesFromUser") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
@@ -346,10 +349,15 @@ public:
class CmdUsersInfo : public BasicCommand {
public:
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return false;
}
+ virtual bool slaveOverrideOk() const {
+ return true;
+ }
+
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
@@ -380,10 +388,11 @@ class CmdCreateRole : public BasicCommand {
public:
CmdCreateRole() : BasicCommand("createRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
@@ -416,10 +425,11 @@ class CmdUpdateRole : public BasicCommand {
public:
CmdUpdateRole() : BasicCommand("updateRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
@@ -458,8 +468,8 @@ class CmdGrantPrivilegesToRole : public BasicCommand {
public:
CmdGrantPrivilegesToRole() : BasicCommand("grantPrivilegesToRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
@@ -501,10 +511,11 @@ class CmdRevokePrivilegesFromRole : public BasicCommand {
public:
CmdRevokePrivilegesFromRole() : BasicCommand("revokePrivilegesFromRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
@@ -543,10 +554,11 @@ class CmdGrantRolesToRole : public BasicCommand {
public:
CmdGrantRolesToRole() : BasicCommand("grantRolesToRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
@@ -585,10 +597,11 @@ class CmdRevokeRolesFromRole : public BasicCommand {
public:
CmdRevokeRolesFromRole() : BasicCommand("revokeRolesFromRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
@@ -627,10 +640,11 @@ class CmdDropRole : public BasicCommand {
public:
CmdDropRole() : BasicCommand("dropRole") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
@@ -672,8 +686,8 @@ class CmdDropAllRolesFromDatabase : public BasicCommand {
public:
CmdDropAllRolesFromDatabase() : BasicCommand("dropAllRolesFromDatabase") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
@@ -719,10 +733,15 @@ class CmdRolesInfo : public BasicCommand {
public:
CmdRolesInfo() : BasicCommand("rolesInfo") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kOptIn;
+ virtual bool slaveOk() const {
+ return false;
+ }
+
+ virtual bool slaveOverrideOk() const {
+ return true;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
@@ -751,8 +770,8 @@ class CmdInvalidateUserCache : public BasicCommand {
public:
CmdInvalidateUserCache() : BasicCommand("invalidateUserCache") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool adminOnly() const {
@@ -800,10 +819,11 @@ class CmdMergeAuthzCollections : public BasicCommand {
public:
CmdMergeAuthzCollections() : BasicCommand("_mergeAuthzCollections") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ virtual bool slaveOk() const {
+ return false;
}
+
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 7cd621302ba..a44d6fbb8c1 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") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
diff --git a/src/mongo/s/commands/cluster_write_cmd.cpp b/src/mongo/s/commands/cluster_write_cmd.cpp
index 779b3993c99..bf1949d73c8 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() {}
- AllowedOnSecondary secondaryAllowed() const final {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const final {
+ return false;
}
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 c5e0ecb358d..4c153831450 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) {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kAlways;
+ virtual bool slaveOk() const {
+ return true;
}
virtual bool adminOnly() const {
@@ -247,8 +247,8 @@ class DropIndexesCmd : public ErrmsgCommandDeprecated {
public:
DropIndexesCmd() : ErrmsgCommandDeprecated("dropIndexes", "deleteIndexes") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
bool adminOnly() const override {
@@ -291,8 +291,8 @@ class CreateIndexesCmd : public ErrmsgCommandDeprecated {
public:
CreateIndexesCmd() : ErrmsgCommandDeprecated("createIndexes") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
bool adminOnly() const override {
@@ -340,8 +340,8 @@ class ReIndexCmd : public ErrmsgCommandDeprecated {
public:
ReIndexCmd() : ErrmsgCommandDeprecated("reIndex") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
bool adminOnly() const override {
@@ -384,8 +384,8 @@ class CollectionModCmd : public ErrmsgCommandDeprecated {
public:
CollectionModCmd() : ErrmsgCommandDeprecated("collMod") {}
- AllowedOnSecondary secondaryAllowed() const override {
- return AllowedOnSecondary::kNever;
+ bool slaveOk() const override {
+ return false;
}
bool adminOnly() const override {