summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenety Goh <benety@mongodb.com>2019-11-08 18:29:38 +0000
committerevergreen <evergreen@mongodb.com>2019-11-08 18:29:38 +0000
commit8d02d5b95fd198e685cb5009e1613730379d5e0c (patch)
tree6c0beb607ada8bc4db50ae22ea889047f55a1328
parent71add1d5fbb07c95df6cde80a79ab203ac451470 (diff)
downloadmongo-8d02d5b95fd198e685cb5009e1613730379d5e0c.tar.gz
SERVER-44393 split IndexBuildsCoordinator::_buildIndex() by index build protocol (single or two phase)
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp30
-rw-r--r--src/mongo/db/index_builds_coordinator.h22
2 files changed, 52 insertions, 0 deletions
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index a1bed562111..102a431fc2c 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -1248,6 +1248,36 @@ void IndexBuildsCoordinator::_buildIndex(
std::shared_ptr<ReplIndexBuildState> replState,
const IndexBuildOptions& indexBuildOptions,
boost::optional<Lock::CollectionLock>* exclusiveCollectionLock) {
+
+ if (IndexBuildProtocol::kSinglePhase == replState->protocol) {
+ _buildIndexSinglePhase(
+ opCtx, dbAndUUID, replState, indexBuildOptions, exclusiveCollectionLock);
+ return;
+ }
+
+ invariant(IndexBuildProtocol::kTwoPhase == replState->protocol,
+ str::stream() << replState->buildUUID);
+ _buildIndexTwoPhase(opCtx, dbAndUUID, replState, indexBuildOptions, exclusiveCollectionLock);
+}
+
+void IndexBuildsCoordinator::_buildIndexSinglePhase(
+ OperationContext* opCtx,
+ const NamespaceStringOrUUID& dbAndUUID,
+ std::shared_ptr<ReplIndexBuildState> replState,
+ const IndexBuildOptions& indexBuildOptions,
+ boost::optional<Lock::CollectionLock>* exclusiveCollectionLock) {
+ _scanCollectionAndInsertKeysIntoSorter(opCtx, dbAndUUID, replState, exclusiveCollectionLock);
+ _insertKeysFromSideTablesWithoutBlockingWrites(opCtx, dbAndUUID, replState);
+ _insertKeysFromSideTablesAndCommit(
+ opCtx, dbAndUUID, replState, indexBuildOptions, exclusiveCollectionLock, {});
+}
+
+void IndexBuildsCoordinator::_buildIndexTwoPhase(
+ OperationContext* opCtx,
+ const NamespaceStringOrUUID& dbAndUUID,
+ std::shared_ptr<ReplIndexBuildState> replState,
+ const IndexBuildOptions& indexBuildOptions,
+ boost::optional<Lock::CollectionLock>* exclusiveCollectionLock) {
_scanCollectionAndInsertKeysIntoSorter(opCtx, dbAndUUID, replState, exclusiveCollectionLock);
auto nss = _insertKeysFromSideTablesWithoutBlockingWrites(opCtx, dbAndUUID, replState);
auto commitIndexBuildTimestamp = _waitForCommitOrAbort(opCtx, nss, replState);
diff --git a/src/mongo/db/index_builds_coordinator.h b/src/mongo/db/index_builds_coordinator.h
index 3c909c3f2c9..2183b1f1e5f 100644
--- a/src/mongo/db/index_builds_coordinator.h
+++ b/src/mongo/db/index_builds_coordinator.h
@@ -421,6 +421,28 @@ protected:
boost::optional<Lock::CollectionLock>* collLock);
/**
+ * Builds the indexes single-phased.
+ * This method matches pre-4.4 behavior for a background index build driven by a single
+ * createIndexes oplog entry.
+ */
+ void _buildIndexSinglePhase(OperationContext* opCtx,
+ const NamespaceStringOrUUID& dbAndUUID,
+ std::shared_ptr<ReplIndexBuildState> replState,
+ const IndexBuildOptions& indexBuildOptions,
+ boost::optional<Lock::CollectionLock>* collLock);
+
+ /**
+ * Builds the indexes two-phased.
+ * The beginning and completion of a index build is driven by the startIndexBuild and
+ * commitIndexBuild oplog entries, respectively.
+ */
+ void _buildIndexTwoPhase(OperationContext* opCtx,
+ const NamespaceStringOrUUID& dbAndUUID,
+ std::shared_ptr<ReplIndexBuildState> replState,
+ const IndexBuildOptions& indexBuildOptions,
+ boost::optional<Lock::CollectionLock>* collLock);
+
+ /**
* First phase is the collection scan and insertion of the keys into the sorter.
*/
void _scanCollectionAndInsertKeysIntoSorter(