summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2015-05-19 16:04:20 -0400
committerJason Rassi <rassi@10gen.com>2015-05-21 13:36:12 -0400
commit365f1d98a600472c1494e69ad0c2bf5f102df8da (patch)
tree0394794c2950d4844446420edcd95c1ddda1cd39
parent42140e7002960ef23227e78289ed07a43ea4d14e (diff)
downloadmongo-365f1d98a600472c1494e69ad0c2bf5f102df8da.tar.gz
SERVER-18566 findAndModify: re-check for primary before upsert
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index 5399595d76b..611faf6d5d7 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -430,6 +430,20 @@ namespace mongo {
&newDoc));
}
+ // Return an error if the primary stepped down while our PlanExecutor was
+ // yielding locks. update() and deleteObjects() check this for us in the
+ // update and delete cases, respectively, but we need to perform an explicit
+ // check here for the upsert case.
+ if (!repl::getGlobalReplicationCoordinator()
+ ->canAcceptWritesForDatabase(dbname)) {
+ return appendCommandStatus(result,
+ Status(ErrorCodes::NotMaster,
+ str::stream()
+ << "Stepped down from primary "
+ << "while running findAndModify "
+ << "in " << ns));
+ }
+
const bool enforceQuota = true;
uassertStatusOK(collection->insertDocument(txn, newDoc, enforceQuota)
.getStatus());