diff options
author | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2018-10-25 18:07:09 -0400 |
---|---|---|
committer | Xiangyu Yao <xiangyu.yao@mongodb.com> | 2018-10-25 18:07:21 -0400 |
commit | dd4c4c1043f3e20618e536f96d4237691bfedd2f (patch) | |
tree | 67b2dadf98952f561e31612519452da245622de0 | |
parent | 373dc8e89ec8a6dfabe003c9c9711caa5ee5b45d (diff) | |
download | mongo-dd4c4c1043f3e20618e536f96d4237691bfedd2f.tar.gz |
Revert "SERVER-37313 Secondary foreground index build should take Database X rather than Global X lock"
This reverts commit 3aebbb51ed5fe82601f601916251c5f892a59467.
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/repl/sync_tail.cpp | 8 |
2 files changed, 5 insertions, 13 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 94477d111d8..2ad84d776e9 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -231,11 +231,6 @@ void createIndexForApplyOps(OperationContext* opCtx, const NamespaceString& indexNss, IncrementOpsAppliedStatsFn incrementOpsAppliedStats, OplogApplication::Mode mode) { - // Lock the database if it's not locked. - boost::optional<Lock::DBLock> dbLock; - if (!opCtx->lockState()->isDbLockedForMode(indexNss.db(), MODE_X)) { - dbLock.emplace(opCtx, indexNss.db(), MODE_X); - } // Check if collection exists. Database* db = DatabaseHolder::getDatabaseHolder().get(opCtx, indexNss.ns()); auto indexCollection = db ? db->getCollection(opCtx, indexNss) : nullptr; @@ -1530,7 +1525,6 @@ Status applyCommand_inlock(OperationContext* opCtx, return {ErrorCodes::InvalidNamespace, "invalid ns: " + std::string(nss.ns())}; } { - Lock::DBLock lock(opCtx, nss.db(), MODE_IS); Database* db = DatabaseHolder::getDatabaseHolder().get(opCtx, nss.ns()); if (db && !db->getCollection(opCtx, nss) && db->getViewCatalog()->lookup(opCtx, nss.ns())) { return {ErrorCodes::CommandNotSupportedOnView, @@ -1555,6 +1549,10 @@ Status applyCommand_inlock(OperationContext* opCtx, << redact(op)); } + // Applying commands in repl is done under Global W-lock, so it is safe to not + // perform the current DB checks after reacquiring the lock. + invariant(opCtx->lockState()->isW()); + // Parse optime from oplog entry unless we are applying this command in standalone or on a // primary (replicated writes enabled). OpTime opTime; diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp index b611f8b8305..0356a80e1d9 100644 --- a/src/mongo/db/repl/sync_tail.cpp +++ b/src/mongo/db/repl/sync_tail.cpp @@ -387,13 +387,7 @@ Status SyncTail::syncApply(OperationContext* opCtx, return writeConflictRetry(opCtx, "syncApply_command", nss.ns(), [&] { // a command may need a global write lock. so we will conservatively go // ahead and grab one here. suboptimal. :-( - boost::optional<Lock::GlobalWrite> globalWriteLock; - - const StringData commandName(op["o"].embeddedObject().firstElementFieldName()); - // SERVER-37313: createIndex does not need to take the Global X lock. - if (commandName != "createIndexes") { - globalWriteLock.emplace(opCtx); - } + Lock::GlobalWrite globalWriteLock(opCtx); // special case apply for commands to avoid implicit database creation Status status = applyCommand_inlock(opCtx, op, oplogApplicationMode); |