summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/apply_ops.cpp
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2019-03-04 09:28:06 -0500
committerEric Milkie <milkie@10gen.com>2019-03-08 12:19:56 -0500
commit77742598f84ab1137514ae13824f7afa2c1e9804 (patch)
treed6ac67c6f05235b008ef4037ba323e532176b2b8 /src/mongo/db/repl/apply_ops.cpp
parent7f620154e595d2c1e6c7af79fc62070ced3bb941 (diff)
downloadmongo-77742598f84ab1137514ae13824f7afa2c1e9804.tar.gz
SERVER-38588 block application of prepare oplog entry on secondaries when a concurrent background index build is running
This will prevent hybrid index builds from corrupting an index on secondary nodes if a prepared transaction becomes prepared during a build but commits after the index build commits.
Diffstat (limited to 'src/mongo/db/repl/apply_ops.cpp')
-rw-r--r--src/mongo/db/repl/apply_ops.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/db/repl/apply_ops.cpp b/src/mongo/db/repl/apply_ops.cpp
index 8c3bea492b3..82c5717eb8a 100644
--- a/src/mongo/db/repl/apply_ops.cpp
+++ b/src/mongo/db/repl/apply_ops.cpp
@@ -34,6 +34,7 @@
#include "mongo/db/repl/apply_ops.h"
#include "mongo/bson/util/bson_extract.h"
+#include "mongo/db/background.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_holder.h"
@@ -290,6 +291,18 @@ Status _applyPrepareTransaction(OperationContext* opCtx,
"applyOps with prepared must only include CRUD operations and cannot have precondition.",
!info.getPreCondition() && info.areOpsCrudOnly());
+ // Block application of prepare oplog entry on secondaries when a concurrent background index
+ // build is running.
+ // This will prevent hybrid index builds from corrupting an index on secondary nodes if a
+ // prepared transaction becomes prepared during a build but commits after the index build
+ // commits.
+ for (const auto& opObj : info.getOperations()) {
+ auto ns = opObj.getField("ns").checkAndGetStringData();
+ if (BackgroundOperation::inProgForNs(ns)) {
+ BackgroundOperation::awaitNoBgOpInProgForNs(ns);
+ }
+ }
+
// Transaction operations are in its own batch, so we can modify their opCtx.
invariant(entry.getSessionId());
invariant(entry.getTxnNumber());