summaryrefslogtreecommitdiff
path: root/src/mongo/db/system_index.cpp
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2019-09-30 20:36:02 +0000
committerevergreen <evergreen@mongodb.com>2019-09-30 20:36:02 +0000
commit3bd5a68827f73f0f3717cb21e725301c8d2cd480 (patch)
tree2cafc66d6e2b4267235bdccbaebf72194babc246 /src/mongo/db/system_index.cpp
parent8e981e8315ab7c7bae93da623e40ffdce5b4ec6e (diff)
downloadmongo-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/system_index.cpp')
-rw-r--r--src/mongo/db/system_index.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/mongo/db/system_index.cpp b/src/mongo/db/system_index.cpp
index 3cde99b3a97..06c1fecc91d 100644
--- a/src/mongo/db/system_index.cpp
+++ b/src/mongo/db/system_index.cpp
@@ -245,12 +245,35 @@ void createSystemIndexes(OperationContext* opCtx, Collection* collection) {
opCtx, v3SystemRolesIndexSpec.toBSON(), serverGlobalParams.featureCompatibility));
}
if (!indexSpec.isEmpty()) {
- opCtx->getServiceContext()->getOpObserver()->onCreateIndex(
- opCtx, ns, collection->uuid(), indexSpec, false /* fromMigrate */);
+ // 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;
+
+ if (buildUUID) {
+ opObserver->onStartIndexBuild(
+ opCtx, ns, collection->uuid(), *buildUUID, {indexSpec}, fromMigrate);
+ }
+
+ // If two phase index builds are enabled, the index build will be coordinated using
+ // startIndexBuild and commitIndexBuild oplog entries.
+ if (!IndexBuildsCoordinator::get(opCtx)->supportsTwoPhaseIndexBuild()) {
+ opObserver->onCreateIndex(opCtx, ns, collection->uuid(), indexSpec, fromMigrate);
+ }
+
// Note that the opObserver is called prior to creating the index. This ensures the index
// write gets the same storage timestamp as the oplog entry.
fassert(40456,
collection->getIndexCatalog()->createIndexOnEmptyCollection(opCtx, indexSpec));
+
+ if (buildUUID) {
+ opObserver->onCommitIndexBuild(
+ opCtx, ns, collection->uuid(), *buildUUID, {indexSpec}, fromMigrate);
+ }
}
}