summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/haystack.cpp
diff options
context:
space:
mode:
authorWilliam Schultz <william.schultz@mongodb.com>2018-05-02 13:23:13 -0400
committerWilliam Schultz <william.schultz@mongodb.com>2018-05-02 13:23:13 -0400
commite8fe32029aded4d0e909f531196edff43c96cfff (patch)
treed9f4e02e7ad6fc9e07083908761ae230c9ab4b34 /src/mongo/db/commands/haystack.cpp
parentbbe227d11d937088f832c5e485f16621d4251966 (diff)
downloadmongo-e8fe32029aded4d0e909f531196edff43c96cfff.tar.gz
SERVER-34557 Restrict transactions to only run against replica set primaries
Diffstat (limited to 'src/mongo/db/commands/haystack.cpp')
-rw-r--r--src/mongo/db/commands/haystack.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/mongo/db/commands/haystack.cpp b/src/mongo/db/commands/haystack.cpp
index 695e8f90a6f..6b67b468de7 100644
--- a/src/mongo/db/commands/haystack.cpp
+++ b/src/mongo/db/commands/haystack.cpp
@@ -103,6 +103,11 @@ public:
AutoGetCollectionForReadCommand ctx(opCtx, nss);
+ // Check whether we are allowed to read from this node after acquiring our locks.
+ auto replCoord = repl::ReplicationCoordinator::get(opCtx);
+ uassertStatusOK(replCoord->checkCanServeReadsFor(
+ opCtx, nss, ReadPreferenceSetting::get(opCtx).canRunOnSecondary()));
+
Collection* collection = ctx.getCollection();
if (!collection) {
errmsg = "can't find ns";