From 3105cafb4d712deb5cef0b6b12f137b14d2dee33 Mon Sep 17 00:00:00 2001 From: Eric Milkie Date: Mon, 28 Nov 2016 14:51:04 -0500 Subject: SERVER-27164 do not upgrade dblock for replication, to avoid deadlock (cherry picked from commit e876419bebadd6468c402e85e1fcf6eff5a374d4) --- src/mongo/db/repl/sync_tail.cpp | 12 +++++++++--- 1 file 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; } -- cgit v1.2.1