summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2016-11-28 14:51:04 -0500
committerBenety Goh <benety@mongodb.com>2017-02-15 16:41:30 -0500
commit3105cafb4d712deb5cef0b6b12f137b14d2dee33 (patch)
tree8fd2a6e327a6f495675e75b0cd010c064a2e7ff8
parent99ab9a6e264939397d134378a70f500b54e91a23 (diff)
downloadmongo-3105cafb4d712deb5cef0b6b12f137b14d2dee33.tar.gz
SERVER-27164 do not upgrade dblock for replication, to avoid deadlock
(cherry picked from commit e876419bebadd6468c402e85e1fcf6eff5a374d4)
-rw-r--r--src/mongo/db/repl/sync_tail.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp
index b267e37ad43..d7620d822c1 100644
--- a/src/mongo/db/repl/sync_tail.cpp
+++ b/src/mongo/db/repl/sync_tail.cpp
@@ -158,14 +158,20 @@ bool SyncTail::syncApply(OperationContext* txn, const BSONObj& op, bool convertU
// ahead and grab one here. suboptimal. :-(
globalWriteLock.reset(new Lock::GlobalWrite(txn->lockState()));
} else if (isIndexBuild) {
+ // Warning: We must reset the pointer to nullptr first, in order to ensure that we
+ // drop the DB lock before acquiring the upgraded one.
+ dbLock.reset();
dbLock.reset(new Lock::DBLock(txn->lockState(), nsToDatabaseSubstring(ns), MODE_X));
} else if (isCrudOpType(opType)) {
+ // Warning: We must reset the pointer to nullptr first, in order to ensure that we
+ // drop the DB lock before acquiring the upgraded one.
+ dbLock.reset();
LockMode mode = createCollection ? MODE_X : MODE_IX;
dbLock.reset(new Lock::DBLock(txn->lockState(), nsToDatabaseSubstring(ns), mode));
collectionLock.reset(new Lock::CollectionLock(txn->lockState(), ns, mode));
if (!createCollection && !dbHolder().get(txn, nsToDatabaseSubstring(ns))) {
- // need to create database, try again
+ // Need to create database, so reset lock to stronger mode.
continue;
}
} else {
@@ -177,8 +183,8 @@ bool SyncTail::syncApply(OperationContext* txn, const BSONObj& op, bool convertU
if (createCollection == 0 && !isIndexBuild && isCrudOpType(opType) &&
ctx.db()->getCollection(ns) == NULL) {
- // uh, oh, we need to create collection
- // try again
+ // Need to implicitly create collection. This occurs for 'u' opTypes,
+ // but not for 'i' nor 'd'.
continue;
}