summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2016-01-05 16:13:22 -0500
committerBenety Goh <benety@mongodb.com>2016-01-07 15:11:47 -0500
commit95933f3bc721ccbcfda98e12ef85f21801add565 (patch)
tree99205e88fa7bfd3073e523f1503dab3c3fd4fdd0
parent0636cc5de3485479edc98ce383ff8b512bfe118d (diff)
downloadmongo-95933f3bc721ccbcfda98e12ef85f21801add565.tar.gz
SERVER-21583 applyOperation_inlock builds background indexes in foreground if temp release fails
(cherry picked from commit edc5989d36f6dea86ffe034c414e97e98549004e)
-rw-r--r--src/mongo/db/repl/oplog.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index dbf1e83d24a..d33a9814f9c 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -634,12 +634,21 @@ bool applyOperation_inlock(OperationContext* txn,
const char* p = strchr(ns, '.');
if (p && nsToCollectionSubstring(p) == "system.indexes") {
if (o["background"].trueValue()) {
- IndexBuilder* builder = new IndexBuilder(o);
- // This spawns a new thread and returns immediately.
- builder->go();
- // Wait for thread to start and register itself
Lock::TempRelease release(txn->lockState());
- IndexBuilder::waitForBgIndexStarting();
+ if (txn->lockState()->isLocked()) {
+ // If TempRelease fails, background index build will deadlock.
+ LOG(3) << "apply op: building background index " << o
+ << " in the foreground because temp release failed";
+ IndexBuilder builder(o);
+ Status status = builder.buildInForeground(txn, db);
+ uassertStatusOK(status);
+ } else {
+ IndexBuilder* builder = new IndexBuilder(o);
+ // This spawns a new thread and returns immediately.
+ builder->go();
+ // Wait for thread to start and register itself
+ IndexBuilder::waitForBgIndexStarting();
+ }
} else {
IndexBuilder builder(o);
Status status = builder.buildInForeground(txn, db);