summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/explain_cmd.cpp
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 /src/mongo/db/commands/explain_cmd.cpp
parentbe24b0323d3f2d424d9e22337f4221d39001ac31 (diff)
downloadmongo-d75cb425fbc3cf4b569eb1722c3f8abec45654a2.tar.gz
Revert "SERVER-32958 slaveOk,slaveOverrideOk replacement"
This reverts commit be24b0323d3f2d424d9e22337f4221d39001ac31.
Diffstat (limited to 'src/mongo/db/commands/explain_cmd.cpp')
-rw-r--r--src/mongo/db/commands/explain_cmd.cpp25
1 files changed, 21 insertions, 4 deletions
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?";