summaryrefslogtreecommitdiff
path: root/src/mongo/db/index_builds_coordinator.h
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2019-12-03 03:19:38 +0000
committerevergreen <evergreen@mongodb.com>2019-12-03 03:19:38 +0000
commitd84c908c148e2bd8a4cecec7e4b417ebaacd91ce (patch)
tree84ad5ece5528d36d964da232d38539f9efee566f /src/mongo/db/index_builds_coordinator.h
parent587f15f0f823924c852b261497110e4b78dca7fe (diff)
downloadmongo-d84c908c148e2bd8a4cecec7e4b417ebaacd91ce.tar.gz
SERVER-44609 Replicate startIndexBuild oplog entry in the same thread as the index build
Instead of initializing and replicating the startIndexBuild oplog entry on the caller thread, this moves that logic into the builder thread. This change removes the need for a mutex which previously made that operation atomic.
Diffstat (limited to 'src/mongo/db/index_builds_coordinator.h')
-rw-r--r--src/mongo/db/index_builds_coordinator.h53
1 files changed, 34 insertions, 19 deletions
diff --git a/src/mongo/db/index_builds_coordinator.h b/src/mongo/db/index_builds_coordinator.h
index ab4fae20711..f0fd24d3ea4 100644
--- a/src/mongo/db/index_builds_coordinator.h
+++ b/src/mongo/db/index_builds_coordinator.h
@@ -115,8 +115,11 @@ public:
bool supportsTwoPhaseIndexBuild() const;
/**
- * Sets up the in-memory and persisted state of the index build. A Future is returned upon which
- * the user can await the build result.
+ * Sets up the in-memory and durable state of the index build. When successful, returns after
+ * the index build has started and the first catalog write has been made, and if called on a
+ * primary, when the startIndexBuild oplog entry has been written.
+ *
+ * A Future is returned that will complete when the index build commits or aborts.
*
* On a successful index build, calling Future::get(), or Future::getNoThrows(), returns index
* catalog statistics.
@@ -125,7 +128,7 @@ public:
*/
virtual StatusWith<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>> startIndexBuild(
OperationContext* opCtx,
- StringData dbName,
+ std::string dbName,
CollectionUUID collectionUUID,
const std::vector<BSONObj>& specs,
const UUID& buildUUID,
@@ -383,7 +386,7 @@ private:
Status _registerIndexBuild(WithLock, std::shared_ptr<ReplIndexBuildState> replIndexBuildState);
/**
- * Sets up the in-memory and persisted state of the index build.
+ * Sets up the in-memory and durable state of the index build.
*
* This function should only be called when in recovery mode, because we drop and replace
* existing indexes in a single WriteUnitOfWork.
@@ -402,32 +405,44 @@ protected:
std::shared_ptr<ReplIndexBuildState> replIndexBuildState);
/**
- * Sets up the in-memory and persisted state of the index build.
+ * Sets up the in-memory state of the index build. Validates index specs and filters out
+ * existing indexes from the list of specs.
*
* Helper function for startIndexBuild. If the returned boost::optional is set, then the task
* does not require scheduling and can be immediately returned to the caller of startIndexBuild.
*
- * Returns an error status if there are any errors setting up the index build.
+ * Returns an error status if there are any errors registering the index build.
*/
StatusWith<boost::optional<SharedSemiFuture<ReplIndexBuildState::IndexCatalogStats>>>
- _registerAndSetUpIndexBuild(OperationContext* opCtx,
- StringData dbName,
- CollectionUUID collectionUUID,
- const std::vector<BSONObj>& specs,
- const UUID& buildUUID,
- IndexBuildProtocol protocol,
- boost::optional<CommitQuorumOptions> commitQuorum);
+ _filterSpecsAndRegisterBuild(OperationContext* opCtx,
+ StringData dbName,
+ CollectionUUID collectionUUID,
+ const std::vector<BSONObj>& specs,
+ const UUID& buildUUID,
+ IndexBuildProtocol protocol,
+ boost::optional<CommitQuorumOptions> commitQuorum);
+
+ /**
+ * Sets up the durable state of the index build.
+ *
+ * Returns an error status if there are any errors setting up the index build.
+ */
+ Status _setUpIndexBuild(OperationContext* opCtx,
+ StringData dbName,
+ CollectionUUID collectionUUID,
+ const UUID& buildUUID,
+ Timestamp startTimestamp);
/**
- * Sets up the in-memory and persisted state of the index build for two-phase recovery.
+ * Sets up the in-memory and durable state of the index build for two-phase recovery.
*
* Helper function for startIndexBuild during the two-phase index build recovery process.
*/
- Status _registerAndSetUpIndexBuildForTwoPhaseRecovery(OperationContext* opCtx,
- StringData dbName,
- CollectionUUID collectionUUID,
- const std::vector<BSONObj>& specs,
- const UUID& buildUUID);
+ Status _setUpIndexBuildForTwoPhaseRecovery(OperationContext* opCtx,
+ StringData dbName,
+ CollectionUUID collectionUUID,
+ const std::vector<BSONObj>& specs,
+ const UUID& buildUUID);
/**
* Runs the index build on the caller thread. Handles unregistering the index build and setting
* the index build's Promise with the outcome of the index build.