summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/mr.cpp
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2017-03-15 17:14:53 -0400
committerSpencer T Brody <spencer@mongodb.com>2017-03-21 18:12:23 -0400
commit7cd3934080fcf0a14e8133074cd77598285126a1 (patch)
treec14a0865e1fe93e9192807123f316ec87a5680a0 /src/mongo/db/commands/mr.cpp
parent6b50dfdb11392709c2dd0462098e3793e962ce78 (diff)
downloadmongo-7cd3934080fcf0a14e8133074cd77598285126a1.tar.gz
SERVER-27892 Don't call canAcceptWritesFor in mapReduce until after grabing locks
Diffstat (limited to 'src/mongo/db/commands/mr.cpp')
-rw-r--r--src/mongo/db/commands/mr.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index ffeecffaca5..50e6edc44a5 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -1436,15 +1436,6 @@ public:
Status(ErrorCodes::NamespaceNotFound,
str::stream() << "namespace does not exist: " << config.nss.ns()));
}
- if (state.isOnDisk()) {
- // this means that it will be doing a write operation, make sure we are on Master
- // ideally this check should be in slaveOk(), but at that point config is not known
- if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesFor_UNSAFE(opCtx,
- config.nss)) {
- errmsg = "not master";
- return false;
- }
- }
try {
state.init();
@@ -1485,6 +1476,16 @@ public:
// Need lock and context to use it
unique_ptr<AutoGetDb> scopedAutoDb(new AutoGetDb(opCtx, config.nss.db(), MODE_S));
+ if (state.isOnDisk()) {
+ // this means that it will be doing a write operation, make sure it is safe to
+ // do so.
+ if (!repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(opCtx,
+ config.nss)) {
+ uasserted(ErrorCodes::NotMaster, "not master");
+ return false;
+ }
+ }
+
auto qr = stdx::make_unique<QueryRequest>(config.nss);
qr->setFilter(config.filter);
qr->setSort(config.sort);