summaryrefslogtreecommitdiff
path: root/src/mongo/client/embedded/service_entry_point_embedded.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/client/embedded/service_entry_point_embedded.cpp')
-rw-r--r--src/mongo/client/embedded/service_entry_point_embedded.cpp22
1 files changed, 13 insertions, 9 deletions
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);
}
}