diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2018-01-30 19:40:46 -0500 |
---|---|---|
committer | Billy Donahue <billy.donahue@mongodb.com> | 2018-01-31 14:04:35 -0500 |
commit | be24b0323d3f2d424d9e22337f4221d39001ac31 (patch) | |
tree | 98577c05a24da852ec518699c4d039da5bbd7329 /src/mongo/db/commands/explain_cmd.cpp | |
parent | 0322da76ec976d240191b1ca8f70c2c732f9753a (diff) | |
download | mongo-be24b0323d3f2d424d9e22337f4221d39001ac31.tar.gz |
SERVER-32958 slaveOk,slaveOverrideOk replacement
declare read_preference dep. update service_entry_opint_embedded
Diffstat (limited to 'src/mongo/db/commands/explain_cmd.cpp')
-rw-r--r-- | src/mongo/db/commands/explain_cmd.cpp | 25 |
1 files changed, 4 insertions, 21 deletions
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?"; |