summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2019-10-27 17:42:41 +0000
committerevergreen <evergreen@mongodb.com>2019-10-27 17:42:41 +0000
commit80c13a3f72d3721ce6de872231170b18c0dc6ff5 (patch)
tree11d998836d03efd618ce5a7197cf9e0331bc896d
parent1613fab5c5b62845c11b7624f9a6c64cad8255b0 (diff)
downloadmongo-80c13a3f72d3721ce6de872231170b18c0dc6ff5.tar.gz
SERVER-44186 index builds use same OperationContext::writesAreReplicated() setting across primaries and secondaries
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp7
-rw-r--r--src/mongo/db/index_builds_coordinator_mongod.cpp17
3 files changed, 8 insertions, 17 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index c0f40eebca9..8305d3dc094 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -765,6 +765,7 @@ env.Library(
'db_raii',
'index_build_entry_helpers',
'$BUILD_DIR/mongo/db/catalog/collection_catalog',
+ '$BUILD_DIR/mongo/db/catalog/index_timestamp_helper',
],
)
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index 4c20962831e..f570d9e3e13 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -37,6 +37,7 @@
#include "mongo/db/catalog/commit_quorum_options.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/index_build_entry_gen.h"
+#include "mongo/db/catalog/index_timestamp_helper.h"
#include "mongo/db/catalog_raii.h"
#include "mongo/db/concurrency/locker.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
@@ -147,6 +148,12 @@ void onCommitIndexBuild(OperationContext* opCtx,
// index builds are not in effect because the index build would be aborted (most likely due
// to a stepdown) before we reach here.
if (replSetAndNotPrimaryAtStart) {
+ // Get a timestamp to complete the index build in the absence of a commitIndexBuild
+ // oplog entry.
+ repl::UnreplicatedWritesBlock uwb(opCtx);
+ if (!IndexTimestampHelper::setGhostCommitTimestampForCatalogWrite(opCtx, nss)) {
+ log() << "Did not timestamp index commit write.";
+ }
return;
}
opObserver->onCommitIndexBuild(opCtx, nss, collUUID, buildUUID, indexSpecs, fromMigrate);
diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp
index 628bb51c5ef..ab382899123 100644
--- a/src/mongo/db/index_builds_coordinator_mongod.cpp
+++ b/src/mongo/db/index_builds_coordinator_mongod.cpp
@@ -130,14 +130,6 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx,
const auto deadline = opCtx->getDeadline();
const auto timeoutError = opCtx->getTimeoutError();
- // TODO: SERVER-39484 Because both 'writesAreReplicated' and
- // 'shouldNotConflictWithSecondaryBatchApplication' depend on the current replication state,
- // just passing the state here is not resilient to member state changes like stepup/stepdown.
-
- // If the calling thread is replicating oplog writes (primary), this state should be passed to
- // the builder.
- const bool writesAreReplicated = opCtx->writesAreReplicated();
-
// Task in thread pool should have similar CurOp representation to the caller so that it can be
// identified as a createIndexes operation.
LogicalOp logicalOp = LogicalOp::opInvalid;
@@ -155,7 +147,6 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx,
indexBuildOptions,
deadline,
timeoutError,
- writesAreReplicated,
logicalOp,
opDesc,
replState
@@ -180,14 +171,6 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx,
opCtx->setDeadlineByDate(deadline, timeoutError);
- // Two phase index builds have to adapt to replication state transitions and decide if it
- // is ok to write to the oplog. Therefore, the caller's replicated writes setting should
- // have no effect on the index build thread.
- boost::optional<repl::UnreplicatedWritesBlock> unreplicatedWrites;
- if (IndexBuildProtocol::kTwoPhase != replState->protocol && !writesAreReplicated) {
- unreplicatedWrites.emplace(opCtx.get());
- }
-
// Index builds should never take the PBWM lock, even on a primary. This allows the index
// to continue running after the node steps down to a secondary.
ShouldNotConflictWithSecondaryBatchApplicationBlock shouldNotConflictBlock(