diff options
author | Benety Goh <benety@mongodb.com> | 2015-02-03 17:13:01 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2015-02-05 00:18:34 -0500 |
commit | 1e58c0374677a37c09438aa8c21d745cd5b08468 (patch) | |
tree | 805eb3c064b76e2612cbd3fe7e90032f380a08e9 /src/mongo/db/ops/update.cpp | |
parent | 5ee9c2eafe66f72c1f5d28a764bd729aa24be472 (diff) | |
download | mongo-1e58c0374677a37c09438aa8c21d745cd5b08468.tar.gz |
SERVER-15308 SERVER-17150 cancel current command on the primary when the node is stepped down
Diffstat (limited to 'src/mongo/db/ops/update.cpp')
-rw-r--r-- | src/mongo/db/ops/update.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/mongo/db/ops/update.cpp b/src/mongo/db/ops/update.cpp index e4a008b3b06..9aeb9946a45 100644 --- a/src/mongo/db/ops/update.cpp +++ b/src/mongo/db/ops/update.cpp @@ -46,6 +46,7 @@ #include "mongo/db/query/explain.h" #include "mongo/db/query/get_executor.h" #include "mongo/db/repl/oplog.h" +#include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/update_index_data.h" #include "mongo/util/log.h" @@ -76,6 +77,14 @@ namespace mongo { ScopedTransaction transaction(txn, MODE_IX); Lock::DBLock lk(txn->lockState(), nsString.db(), MODE_X); + if (!request.isFromReplication() && + !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase( + nsString.db())) { + uassertStatusOK(Status(ErrorCodes::NotMaster, str::stream() + << "Not primary while creating collection " << nsString.ns() + << " during upsert")); + } + WriteUnitOfWork wuow(txn); collection = db->createCollection(txn, nsString.ns()); invariant(collection); |