diff options
author | Louis Williams <louis.williams@mongodb.com> | 2019-09-30 20:36:02 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-30 20:36:02 +0000 |
commit | 3bd5a68827f73f0f3717cb21e725301c8d2cd480 (patch) | |
tree | 2cafc66d6e2b4267235bdccbaebf72194babc246 /src/mongo/db/cloner.cpp | |
parent | 8e981e8315ab7c7bae93da623e40ffdce5b4ec6e (diff) | |
download | mongo-3bd5a68827f73f0f3717cb21e725301c8d2cd480.tar.gz |
SERVER-43323 All replicated index builds should write startIndexBuild
and commitIndexBuild oplog entries
This emits the two-phase oplog entries in cloner.cpp, system_index.cpp and
index_builder.cpp.
Diffstat (limited to 'src/mongo/db/cloner.cpp')
-rw-r--r-- | src/mongo/db/cloner.cpp | 54 |
1 files changed, 44 insertions, 10 deletions
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index 06d594d1afd..16dfcd0cd8f 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -52,6 +52,7 @@ #include "mongo/db/curop.h" #include "mongo/db/dbdirectclient.h" #include "mongo/db/index/index_descriptor.h" +#include "mongo/db/index_builds_coordinator.h" #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" #include "mongo/db/op_observer.h" @@ -369,20 +370,53 @@ void Cloner::copyIndexes(OperationContext* opCtx, // The code below throws, so ensure build cleanup occurs. ON_BLOCK_EXIT([&] { indexer.cleanUpAfterBuild(opCtx, collection); }); - auto indexInfoObjs = uassertStatusOK( - indexer.init(opCtx, collection, indexesToBuild, MultiIndexBlock::kNoopOnInitFn)); + // Emit startIndexBuild and commitIndexBuild oplog entries if supported by the current FCV. + auto opObserver = opCtx->getServiceContext()->getOpObserver(); + auto fromMigrate = false; + auto buildUUID = serverGlobalParams.featureCompatibility.isVersionInitialized() && + serverGlobalParams.featureCompatibility.getVersion() == + ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo44 + ? boost::make_optional(UUID::gen()) + : boost::none; + + MultiIndexBlock::OnInitFn onInitFn; + if (opCtx->writesAreReplicated() && buildUUID) { + onInitFn = [&](std::vector<BSONObj>& specs) { + opObserver->onStartIndexBuild( + opCtx, to_collection, collection->uuid(), *buildUUID, specs, fromMigrate); + return Status::OK(); + }; + } else { + onInitFn = MultiIndexBlock::kNoopOnInitFn; + } + + auto indexInfoObjs = uassertStatusOK(indexer.init(opCtx, collection, indexesToBuild, onInitFn)); uassertStatusOK(indexer.insertAllDocumentsInCollection(opCtx, collection)); uassertStatusOK(indexer.checkConstraints(opCtx)); WriteUnitOfWork wunit(opCtx); - uassertStatusOK(indexer.commit( - opCtx, collection, MultiIndexBlock::kNoopOnCreateEachFn, MultiIndexBlock::kNoopOnCommitFn)); - if (opCtx->writesAreReplicated()) { - for (auto&& infoObj : indexInfoObjs) { - getGlobalServiceContext()->getOpObserver()->onCreateIndex( - opCtx, collection->ns(), collection->uuid(), infoObj, false); - } - } + uassertStatusOK( + indexer.commit(opCtx, + collection, + [&](const BSONObj& spec) { + // If two phase index builds are enabled, the index build will be + // coordinated using startIndexBuild and commitIndexBuild oplog entries. + if (opCtx->writesAreReplicated() && + !IndexBuildsCoordinator::get(opCtx)->supportsTwoPhaseIndexBuild()) { + opObserver->onCreateIndex( + opCtx, collection->ns(), collection->uuid(), spec, fromMigrate); + } + }, + [&] { + if (opCtx->writesAreReplicated() && buildUUID) { + opObserver->onCommitIndexBuild(opCtx, + collection->ns(), + collection->uuid(), + *buildUUID, + indexInfoObjs, + fromMigrate); + } + })); wunit.commit(); } |