summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2018-10-20 20:56:37 -0400
committerXiangyu Yao <xiangyu.yao@mongodb.com>2018-10-23 16:14:14 -0400
commite7bed9bdcb376d5a06dce6228047309e8481f9cf (patch)
treeccbf41dcc12823b2416e6588313e6c656c9e31de /src
parent1fea1df1ee21cac90a2217f219f1ba12244fc4fa (diff)
downloadmongo-e7bed9bdcb376d5a06dce6228047309e8481f9cf.tar.gz
SERVER-37313 Secondary foreground index build should take Database X rather than Global X lock
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/repl/oplog.cpp5
-rw-r--r--src/mongo/db/repl/sync_tail.cpp4
2 files changed, 8 insertions, 1 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index bd41e12bd1e..e2c497de5f7 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -232,6 +232,11 @@ 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()->isLocked()) {
+ 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;
diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp
index e3473ed5626..f5e11dda175 100644
--- a/src/mongo/db/repl/sync_tail.cpp
+++ b/src/mongo/db/repl/sync_tail.cpp
@@ -312,7 +312,9 @@ Status SyncTail::syncApply(OperationContext* opCtx,
// The command entry has been parsed before, so it must be valid.
auto entry = uassertStatusOK(OplogEntry::parse(op));
const StringData commandName(op["o"].embeddedObject().firstElementFieldName());
- if (!op.getBoolField("prepare") && commandName != "abortTransaction") {
+ // SERVER-37313: createIndex does not need to take the Global X lock.
+ if (!op.getBoolField("prepare") && commandName != "abortTransaction" &&
+ commandName != "createIndexes") {
globalWriteLock.emplace(opCtx);
}