summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);
}