diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/index_builds_coordinator.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator.h | 10 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 11 | ||||
-rw-r--r-- | src/mongo/embedded/index_builds_coordinator_embedded.cpp | 3 |
5 files changed, 26 insertions, 11 deletions
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp index 1ec6de7ede8..7bb6004d42b 100644 --- a/src/mongo/db/index_builds_coordinator.cpp +++ b/src/mongo/db/index_builds_coordinator.cpp @@ -691,7 +691,8 @@ IndexBuildsCoordinator::_registerAndSetUpIndexBuild( } void IndexBuildsCoordinator::_runIndexBuild(OperationContext* opCtx, - const UUID& buildUUID) noexcept { + const UUID& buildUUID, + const IndexBuildOptions& indexBuildOptions) noexcept { { stdx::unique_lock<stdx::mutex> lk(_mutex); while (_sleepForTest) { @@ -710,7 +711,7 @@ void IndexBuildsCoordinator::_runIndexBuild(OperationContext* opCtx, auto status = [&]() { try { - _runIndexBuildInner(opCtx, replState); + _runIndexBuildInner(opCtx, replState, indexBuildOptions); } catch (const DBException& ex) { return ex.toStatus(); } @@ -732,7 +733,8 @@ void IndexBuildsCoordinator::_runIndexBuild(OperationContext* opCtx, } void IndexBuildsCoordinator::_runIndexBuildInner(OperationContext* opCtx, - std::shared_ptr<ReplIndexBuildState> replState) { + std::shared_ptr<ReplIndexBuildState> replState, + const IndexBuildOptions& indexBuildOptions) { // 'status' should always be set to something else before this function exits. Status status{ErrorCodes::InternalError, "Uninitialized status value in IndexBuildsCoordinator"}; diff --git a/src/mongo/db/index_builds_coordinator.h b/src/mongo/db/index_builds_coordinator.h index 2c57b01e6d5..2a502c5dfff 100644 --- a/src/mongo/db/index_builds_coordinator.h +++ b/src/mongo/db/index_builds_coordinator.h @@ -74,6 +74,7 @@ public: */ struct IndexBuildOptions { boost::optional<CommitQuorumOptions> commitQuorum; + bool replSetAndNotPrimary = false; }; /** @@ -346,14 +347,19 @@ protected: /** * 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. + * 'IndexBuildOptios::replSetAndNotPrimary' is determined at the start of the index build. */ - void _runIndexBuild(OperationContext* opCtx, const UUID& buildUUID) noexcept; + void _runIndexBuild(OperationContext* opCtx, + const UUID& buildUUID, + const IndexBuildOptions& indexBuildOptions) noexcept; /** * Acquires locks and runs index build. Throws on error. + * 'IndexBuildOptios::replSetAndNotPrimary' is determined at the start of the index build. */ void _runIndexBuildInner(OperationContext* opCtx, - std::shared_ptr<ReplIndexBuildState> replState); + std::shared_ptr<ReplIndexBuildState> replState, + const IndexBuildOptions& indexBuildOptions); /** * Modularizes the _indexBuildsManager calls part of _runIndexBuildInner. Throws on error. diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index 8d71eed1d16..baba0f332ff 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -124,7 +124,7 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx, "replication states: " << buildUUID; // Sets up and runs the index build. Sets result and cleans up index build. - _runIndexBuild(opCtx, buildUUID); + _runIndexBuild(opCtx, buildUUID, indexBuildOptions); return replState->sharedPromise.getFuture(); } @@ -160,6 +160,7 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx, _threadPool.schedule([ this, buildUUID, + indexBuildOptions, deadline, timeoutError, writesAreReplicated, @@ -207,7 +208,7 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx, } // Sets up and runs the index build. Sets result and cleans up index build. - _runIndexBuild(opCtx.get(), buildUUID); + _runIndexBuild(opCtx.get(), buildUUID, indexBuildOptions); }); diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 68df63b3cff..5d5b2f16ef5 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -188,7 +188,9 @@ Status startIndexBuild(OperationContext* opCtx, return statusWithIndexes.getStatus(); } - IndexBuildsCoordinator::IndexBuildOptions indexBuildOptions = {/*commitQuorum=*/boost::none}; + IndexBuildsCoordinator::IndexBuildOptions indexBuildOptions; + invariant(!indexBuildOptions.commitQuorum); + indexBuildOptions.replSetAndNotPrimary = true; // We don't pass in a commit quorum here because secondary nodes don't have any knowledge of it. return IndexBuildsCoordinator::get(opCtx) @@ -269,10 +271,13 @@ void createIndexForApplyOps(OperationContext* opCtx, auto collUUID = *indexCollection->uuid(); auto indexBuildUUID = UUID::gen(); auto indexBuildsCoordinator = IndexBuildsCoordinator::get(opCtx); + // We don't pass in a commit quorum here because secondary nodes don't have any knowledge of // it. - IndexBuildsCoordinator::IndexBuildOptions indexBuildOptions = { - /*commitQuorum=*/boost::none}; + IndexBuildsCoordinator::IndexBuildOptions indexBuildOptions; + invariant(!indexBuildOptions.commitQuorum); + indexBuildOptions.replSetAndNotPrimary = true; + // This spawns a new thread and returns immediately. MONGO_COMPILER_VARIABLE_UNUSED auto fut = uassertStatusOK( indexBuildsCoordinator->startIndexBuild(opCtx, diff --git a/src/mongo/embedded/index_builds_coordinator_embedded.cpp b/src/mongo/embedded/index_builds_coordinator_embedded.cpp index 860e762b493..594ec36f8a0 100644 --- a/src/mongo/embedded/index_builds_coordinator_embedded.cpp +++ b/src/mongo/embedded/index_builds_coordinator_embedded.cpp @@ -74,7 +74,8 @@ IndexBuildsCoordinatorEmbedded::startIndexBuild(OperationContext* opCtx, return it->second; }(); - _runIndexBuild(opCtx, buildUUID); + invariant(!indexBuildOptions.replSetAndNotPrimary); + _runIndexBuild(opCtx, buildUUID, indexBuildOptions); return replState->sharedPromise.getFuture(); } |