diff options
author | Louis Williams <louis.williams@mongodb.com> | 2019-11-13 19:06:03 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-11-13 19:06:03 +0000 |
commit | 5074799696cdff95f46b81f054f04b2a55a1e2bc (patch) | |
tree | 3685b11ba3084fa460fb5f053bbbc377eadd69d3 | |
parent | 4163903e61da8a841bb10b59cea6ab1180305d65 (diff) | |
download | mongo-5074799696cdff95f46b81f054f04b2a55a1e2bc.tar.gz |
SERVER-44250 serialize startIndexBuild oplog write and thread pool scheduling between concurrent threads on primaries
-rw-r--r-- | etc/evergreen.yml | 1 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/index_builds_coordinator_mongod.h | 3 |
3 files changed, 15 insertions, 0 deletions
diff --git a/etc/evergreen.yml b/etc/evergreen.yml index c5d169f7ffe..8ecf15dd47f 100644 --- a/etc/evergreen.yml +++ b/etc/evergreen.yml @@ -11219,6 +11219,7 @@ buildvariants: - name: compile_TG distros: - rhel62-large + - name: .concurrency !.large !.ubsan !.no_txns !.stepdowns !.kill_terminate !.debug_only - name: .jscore .common - name: noPassthrough_gen - name: noPassthroughWithMongod_gen diff --git a/src/mongo/db/index_builds_coordinator_mongod.cpp b/src/mongo/db/index_builds_coordinator_mongod.cpp index 99cdc6b6ca1..2d205a452c4 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.cpp +++ b/src/mongo/db/index_builds_coordinator_mongod.cpp @@ -95,6 +95,17 @@ IndexBuildsCoordinatorMongod::startIndexBuild(OperationContext* opCtx, const UUID& buildUUID, IndexBuildProtocol protocol, IndexBuildOptions indexBuildOptions) { + // This lock serializes setting up the index build and scheduling it on the thread pool between + // concurrent callers. It guarantees that if this thread replicates a "startIndexBuild" oplog + // entry in the setup, no other concurrent thread can schedule its work ahead of this one. The + // thread pool can become saturated with work such that the task gets queued and not immediately + // run. The serialization in this function guarantees that primaries and secondaries will + // execute these steps in the same order, which is important to avoid deadlocks due to thread + // pool resource contention. + // TODO(SERVER-44609): Remove this mutex and setup the index build on the scheduled index build + // thread. + stdx::unique_lock<Latch> lk(_startBuildMutex); + auto statusWithOptionalResult = _registerAndSetUpIndexBuild( opCtx, dbName, collectionUUID, specs, buildUUID, protocol, indexBuildOptions.commitQuorum); if (!statusWithOptionalResult.isOK()) { diff --git a/src/mongo/db/index_builds_coordinator_mongod.h b/src/mongo/db/index_builds_coordinator_mongod.h index d03e5f33653..46e990abd23 100644 --- a/src/mongo/db/index_builds_coordinator_mongod.h +++ b/src/mongo/db/index_builds_coordinator_mongod.h @@ -123,6 +123,9 @@ private: */ void _refreshReplStateFromPersisted(OperationContext* opCtx, const UUID& buildUUID); + // Serializes setting up an index build and scheduling it on the thread pool. + mutable Mutex _startBuildMutex = MONGO_MAKE_LATCH("IndexBuildsCoordinator::_startBuildMutex"); + // Thread pool on which index builds are run. ThreadPool _threadPool; }; |