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 12:06:20 -0500
commitedc5989d36f6dea86ffe034c414e97e98549004e (patch)
treee0e5ba626f7ac74bd9fac245087c503679c74f1a
parent54dfb6df908be81c50587a854964551ad72110cc (diff)
downloadmongo-edc5989d36f6dea86ffe034c414e97e98549004e.tar.gz
SERVER-21583 applyOperation_inlock builds background indexes in foreground if temp release fails
-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 6cdc8fdc01d..0837c9177e0 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -734,12 +734,21 @@ Status applyOperation_inlock(OperationContext* txn,
if (nsToCollectionSubstring(ns) == "system.indexes") {
opCounters->gotInsert();
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);