summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/update.cpp
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2015-04-23 09:17:57 -0400
committerScott Hernandez <scotthernandez@gmail.com>2015-04-23 14:44:08 -0400
commit57232d88b869b0741d95998f8ed09a96b2e7a1bc (patch)
treec00ae7d21304389cfbdb31d1abfa6daed6e08dda /src/mongo/db/ops/update.cpp
parent623d5413c322136d75c43c8d48f58b19761b3709 (diff)
downloadmongo-57232d88b869b0741d95998f8ed09a96b2e7a1bc.tar.gz
SERVER-17689: handle wce better in initial sync
Diffstat (limited to 'src/mongo/db/ops/update.cpp')
-rw-r--r--src/mongo/db/ops/update.cpp36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/mongo/db/ops/update.cpp b/src/mongo/db/ops/update.cpp
index ffdc244e42c..ab2a48a72fb 100644
--- a/src/mongo/db/ops/update.cpp
+++ b/src/mongo/db/ops/update.cpp
@@ -40,6 +40,7 @@
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/clientcursor.h"
#include "mongo/db/concurrency/d_concurrency.h"
+#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/exec/update.h"
#include "mongo/db/operation_context_impl.h"
#include "mongo/db/op_observer.h"
@@ -75,23 +76,24 @@ namespace mongo {
locker->isLockHeldForMode(ResourceId(RESOURCE_DATABASE, nsString.db()),
MODE_X));
- ScopedTransaction transaction(txn, MODE_IX);
- Lock::DBLock lk(txn->lockState(), nsString.db(), MODE_X);
-
- bool userInitiatedWritesAndNotPrimary = txn->writesAreReplicated() &&
- !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(nsString.db());
-
- if (userInitiatedWritesAndNotPrimary) {
- uassertStatusOK(Status(ErrorCodes::NotMaster, str::stream()
- << "Not primary while creating collection " << nsString.ns()
- << " during upsert"));
- }
-
- WriteUnitOfWork wuow(txn);
- collection = db->createCollection(txn, nsString.ns(), CollectionOptions());
- invariant(collection);
-
- wuow.commit();
+ MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
+ ScopedTransaction transaction(txn, MODE_IX);
+ Lock::DBLock lk(txn->lockState(), nsString.db(), MODE_X);
+
+ const bool userInitiatedWritesAndNotPrimary = txn->writesAreReplicated() &&
+ !repl::getGlobalReplicationCoordinator()->canAcceptWritesForDatabase(
+ nsString.db());
+
+ if (userInitiatedWritesAndNotPrimary) {
+ uassertStatusOK(Status(ErrorCodes::NotMaster, str::stream()
+ << "Not primary while creating collection " << nsString.ns()
+ << " during upsert"));
+ }
+ WriteUnitOfWork wuow(txn);
+ collection = db->createCollection(txn, nsString.ns(), CollectionOptions());
+ invariant(collection);
+ wuow.commit();
+ } MONGO_WRITE_CONFLICT_RETRY_LOOP_END(txn, "createCollection", nsString.ns());
}
// Parse the update, get an executor for it, run the executor, get stats out.