summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/commands')
-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/restart_catalog_command.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
77 files changed, 300 insertions, 353 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index 36107dce430..378e475dc44 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -212,6 +212,7 @@ env.Library(
'$BUILD_DIR/mongo/db/catalog/collection',
'$BUILD_DIR/mongo/db/catalog/index_key_validate',
'$BUILD_DIR/mongo/db/cloner',
+ '$BUILD_DIR/mongo/db/command_can_run_here',
'$BUILD_DIR/mongo/db/commands',
'$BUILD_DIR/mongo/db/exec/stagedebug_cmd',
'$BUILD_DIR/mongo/db/index/index_access_method',
diff --git a/src/mongo/db/commands/apply_ops_cmd.cpp b/src/mongo/db/commands/apply_ops_cmd.cpp
index f2b41250973..d0bce7a629e 100644
--- a/src/mongo/db/commands/apply_ops_cmd.cpp
+++ b/src/mongo/db/commands/apply_ops_cmd.cpp
@@ -202,8 +202,8 @@ class ApplyOpsCmd : public BasicCommand {
public:
ApplyOpsCmd() : BasicCommand("applyOps") {}
- bool slaveOk() const override {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
bool supportsWriteConcern(const BSONObj& cmd) const override {
diff --git a/src/mongo/db/commands/authentication_commands.cpp b/src/mongo/db/commands/authentication_commands.cpp
index 58e34b87f9d..0b925c3d84c 100644
--- a/src/mongo/db/commands/authentication_commands.cpp
+++ b/src/mongo/db/commands/authentication_commands.cpp
@@ -97,8 +97,8 @@ class CmdGetNonce : public BasicCommand {
public:
CmdGetNonce() : BasicCommand("getnonce"), _random(SecureRandom::create()) {}
- bool slaveOk() const final {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
std::string help() const final {
@@ -259,8 +259,8 @@ CmdAuthenticate cmdAuthenticate;
class CmdLogout : public BasicCommand {
public:
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
diff --git a/src/mongo/db/commands/authentication_commands.h b/src/mongo/db/commands/authentication_commands.h
index a5123fb932b..5e886827256 100644
--- a/src/mongo/db/commands/authentication_commands.h
+++ b/src/mongo/db/commands/authentication_commands.h
@@ -40,8 +40,8 @@ class CmdAuthenticate : public BasicCommand {
public:
static void disableAuthMechanism(std::string authMechanism);
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
std::string help() const override {
return "internal";
diff --git a/src/mongo/db/commands/clone.cpp b/src/mongo/db/commands/clone.cpp
index e7ec4973221..0e50419a5df 100644
--- a/src/mongo/db/commands/clone.cpp
+++ b/src/mongo/db/commands/clone.cpp
@@ -56,11 +56,10 @@ class CmdClone : public BasicCommand {
public:
CmdClone() : BasicCommand("clone") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
-
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
diff --git a/src/mongo/db/commands/clone_collection.cpp b/src/mongo/db/commands/clone_collection.cpp
index 0a8ddde8bea..493ea75d044 100644
--- a/src/mongo/db/commands/clone_collection.cpp
+++ b/src/mongo/db/commands/clone_collection.cpp
@@ -63,11 +63,10 @@ class CmdCloneCollection : public ErrmsgCommandDeprecated {
public:
CmdCloneCollection() : ErrmsgCommandDeprecated("cloneCollection") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
-
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
diff --git a/src/mongo/db/commands/collection_to_capped.cpp b/src/mongo/db/commands/collection_to_capped.cpp
index 14a3bf3f00e..56dad067123 100644
--- a/src/mongo/db/commands/collection_to_capped.cpp
+++ b/src/mongo/db/commands/collection_to_capped.cpp
@@ -52,8 +52,8 @@ using std::stringstream;
class CmdCloneCollectionAsCapped : public ErrmsgCommandDeprecated {
public:
CmdCloneCollectionAsCapped() : ErrmsgCommandDeprecated("cloneCollectionAsCapped") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
@@ -151,8 +151,8 @@ public:
class CmdConvertToCapped : public ErrmsgCommandDeprecated {
public:
CmdConvertToCapped() : ErrmsgCommandDeprecated("convertToCapped") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
diff --git a/src/mongo/db/commands/compact.cpp b/src/mongo/db/commands/compact.cpp
index e914d2f606d..4a52700118c 100644
--- a/src/mongo/db/commands/compact.cpp
+++ b/src/mongo/db/commands/compact.cpp
@@ -61,8 +61,8 @@ public:
virtual bool adminOnly() const {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool maintenanceMode() const {
return true;
diff --git a/src/mongo/db/commands/conn_pool_stats.cpp b/src/mongo/db/commands/conn_pool_stats.cpp
index 298bbda74d4..e799257d923 100644
--- a/src/mongo/db/commands/conn_pool_stats.cpp
+++ b/src/mongo/db/commands/conn_pool_stats.cpp
@@ -53,8 +53,8 @@ public:
return "stats about connections between servers in a replica set or sharded cluster.";
}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool supportsWriteConcern(const BSONObj& cmd) const override {
diff --git a/src/mongo/db/commands/conn_pool_sync.cpp b/src/mongo/db/commands/conn_pool_sync.cpp
index 44893d621e6..ecf135bb7e6 100644
--- a/src/mongo/db/commands/conn_pool_sync.cpp
+++ b/src/mongo/db/commands/conn_pool_sync.cpp
@@ -62,8 +62,8 @@ public:
globalConnPool.flush();
return true;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
} poolFlushCmd;
diff --git a/src/mongo/db/commands/connection_status.cpp b/src/mongo/db/commands/connection_status.cpp
index 14e6413014f..80b4fdd9e2c 100644
--- a/src/mongo/db/commands/connection_status.cpp
+++ b/src/mongo/db/commands/connection_status.cpp
@@ -41,8 +41,8 @@ using std::stringstream;
class CmdConnectionStatus : public BasicCommand {
public:
CmdConnectionStatus() : BasicCommand("connectionStatus") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
diff --git a/src/mongo/db/commands/copydb.cpp b/src/mongo/db/commands/copydb.cpp
index 297ec8f1c10..99178166050 100644
--- a/src/mongo/db/commands/copydb.cpp
+++ b/src/mongo/db/commands/copydb.cpp
@@ -95,8 +95,8 @@ public:
return true;
}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
diff --git a/src/mongo/db/commands/copydb_start_commands.cpp b/src/mongo/db/commands/copydb_start_commands.cpp
index 59c21a4fcd2..6f675971ea0 100644
--- a/src/mongo/db/commands/copydb_start_commands.cpp
+++ b/src/mongo/db/commands/copydb_start_commands.cpp
@@ -78,11 +78,10 @@ public:
return true;
}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
-
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp
index 639d842e1db..129af8c89de 100644
--- a/src/mongo/db/commands/count_cmd.cpp
+++ b/src/mongo/db/commands/count_cmd.cpp
@@ -63,13 +63,12 @@ public:
return false;
}
- virtual bool slaveOk() const {
- // ok on --slave setups
- return repl::getGlobalReplicationCoordinator()->getSettings().isSlave();
- }
-
- virtual bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ if (repl::getGlobalReplicationCoordinator()->getSettings().isSlave()) {
+ // ok on --slave setups
+ return Command::AllowedOnSecondary::kAlways;
+ }
+ return Command::AllowedOnSecondary::kOptIn;
}
virtual bool maintenanceOk() const {
diff --git a/src/mongo/db/commands/cpuload.cpp b/src/mongo/db/commands/cpuload.cpp
index be297b83ed6..587ee0af693 100644
--- a/src/mongo/db/commands/cpuload.cpp
+++ b/src/mongo/db/commands/cpuload.cpp
@@ -42,8 +42,8 @@ using std::stringstream;
class CPULoadCommand : public BasicCommand {
public:
CPULoadCommand() : BasicCommand("cpuload") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool isWriteCommandForConfigServer() const {
return false;
diff --git a/src/mongo/db/commands/cpuprofile.cpp b/src/mongo/db/commands/cpuprofile.cpp
index 51cc7d8a205..396e396856d 100644
--- a/src/mongo/db/commands/cpuprofile.cpp
+++ b/src/mongo/db/commands/cpuprofile.cpp
@@ -71,8 +71,8 @@ namespace {
class CpuProfilerCommand : public ErrmsgCommandDeprecated {
public:
CpuProfilerCommand(char const* name) : ErrmsgCommandDeprecated(name) {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool adminOnly() const {
return true;
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index 036e8dc5148..a38c935163c 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -216,9 +216,9 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
- virtual bool slaveOk() const {
- return false;
- } // TODO: this could be made true...
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
+ }
virtual Status checkAuthForCommand(Client* client,
const std::string& dbname,
diff --git a/src/mongo/db/commands/current_op_common.h b/src/mongo/db/commands/current_op_common.h
index 517d494d851..367fb7f0ba8 100644
--- a/src/mongo/db/commands/current_op_common.h
+++ b/src/mongo/db/commands/current_op_common.h
@@ -51,8 +51,8 @@ public:
return false;
}
- bool slaveOk() const final {
- return true;
+ AllowedOnSecondary secondaryAllowed() const final {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const final {
diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp
index 15b6e6cd516..3cbc2abe362 100644
--- a/src/mongo/db/commands/dbcheck.cpp
+++ b/src/mongo/db/commands/dbcheck.cpp
@@ -489,8 +489,8 @@ class DbCheckCmd : public BasicCommand {
public:
DbCheckCmd() : BasicCommand("dbCheck") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool adminOnly() const {
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index b46512cd7e2..8f25ddcc13d 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -147,8 +147,8 @@ public:
std::string help() const override {
return "drop (delete) this database";
}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual void addRequiredPrivileges(const std::string& dbname,
@@ -210,8 +210,8 @@ public:
class CmdRepairDatabase : public ErrmsgCommandDeprecated {
public:
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool maintenanceMode() const {
return true;
@@ -295,8 +295,8 @@ public:
*/
class CmdProfile : public ErrmsgCommandDeprecated {
public:
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
std::string help() const override {
@@ -396,8 +396,8 @@ public:
class CmdDrop : public ErrmsgCommandDeprecated {
public:
CmdDrop() : ErrmsgCommandDeprecated("drop") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool adminOnly() const {
return false;
@@ -452,8 +452,8 @@ public:
class CmdCreate : public BasicCommand {
public:
CmdCreate() : BasicCommand("create") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool adminOnly() const {
return false;
@@ -570,8 +570,8 @@ class CmdFileMD5 : public BasicCommand {
public:
CmdFileMD5() : BasicCommand("filemd5") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
std::string help() const override {
@@ -747,8 +747,8 @@ class CmdDatasize : public ErrmsgCommandDeprecated {
public:
CmdDatasize() : ErrmsgCommandDeprecated("dataSize", "datasize") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -897,8 +897,8 @@ class CollectionStats : public ErrmsgCommandDeprecated {
public:
CollectionStats() : ErrmsgCommandDeprecated("collStats", "collstats") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -944,8 +944,8 @@ class CollectionModCommand : public BasicCommand {
public:
CollectionModCommand() : BasicCommand("collMod") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
@@ -978,8 +978,8 @@ class DBStats : public ErrmsgCommandDeprecated {
public:
DBStats() : ErrmsgCommandDeprecated("dbStats", "dbstats") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -1074,8 +1074,8 @@ public:
class CmdWhatsMyUri : public BasicCommand {
public:
CmdWhatsMyUri() : BasicCommand("whatsmyuri") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -1099,8 +1099,8 @@ class AvailableQueryOptions : public BasicCommand {
public:
AvailableQueryOptions() : BasicCommand("availableQueryOptions", "availablequeryoptions") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index 1a006d41298..e16a3068d12 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -62,8 +62,8 @@ public:
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual void addRequiredPrivileges(const std::string& dbname,
diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp
index b12a485d68e..50b05986912 100644
--- a/src/mongo/db/commands/distinct.cpp
+++ b/src/mongo/db/commands/distinct.cpp
@@ -75,12 +75,8 @@ class DistinctCommand : public BasicCommand {
public:
DistinctCommand() : BasicCommand("distinct") {}
- virtual bool slaveOk() const {
- return false;
- }
-
- virtual bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kOptIn;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
diff --git a/src/mongo/db/commands/do_txn_cmd.cpp b/src/mongo/db/commands/do_txn_cmd.cpp
index 3193b5ba30d..806d282aa79 100644
--- a/src/mongo/db/commands/do_txn_cmd.cpp
+++ b/src/mongo/db/commands/do_txn_cmd.cpp
@@ -131,8 +131,8 @@ class DoTxnCmd : public BasicCommand {
public:
DoTxnCmd() : BasicCommand("doTxn") {}
- bool slaveOk() const override {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
bool supportsWriteConcern(const BSONObj& cmd) const override {
diff --git a/src/mongo/db/commands/driverHelpers.cpp b/src/mongo/db/commands/driverHelpers.cpp
index 2f1e688aa15..9caef43f7b1 100644
--- a/src/mongo/db/commands/driverHelpers.cpp
+++ b/src/mongo/db/commands/driverHelpers.cpp
@@ -59,11 +59,9 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
- return true;
- }
- virtual bool slaveOverrideOk() const {
- return true;
+
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
};
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index 8f311a94295..11cbed2f00c 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -66,8 +66,8 @@ using std::vector;
/* "dropIndexes" is now the preferred form - "deleteIndexes" deprecated */
class CmdDropIndexes : public BasicCommand {
public:
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
@@ -96,9 +96,9 @@ public:
class CmdReIndex : public ErrmsgCommandDeprecated {
public:
- virtual bool slaveOk() const {
- return true;
- } // can reindex on a secondary
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways; // can reindex on a secondary
+ }
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
diff --git a/src/mongo/db/commands/end_sessions_command.cpp b/src/mongo/db/commands/end_sessions_command.cpp
index 39383f8e58d..9397d39f841 100644
--- a/src/mongo/db/commands/end_sessions_command.cpp
+++ b/src/mongo/db/commands/end_sessions_command.cpp
@@ -44,8 +44,8 @@ class EndSessionsCommand final : public BasicCommand {
public:
EndSessionsCommand() : BasicCommand("endSessions") {}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const override {
return false;
diff --git a/src/mongo/db/commands/eval.cpp b/src/mongo/db/commands/eval.cpp
index 36153a54181..0ae44555037 100644
--- a/src/mongo/db/commands/eval.cpp
+++ b/src/mongo/db/commands/eval.cpp
@@ -154,8 +154,8 @@ bool dbEval(OperationContext* opCtx,
class CmdEval : public ErrmsgCommandDeprecated {
public:
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
std::string help() const override {
diff --git a/src/mongo/db/commands/explain_cmd.cpp b/src/mongo/db/commands/explain_cmd.cpp
index 08463e626df..0c5ffb15a06 100644
--- a/src/mongo/db/commands/explain_cmd.cpp
+++ b/src/mongo/db/commands/explain_cmd.cpp
@@ -28,6 +28,7 @@
#include "mongo/platform/basic.h"
+#include "mongo/db/command_can_run_here.h"
#include "mongo/db/commands.h"
#include "mongo/db/query/explain.h"
#include "mongo/db/repl/replication_coordinator_global.h"
@@ -62,12 +63,8 @@ public:
/**
* Running an explain on a secondary requires explicitly setting slaveOk.
*/
- virtual bool slaveOk() const {
- return false;
- }
-
- virtual bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kOptIn;
}
virtual bool maintenanceOk() const {
@@ -149,21 +146,7 @@ public:
return CommandHelpers::appendCommandStatus(result, explainStatus);
}
- // Check whether the child command is allowed to run here. TODO: this logic is
- // copied from Command::execCommand and should be abstracted. Until then, make
- // sure to keep it up to date.
- repl::ReplicationCoordinator* replCoord = repl::ReplicationCoordinator::get(opCtx);
- bool iAmPrimary = replCoord->canAcceptWritesForDatabase_UNSAFE(opCtx, dbname);
- bool commandCanRunOnSecondary = commToExplain->slaveOk();
-
- bool commandIsOverriddenToRunOnSecondary = commToExplain->slaveOverrideOk() &&
- ReadPreferenceSetting::get(opCtx).canRunOnSecondary();
- bool iAmStandalone = !opCtx->writesAreReplicated();
-
- const bool canRunHere = iAmPrimary || commandCanRunOnSecondary ||
- commandIsOverriddenToRunOnSecondary || iAmStandalone;
-
- if (!canRunHere) {
+ if (!commandCanRunHere(opCtx, dbname, commToExplain)) {
mongoutils::str::stream ss;
ss << "Explain's child command cannot run on this node. "
<< "Are you explaining a write command on a secondary?";
diff --git a/src/mongo/db/commands/fail_point_cmd.cpp b/src/mongo/db/commands/fail_point_cmd.cpp
index efb705a7bff..940bc33e6a4 100644
--- a/src/mongo/db/commands/fail_point_cmd.cpp
+++ b/src/mongo/db/commands/fail_point_cmd.cpp
@@ -68,11 +68,10 @@ class FaultInjectCmd : public ErrmsgCommandDeprecated {
public:
FaultInjectCmd() : ErrmsgCommandDeprecated("configureFailPoint") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
-
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index 1e8193ce4c9..d5ebaf935c5 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -220,8 +220,8 @@ public:
"Output is in the \"value\" field\n";
}
- bool slaveOk() const override {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
bool supportsReadConcern(const std::string& dbName,
diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp
index 1ce3f931e5b..7139f52175f 100644
--- a/src/mongo/db/commands/find_cmd.cpp
+++ b/src/mongo/db/commands/find_cmd.cpp
@@ -69,12 +69,8 @@ public:
return false;
}
- bool slaveOk() const override {
- return false;
- }
-
- bool slaveOverrideOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kOptIn;
}
bool maintenanceOk() const override {
diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp
index eb2b2d375c7..7c4a3799007 100644
--- a/src/mongo/db/commands/fsync.cpp
+++ b/src/mongo/db/commands/fsync.cpp
@@ -101,8 +101,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool adminOnly() const {
return true;
@@ -273,8 +273,8 @@ public:
return false;
}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const override {
diff --git a/src/mongo/db/commands/generic.cpp b/src/mongo/db/commands/generic.cpp
index 28394239931..7164b951586 100644
--- a/src/mongo/db/commands/generic.cpp
+++ b/src/mongo/db/commands/generic.cpp
@@ -73,9 +73,11 @@ using std::vector;
class CmdBuildInfo : public BasicCommand {
public:
CmdBuildInfo() : BasicCommand("buildInfo", "buildinfo") {}
- virtual bool slaveOk() const {
- return true;
+
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
+
virtual bool adminOnly() const {
return false;
}
@@ -104,8 +106,9 @@ public:
class PingCommand : public BasicCommand {
public:
PingCommand() : BasicCommand("ping") {}
- virtual bool slaveOk() const {
- return true;
+
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
std::string help() const override {
return "a way to check that the server is alive. responds immediately even if server is "
@@ -138,8 +141,8 @@ public:
std::string help() const override {
return "return build level feature settings";
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -169,10 +172,10 @@ public:
class HostInfoCmd : public BasicCommand {
public:
HostInfoCmd() : BasicCommand("hostInfo") {}
- virtual bool slaveOk() const {
- return true;
- }
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
+ }
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -221,11 +224,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
- return true;
- }
- virtual bool adminOnly() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
@@ -255,8 +255,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool adminOnly() const {
return false;
@@ -283,11 +283,11 @@ public:
for (const auto& c : commands) {
BSONObjBuilder temp(b.subobjStart(c->getName()));
temp.append("help", c->help());
- temp.append("slaveOk", c->slaveOk());
+ temp.append("slaveOk", c->secondaryAllowed() == Command::AllowedOnSecondary::kAlways);
temp.append("adminOnly", c->adminOnly());
// optionally indicates that the command can be forced to run on a slave/secondary
- if (c->slaveOverrideOk())
- temp.append("slaveOverrideOk", c->slaveOverrideOk());
+ if (c->secondaryAllowed() == Command::AllowedOnSecondary::kOptIn)
+ temp.append("slaveOverrideOk", true);
temp.done();
}
b.done();
@@ -297,12 +297,37 @@ public:
} listCommandsCmd;
+/* for testing purposes only */
+class CmdForceError : public BasicCommand {
+public:
+ std::string help() const override {
+ return "for testing purposes only. forces a user assertion exception";
+ }
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
+ }
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
+ virtual void addRequiredPrivileges(const std::string& dbname,
+ const BSONObj& cmdObj,
+ std::vector<Privilege>* out) {} // No auth required
+ CmdForceError() : BasicCommand("forceerror") {}
+ bool run(OperationContext* opCtx,
+ const string& dbnamne,
+ const BSONObj& cmdObj,
+ BSONObjBuilder& result) {
+ LastError::get(cc()).setLastError(10038, "forced error");
+ return false;
+ }
+} cmdForceError;
+
class GetLogCmd : public ErrmsgCommandDeprecated {
public:
GetLogCmd() : ErrmsgCommandDeprecated("getLog") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -372,8 +397,8 @@ class ClearLogCmd : public BasicCommand {
public:
ClearLogCmd() : BasicCommand("clearLog") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -433,8 +458,8 @@ public:
virtual bool adminOnly() const {
return true;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
diff --git a/src/mongo/db/commands/geo_near_cmd.cpp b/src/mongo/db/commands/geo_near_cmd.cpp
index ac1d839100b..7cf8a3b7e02 100644
--- a/src/mongo/db/commands/geo_near_cmd.cpp
+++ b/src/mongo/db/commands/geo_near_cmd.cpp
@@ -74,11 +74,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- bool slaveOk() const {
- return true;
- }
- bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool supportsReadConcern(const std::string& dbName,
const BSONObj& cmdObj,
diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp
index 3d2d6d414c1..0eb1a9939a0 100644
--- a/src/mongo/db/commands/get_last_error.cpp
+++ b/src/mongo/db/commands/get_last_error.cpp
@@ -60,8 +60,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
@@ -90,8 +90,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
@@ -313,8 +313,8 @@ public:
std::string help() const override {
return "check for errors since last reseterror commandcal";
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool requiresAuth() const override {
return false;
diff --git a/src/mongo/db/commands/getmore_cmd.cpp b/src/mongo/db/commands/getmore_cmd.cpp
index 594a2886d08..16e5261dbde 100644
--- a/src/mongo/db/commands/getmore_cmd.cpp
+++ b/src/mongo/db/commands/getmore_cmd.cpp
@@ -89,8 +89,8 @@ public:
return false;
}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool maintenanceOk() const override {
diff --git a/src/mongo/db/commands/group_cmd.cpp b/src/mongo/db/commands/group_cmd.cpp
index 85b93ec071a..62f9ee7bbb3 100644
--- a/src/mongo/db/commands/group_cmd.cpp
+++ b/src/mongo/db/commands/group_cmd.cpp
@@ -71,12 +71,8 @@ private:
return false;
}
- virtual bool slaveOk() const {
- return false;
- }
-
- virtual bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kOptIn;
}
bool supportsReadConcern(const std::string& dbName,
diff --git a/src/mongo/db/commands/hashcmd.cpp b/src/mongo/db/commands/hashcmd.cpp
index f65fda66d84..021ccfd573a 100644
--- a/src/mongo/db/commands/hashcmd.cpp
+++ b/src/mongo/db/commands/hashcmd.cpp
@@ -56,8 +56,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
// No auth needed because it only works when enabled via command line.
virtual void addRequiredPrivileges(const std::string& dbname,
diff --git a/src/mongo/db/commands/haystack.cpp b/src/mongo/db/commands/haystack.cpp
index 18f3b1d1edc..61ccbbb00bc 100644
--- a/src/mongo/db/commands/haystack.cpp
+++ b/src/mongo/db/commands/haystack.cpp
@@ -68,12 +68,8 @@ public:
return false;
}
- bool slaveOk() const {
- return true;
- }
-
- bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool supportsReadConcern(const std::string& dbName,
diff --git a/src/mongo/db/commands/index_filter_commands.cpp b/src/mongo/db/commands/index_filter_commands.cpp
index 1eaeadcd656..5bbae6c6de0 100644
--- a/src/mongo/db/commands/index_filter_commands.cpp
+++ b/src/mongo/db/commands/index_filter_commands.cpp
@@ -129,12 +129,8 @@ bool IndexFilterCommand::supportsWriteConcern(const BSONObj& cmd) const {
return false;
}
-bool IndexFilterCommand::slaveOk() const {
- return false;
-}
-
-bool IndexFilterCommand::slaveOverrideOk() const {
- return true;
+Command::AllowedOnSecondary IndexFilterCommand::secondaryAllowed() const {
+ return AllowedOnSecondary::kOptIn;
}
std::string IndexFilterCommand::help() const {
diff --git a/src/mongo/db/commands/index_filter_commands.h b/src/mongo/db/commands/index_filter_commands.h
index aaa785c0d6b..72f758806c5 100644
--- a/src/mongo/db/commands/index_filter_commands.h
+++ b/src/mongo/db/commands/index_filter_commands.h
@@ -70,9 +70,7 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override;
- virtual bool slaveOk() const;
-
- virtual bool slaveOverrideOk() const;
+ AllowedOnSecondary secondaryAllowed() const override;
std::string help() const override;
diff --git a/src/mongo/db/commands/isself.cpp b/src/mongo/db/commands/isself.cpp
index 841dfde9e54..e3c7d077aae 100644
--- a/src/mongo/db/commands/isself.cpp
+++ b/src/mongo/db/commands/isself.cpp
@@ -42,8 +42,8 @@ using std::stringstream;
class IsSelfCommand : public BasicCommand {
public:
IsSelfCommand() : BasicCommand("_isSelf") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
diff --git a/src/mongo/db/commands/kill_all_sessions_by_pattern_command.cpp b/src/mongo/db/commands/kill_all_sessions_by_pattern_command.cpp
index 708cb67d34b..645c5e83c2c 100644
--- a/src/mongo/db/commands/kill_all_sessions_by_pattern_command.cpp
+++ b/src/mongo/db/commands/kill_all_sessions_by_pattern_command.cpp
@@ -57,8 +57,8 @@ class KillAllSessionsByPatternCommand final : public BasicCommand {
public:
KillAllSessionsByPatternCommand() : BasicCommand("killAllSessionsByPattern") {}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const override {
return false;
diff --git a/src/mongo/db/commands/kill_all_sessions_command.cpp b/src/mongo/db/commands/kill_all_sessions_command.cpp
index 86f0a629249..4605a5f1964 100644
--- a/src/mongo/db/commands/kill_all_sessions_command.cpp
+++ b/src/mongo/db/commands/kill_all_sessions_command.cpp
@@ -57,8 +57,8 @@ class KillAllSessionsCommand final : public BasicCommand {
public:
KillAllSessionsCommand() : BasicCommand("killAllSessions") {}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const override {
return false;
diff --git a/src/mongo/db/commands/kill_op.cpp b/src/mongo/db/commands/kill_op.cpp
index 7b07c87f7ba..8cc2754e919 100644
--- a/src/mongo/db/commands/kill_op.cpp
+++ b/src/mongo/db/commands/kill_op.cpp
@@ -55,8 +55,8 @@ public:
return false;
}
- bool slaveOk() const final {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const final {
diff --git a/src/mongo/db/commands/kill_sessions_command.cpp b/src/mongo/db/commands/kill_sessions_command.cpp
index 0be33339f25..55f8dfc1a2d 100644
--- a/src/mongo/db/commands/kill_sessions_command.cpp
+++ b/src/mongo/db/commands/kill_sessions_command.cpp
@@ -84,8 +84,8 @@ class KillSessionsCommand final : public BasicCommand {
public:
KillSessionsCommand() : BasicCommand("killSessions") {}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const override {
return false;
diff --git a/src/mongo/db/commands/killcursors_common.h b/src/mongo/db/commands/killcursors_common.h
index 6991a4a0da7..90541adc709 100644
--- a/src/mongo/db/commands/killcursors_common.h
+++ b/src/mongo/db/commands/killcursors_common.h
@@ -45,8 +45,8 @@ public:
return false;
}
- bool slaveOk() const final {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool maintenanceOk() const final {
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index b21c0f959a1..b92c59034ba 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -197,11 +197,8 @@ BSONObj buildCollectionBson(OperationContext* opCtx,
class CmdListCollections : public BasicCommand {
public:
- virtual bool slaveOk() const {
- return false;
- }
- virtual bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kOptIn;
}
virtual bool adminOnly() const {
return false;
diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp
index f91cb10f680..99bc8166021 100644
--- a/src/mongo/db/commands/list_databases.cpp
+++ b/src/mongo/db/commands/list_databases.cpp
@@ -57,11 +57,8 @@ intmax_t dbSize(const string& database);
class CmdListDatabases : public BasicCommand {
public:
- bool slaveOk() const final {
- return false;
- }
- bool slaveOverrideOk() const final {
- return true;
+ AllowedOnSecondary secondaryAllowed() const final {
+ return AllowedOnSecondary::kOptIn;
}
bool adminOnly() const final {
return true;
diff --git a/src/mongo/db/commands/list_indexes.cpp b/src/mongo/db/commands/list_indexes.cpp
index 5c23ea9f1c6..cef7130a20c 100644
--- a/src/mongo/db/commands/list_indexes.cpp
+++ b/src/mongo/db/commands/list_indexes.cpp
@@ -76,11 +76,8 @@ namespace {
*/
class CmdListIndexes : public BasicCommand {
public:
- virtual bool slaveOk() const {
- return false;
- }
- virtual bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kOptIn;
}
virtual bool adminOnly() const {
return false;
diff --git a/src/mongo/db/commands/lock_info.cpp b/src/mongo/db/commands/lock_info.cpp
index 6bd6aeb3258..3e16e220e39 100644
--- a/src/mongo/db/commands/lock_info.cpp
+++ b/src/mongo/db/commands/lock_info.cpp
@@ -49,12 +49,8 @@ using std::stringstream;
*/
class CmdLockInfo : public BasicCommand {
public:
- virtual bool slaveOk() const {
- return true;
- }
-
- virtual bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool adminOnly() const {
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index ef9043fd78a..ce7d144bfcc 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -1351,13 +1351,12 @@ class MapReduceCommand : public ErrmsgCommandDeprecated {
public:
MapReduceCommand() : ErrmsgCommandDeprecated("mapReduce", "mapreduce") {}
- virtual bool slaveOk() const {
- return repl::getGlobalReplicationCoordinator()->getReplicationMode() !=
- repl::ReplicationCoordinator::modeReplSet;
- }
-
- virtual bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ if (repl::getGlobalReplicationCoordinator()->getReplicationMode() !=
+ repl::ReplicationCoordinator::modeReplSet) {
+ return AllowedOnSecondary::kAlways;
+ }
+ return AllowedOnSecondary::kOptIn;
}
std::size_t reserveBytesForReply() const override {
@@ -1689,13 +1688,15 @@ public:
return "internal";
}
MapReduceFinishCommand() : BasicCommand("mapreduce.shardedfinish") {}
- virtual bool slaveOk() const {
- return repl::getGlobalReplicationCoordinator()->getReplicationMode() !=
- repl::ReplicationCoordinator::modeReplSet;
- }
- virtual bool slaveOverrideOk() const {
- return true;
+
+ AllowedOnSecondary secondaryAllowed() const override {
+ if (repl::getGlobalReplicationCoordinator()->getReplicationMode() !=
+ repl::ReplicationCoordinator::modeReplSet) {
+ return AllowedOnSecondary::kAlways;
+ }
+ return AllowedOnSecondary::kOptIn;
}
+
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
}
diff --git a/src/mongo/db/commands/oplog_note.cpp b/src/mongo/db/commands/oplog_note.cpp
index 9b26b979ba6..2f1d06b79b5 100644
--- a/src/mongo/db/commands/oplog_note.cpp
+++ b/src/mongo/db/commands/oplog_note.cpp
@@ -87,8 +87,8 @@ class AppendOplogNoteCmd : public BasicCommand {
public:
AppendOplogNoteCmd() : BasicCommand("appendOplogNote") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool adminOnly() const {
diff --git a/src/mongo/db/commands/parallel_collection_scan.cpp b/src/mongo/db/commands/parallel_collection_scan.cpp
index 783e74be716..c9f36a820e4 100644
--- a/src/mongo/db/commands/parallel_collection_scan.cpp
+++ b/src/mongo/db/commands/parallel_collection_scan.cpp
@@ -62,8 +62,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool supportsReadConcern(const std::string& dbName,
diff --git a/src/mongo/db/commands/parameters.cpp b/src/mongo/db/commands/parameters.cpp
index 7e03b90985b..391a1ffded8 100644
--- a/src/mongo/db/commands/parameters.cpp
+++ b/src/mongo/db/commands/parameters.cpp
@@ -67,8 +67,8 @@ void appendParameterNames(std::string* help) {
class CmdGet : public ErrmsgCommandDeprecated {
public:
CmdGet() : ErrmsgCommandDeprecated("getParameter") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool adminOnly() const {
return true;
@@ -118,8 +118,8 @@ public:
class CmdSet : public ErrmsgCommandDeprecated {
public:
CmdSet() : ErrmsgCommandDeprecated("setParameter") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool adminOnly() const {
return true;
diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp
index 8ec12102c35..ae607f2713f 100644
--- a/src/mongo/db/commands/pipeline_command.cpp
+++ b/src/mongo/db/commands/pipeline_command.cpp
@@ -57,12 +57,8 @@ public:
return Pipeline::aggSupportsWriteConcern(cmd);
}
- bool slaveOk() const override {
- return false;
- }
-
- bool slaveOverrideOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kOptIn;
}
bool supportsReadConcern(const std::string& dbName,
diff --git a/src/mongo/db/commands/plan_cache_commands.cpp b/src/mongo/db/commands/plan_cache_commands.cpp
index 0cd3593f5c1..a76100a90c7 100644
--- a/src/mongo/db/commands/plan_cache_commands.cpp
+++ b/src/mongo/db/commands/plan_cache_commands.cpp
@@ -124,12 +124,8 @@ bool PlanCacheCommand::supportsWriteConcern(const BSONObj& cmd) const {
return false;
}
-bool PlanCacheCommand::slaveOk() const {
- return false;
-}
-
-bool PlanCacheCommand::slaveOverrideOk() const {
- return true;
+Command::AllowedOnSecondary PlanCacheCommand::secondaryAllowed() const {
+ return AllowedOnSecondary::kOptIn;
}
std::string PlanCacheCommand::help() const {
diff --git a/src/mongo/db/commands/plan_cache_commands.h b/src/mongo/db/commands/plan_cache_commands.h
index 0b0a680b2da..c883a189820 100644
--- a/src/mongo/db/commands/plan_cache_commands.h
+++ b/src/mongo/db/commands/plan_cache_commands.h
@@ -64,9 +64,7 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override;
- virtual bool slaveOk() const;
-
- virtual bool slaveOverrideOk() const;
+ AllowedOnSecondary secondaryAllowed() const override;
std::string help() const override;
diff --git a/src/mongo/db/commands/reap_logical_session_cache_now.cpp b/src/mongo/db/commands/reap_logical_session_cache_now.cpp
index 879952791fc..f04ee086359 100644
--- a/src/mongo/db/commands/reap_logical_session_cache_now.cpp
+++ b/src/mongo/db/commands/reap_logical_session_cache_now.cpp
@@ -44,8 +44,8 @@ class ReapLogicalSessionCacheNowCommand final : public BasicCommand {
public:
ReapLogicalSessionCacheNowCommand() : BasicCommand("reapLogicalSessionCacheNow") {}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const override {
diff --git a/src/mongo/db/commands/refresh_logical_session_cache_now.cpp b/src/mongo/db/commands/refresh_logical_session_cache_now.cpp
index 5dcbe213eaa..ff3e018eede 100644
--- a/src/mongo/db/commands/refresh_logical_session_cache_now.cpp
+++ b/src/mongo/db/commands/refresh_logical_session_cache_now.cpp
@@ -45,8 +45,8 @@ class RefreshLogicalSessionCacheNowCommand final : public BasicCommand {
public:
RefreshLogicalSessionCacheNowCommand() : BasicCommand("refreshLogicalSessionCacheNow") {}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const override {
diff --git a/src/mongo/db/commands/refresh_sessions_command.cpp b/src/mongo/db/commands/refresh_sessions_command.cpp
index 4db76567261..0570821ca1e 100644
--- a/src/mongo/db/commands/refresh_sessions_command.cpp
+++ b/src/mongo/db/commands/refresh_sessions_command.cpp
@@ -46,8 +46,8 @@ class RefreshSessionsCommand final : public BasicCommand {
public:
RefreshSessionsCommand() : BasicCommand("refreshSessions") {}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const override {
return false;
diff --git a/src/mongo/db/commands/refresh_sessions_command_internal.cpp b/src/mongo/db/commands/refresh_sessions_command_internal.cpp
index 1cfbf7deeb0..fa52de2caec 100644
--- a/src/mongo/db/commands/refresh_sessions_command_internal.cpp
+++ b/src/mongo/db/commands/refresh_sessions_command_internal.cpp
@@ -46,8 +46,8 @@ class RefreshSessionsCommandInternal final : public BasicCommand {
public:
RefreshSessionsCommandInternal() : BasicCommand("refreshSessionsInternal") {}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const override {
return false;
diff --git a/src/mongo/db/commands/rename_collection_cmd.cpp b/src/mongo/db/commands/rename_collection_cmd.cpp
index 144ecbf847e..01cba8c386a 100644
--- a/src/mongo/db/commands/rename_collection_cmd.cpp
+++ b/src/mongo/db/commands/rename_collection_cmd.cpp
@@ -62,8 +62,8 @@ public:
virtual bool adminOnly() const {
return true;
}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
diff --git a/src/mongo/db/commands/repair_cursor.cpp b/src/mongo/db/commands/repair_cursor.cpp
index 51567abbabc..12c4cfa3528 100644
--- a/src/mongo/db/commands/repair_cursor.cpp
+++ b/src/mongo/db/commands/repair_cursor.cpp
@@ -52,8 +52,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual Status checkAuthForCommand(Client* client,
diff --git a/src/mongo/db/commands/resize_oplog.cpp b/src/mongo/db/commands/resize_oplog.cpp
index 4373c9c9dd5..ef853e9bb17 100644
--- a/src/mongo/db/commands/resize_oplog.cpp
+++ b/src/mongo/db/commands/resize_oplog.cpp
@@ -54,8 +54,8 @@ class CmdReplSetResizeOplog : public BasicCommand {
public:
CmdReplSetResizeOplog() : BasicCommand("replSetResizeOplog") {}
- virtual bool slaveOk() const final {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const final {
diff --git a/src/mongo/db/commands/restart_catalog_command.cpp b/src/mongo/db/commands/restart_catalog_command.cpp
index 6fb51d4fe56..ff722516cd9 100644
--- a/src/mongo/db/commands/restart_catalog_command.cpp
+++ b/src/mongo/db/commands/restart_catalog_command.cpp
@@ -66,8 +66,8 @@ public:
return false;
}
- bool slaveOk() const final {
- return true;
+ AllowedOnSecondary secondaryAllowed() const final {
+ return AllowedOnSecondary::kAlways;
}
bool supportsWriteConcern(const BSONObj& cmd) const final {
diff --git a/src/mongo/db/commands/server_status.cpp b/src/mongo/db/commands/server_status.cpp
index a4b63e778f2..98aefce2f62 100644
--- a/src/mongo/db/commands/server_status.cpp
+++ b/src/mongo/db/commands/server_status.cpp
@@ -72,8 +72,8 @@ public:
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool allowsAfterClusterTime(const BSONObj& cmdObj) const override {
return false;
diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
index 31e28b6a5b5..b4f58018eaa 100644
--- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
+++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
@@ -69,8 +69,8 @@ public:
SetFeatureCompatibilityVersionCommand()
: BasicCommand(FeatureCompatibilityVersion::kCommandName) {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool adminOnly() const {
diff --git a/src/mongo/db/commands/shutdown.h b/src/mongo/db/commands/shutdown.h
index 655d25b367f..e89aa301261 100644
--- a/src/mongo/db/commands/shutdown.h
+++ b/src/mongo/db/commands/shutdown.h
@@ -48,8 +48,8 @@ public:
virtual bool localHostOnlyIfNoAuth() {
return true;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual void addRequiredPrivileges(const std::string& dbname,
const BSONObj& cmdObj,
diff --git a/src/mongo/db/commands/snapshot_management.cpp b/src/mongo/db/commands/snapshot_management.cpp
index 3661447d224..096cdbf2582 100644
--- a/src/mongo/db/commands/snapshot_management.cpp
+++ b/src/mongo/db/commands/snapshot_management.cpp
@@ -44,8 +44,8 @@ class CmdMakeSnapshot final : public BasicCommand {
public:
CmdMakeSnapshot() : BasicCommand("makeSnapshot") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
@@ -92,8 +92,8 @@ class CmdSetCommittedSnapshot final : public BasicCommand {
public:
CmdSetCommittedSnapshot() : BasicCommand("setCommittedSnapshot") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return false;
diff --git a/src/mongo/db/commands/start_session_command.cpp b/src/mongo/db/commands/start_session_command.cpp
index b621ca02237..a577cc01cb7 100644
--- a/src/mongo/db/commands/start_session_command.cpp
+++ b/src/mongo/db/commands/start_session_command.cpp
@@ -51,8 +51,8 @@ class StartSessionCommand final : public BasicCommand {
public:
StartSessionCommand() : BasicCommand("startSession") {}
- bool slaveOk() const override {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
bool adminOnly() const override {
return false;
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp
index 1615117783e..c7c7c5db1a4 100644
--- a/src/mongo/db/commands/test_commands.cpp
+++ b/src/mongo/db/commands/test_commands.cpp
@@ -62,8 +62,8 @@ public:
virtual bool adminOnly() const {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
@@ -118,8 +118,8 @@ public:
return true;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
std::string help() const override {
@@ -201,8 +201,8 @@ public:
class CapTrunc : public BasicCommand {
public:
CapTrunc() : BasicCommand("captrunc") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
@@ -276,8 +276,8 @@ public:
class EmptyCapped : public BasicCommand {
public:
EmptyCapped() : BasicCommand("emptycapped") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
return true;
diff --git a/src/mongo/db/commands/top_command.cpp b/src/mongo/db/commands/top_command.cpp
index 241c44e5702..d7691005285 100644
--- a/src/mongo/db/commands/top_command.cpp
+++ b/src/mongo/db/commands/top_command.cpp
@@ -46,8 +46,8 @@ class TopCommand : public BasicCommand {
public:
TopCommand() : BasicCommand("top") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool adminOnly() const {
return true;
diff --git a/src/mongo/db/commands/touch.cpp b/src/mongo/db/commands/touch.cpp
index d9c2651f34d..2423c3ae6bd 100644
--- a/src/mongo/db/commands/touch.cpp
+++ b/src/mongo/db/commands/touch.cpp
@@ -61,8 +61,8 @@ public:
virtual bool adminOnly() const {
return false;
}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool maintenanceMode() const {
return true;
diff --git a/src/mongo/db/commands/user_management_commands.cpp b/src/mongo/db/commands/user_management_commands.cpp
index 9ccf077f479..7aafdce777b 100644
--- a/src/mongo/db/commands/user_management_commands.cpp
+++ b/src/mongo/db/commands/user_management_commands.cpp
@@ -611,8 +611,8 @@ class CmdCreateUser : public BasicCommand {
public:
CmdCreateUser() : BasicCommand("createUser") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -758,8 +758,8 @@ class CmdUpdateUser : public BasicCommand {
public:
CmdUpdateUser() : BasicCommand("updateUser") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -892,8 +892,8 @@ class CmdDropUser : public BasicCommand {
public:
CmdDropUser() : BasicCommand("dropUser") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -959,8 +959,8 @@ class CmdDropAllUsersFromDatabase : public BasicCommand {
public:
CmdDropAllUsersFromDatabase() : BasicCommand("dropAllUsersFromDatabase") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1015,8 +1015,8 @@ class CmdGrantRolesToUser : public BasicCommand {
public:
CmdGrantRolesToUser() : BasicCommand("grantRolesToUser") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1087,8 +1087,8 @@ class CmdRevokeRolesFromUser : public BasicCommand {
public:
CmdRevokeRolesFromUser() : BasicCommand("revokeRolesFromUser") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1157,12 +1157,8 @@ public:
class CmdUsersInfo : public BasicCommand {
public:
- virtual bool slaveOk() const {
- return false;
- }
-
- virtual bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kOptIn;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1285,8 +1281,8 @@ class CmdCreateRole : public BasicCommand {
public:
CmdCreateRole() : BasicCommand("createRole") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1406,8 +1402,8 @@ class CmdUpdateRole : public BasicCommand {
public:
CmdUpdateRole() : BasicCommand("updateRole") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1523,8 +1519,8 @@ class CmdGrantPrivilegesToRole : public BasicCommand {
public:
CmdGrantPrivilegesToRole() : BasicCommand("grantPrivilegesToRole") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1633,8 +1629,8 @@ class CmdRevokePrivilegesFromRole : public BasicCommand {
public:
CmdRevokePrivilegesFromRole() : BasicCommand("revokePrivilegesFromRole") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1745,8 +1741,8 @@ class CmdGrantRolesToRole : public BasicCommand {
public:
CmdGrantRolesToRole() : BasicCommand("grantRolesToRole") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1834,8 +1830,8 @@ class CmdRevokeRolesFromRole : public BasicCommand {
public:
CmdRevokeRolesFromRole() : BasicCommand("revokeRolesFromRole") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -1918,8 +1914,8 @@ class CmdDropRole : public BasicCommand {
public:
CmdDropRole() : BasicCommand("dropRole") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -2060,8 +2056,8 @@ class CmdDropAllRolesFromDatabase : public BasicCommand {
public:
CmdDropAllRolesFromDatabase() : BasicCommand("dropAllRolesFromDatabase") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -2191,12 +2187,8 @@ public:
class CmdRolesInfo : public BasicCommand {
public:
- virtual bool slaveOk() const {
- return false;
- }
-
- virtual bool slaveOverrideOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kOptIn;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
@@ -2280,8 +2272,8 @@ public:
class CmdInvalidateUserCache : public BasicCommand {
public:
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool adminOnly() const {
@@ -2317,8 +2309,8 @@ public:
class CmdGetCacheGeneration : public BasicCommand {
public:
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
virtual bool adminOnly() const {
@@ -2366,8 +2358,8 @@ class CmdMergeAuthzCollections : public BasicCommand {
public:
CmdMergeAuthzCollections() : BasicCommand("_mergeAuthzCollections") {}
- virtual bool slaveOk() const {
- return false;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kNever;
}
virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
diff --git a/src/mongo/db/commands/validate.cpp b/src/mongo/db/commands/validate.cpp
index f3d04650286..1ef643d87cf 100644
--- a/src/mongo/db/commands/validate.cpp
+++ b/src/mongo/db/commands/validate.cpp
@@ -67,8 +67,8 @@ class ValidateCmd : public BasicCommand {
public:
ValidateCmd() : BasicCommand("validate") {}
- virtual bool slaveOk() const {
- return true;
+ AllowedOnSecondary secondaryAllowed() const override {
+ return AllowedOnSecondary::kAlways;
}
std::string help() const override {
diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp
index 922c5a57652..ac0a73dee89 100644
--- a/src/mongo/db/commands/write_commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands/write_commands.cpp
@@ -198,8 +198,8 @@ class WriteCommand : public Command {
public:
explicit WriteCommand(StringData name) : Command(name) {}
- bool slaveOk() const final {
- return false;
+ AllowedOnSecondary secondaryAllowed() const final {
+ return AllowedOnSecondary::kNever;
}
bool shouldAffectCommandCounter() const final {