diff options
author | Jason Rassi <rassi@10gen.com> | 2015-05-19 16:04:20 -0400 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2015-05-21 13:36:12 -0400 |
commit | 365f1d98a600472c1494e69ad0c2bf5f102df8da (patch) | |
tree | 0394794c2950d4844446420edcd95c1ddda1cd39 | |
parent | 42140e7002960ef23227e78289ed07a43ea4d14e (diff) | |
download | mongo-365f1d98a600472c1494e69ad0c2bf5f102df8da.tar.gz |
SERVER-18566 findAndModify: re-check for primary before upsert
-rw-r--r-- | src/mongo/db/commands/find_and_modify.cpp | 14 |
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()); |