From 80c13a3f72d3721ce6de872231170b18c0dc6ff5 Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Sun, 27 Oct 2019 17:42:41 +0000 Subject: SERVER-44186 index builds use same OperationContext::writesAreReplicated() setting across primaries and secondaries --- src/mongo/db/SConscript | 1 + src/mongo/db/index_builds_coordinator.cpp | 7 +++++++ src/mongo/db/index_builds_coordinator_mongod.cpp | 17 ----------------- 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 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( -- cgit v1.2.1