summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2020-02-14 18:25:48 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-15 15:21:43 +0000
commitaa158f01816a38e7cc622f34a3bd3446010295a0 (patch)
tree21bab99dff06b9dca1966b597ed17cda9f12f132 /src
parent075fe424dbae0ff4b38d81d7d80cc70492cdd586 (diff)
downloadmongo-aa158f01816a38e7cc622f34a3bd3446010295a0.tar.gz
SERVER-37726 Add the ability for the CollectionIndexBuildsTracker to wait until the requested index build is finished
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/collection_index_builds_tracker.cpp26
-rw-r--r--src/mongo/db/collection_index_builds_tracker.h19
2 files changed, 37 insertions, 8 deletions
diff --git a/src/mongo/db/collection_index_builds_tracker.cpp b/src/mongo/db/collection_index_builds_tracker.cpp
index 677aa17fa3a..2c81c638d62 100644
--- a/src/mongo/db/collection_index_builds_tracker.cpp
+++ b/src/mongo/db/collection_index_builds_tracker.cpp
@@ -68,9 +68,7 @@ void CollectionIndexBuildsTracker::removeIndexBuild(
_buildStateByIndexName.erase(indexName);
}
- if (_buildStateByBuildUUID.empty()) {
- _noIndexBuildsRemainCondVar.notify_all();
- }
+ _indexBuildFinishedCondVar.notify_all();
}
std::shared_ptr<ReplIndexBuildState> CollectionIndexBuildsTracker::getIndexBuildState(
@@ -88,6 +86,14 @@ bool CollectionIndexBuildsTracker::hasIndexBuildState(WithLock, StringData index
return true;
}
+std::vector<UUID> CollectionIndexBuildsTracker::getIndexBuildUUIDs(WithLock) const {
+ std::vector<UUID> buildUUIDs;
+ for (const auto& state : _buildStateByBuildUUID) {
+ buildUUIDs.push_back(state.first);
+ }
+ return buildUUIDs;
+}
+
void CollectionIndexBuildsTracker::runOperationOnAllBuilds(
WithLock lk,
IndexBuildsManager* indexBuildsManager,
@@ -106,7 +112,7 @@ int CollectionIndexBuildsTracker::getNumberOfIndexBuilds(WithLock) const {
}
void CollectionIndexBuildsTracker::waitUntilNoIndexBuildsRemain(stdx::unique_lock<Latch>& lk) {
- _noIndexBuildsRemainCondVar.wait(lk, [&] {
+ _indexBuildFinishedCondVar.wait(lk, [&] {
if (_buildStateByBuildUUID.empty()) {
return true;
}
@@ -122,4 +128,16 @@ void CollectionIndexBuildsTracker::waitUntilNoIndexBuildsRemain(stdx::unique_loc
});
}
+void CollectionIndexBuildsTracker::waitUntilIndexBuildFinished(stdx::unique_lock<Latch>& lk,
+ const UUID& buildUUID) {
+ log() << "Waiting until index build with UUID " << buildUUID << " is finished";
+
+ _indexBuildFinishedCondVar.wait(lk, [&] {
+ if (_buildStateByBuildUUID.find(buildUUID) == _buildStateByBuildUUID.end()) {
+ return true;
+ }
+ return false;
+ });
+}
+
} // namespace mongo
diff --git a/src/mongo/db/collection_index_builds_tracker.h b/src/mongo/db/collection_index_builds_tracker.h
index 81c25fe73d3..234e6ccfcb5 100644
--- a/src/mongo/db/collection_index_builds_tracker.h
+++ b/src/mongo/db/collection_index_builds_tracker.h
@@ -49,7 +49,9 @@ class IndexBuildsManager;
* The owner of a CollectionIndexBuildsTracker instance must instantiate a mutex to use along with
* the data structure to ensure it remains consistent across single or multiple function accesses.
*
- * This is intended to only be used by the IndexBuildsCoordinator class.
+ * This is intended to only be used by the IndexBuildsCoordinator class. Functions expecting a lock
+ * to be passed in as a parameter require an already locked IndexBuildsCoordinator::_mutex in this
+ * case.
*/
class CollectionIndexBuildsTracker {
CollectionIndexBuildsTracker(const CollectionIndexBuildsTracker&) = delete;
@@ -73,6 +75,8 @@ public:
bool hasIndexBuildState(WithLock, StringData indexName) const;
+ std::vector<UUID> getIndexBuildUUIDs(WithLock) const;
+
/**
* Runs the provided function operation on all this collection's index builds
*
@@ -98,15 +102,22 @@ public:
*/
void waitUntilNoIndexBuildsRemain(stdx::unique_lock<Latch>& lk);
+ /**
+ * Returns when the index build with the given build UUID is no longer active. When the build
+ * UUID does not correspond to an active index build, returns immediately.
+ */
+ void waitUntilIndexBuildFinished(stdx::unique_lock<Latch>& lk, const UUID& buildUUID);
+
private:
// Maps of index build states on the collection, by build UUID and index name.
stdx::unordered_map<UUID, std::shared_ptr<ReplIndexBuildState>, UUID::Hash>
_buildStateByBuildUUID;
stdx::unordered_map<std::string, std::shared_ptr<ReplIndexBuildState>> _buildStateByIndexName;
- // Condition variable that is signaled when there are no active index builds remaining on the
- // collection.
- stdx::condition_variable _noIndexBuildsRemainCondVar;
+ // Condition variable that is signaled when an index build has finished on the collection. The
+ // accompanying mutex for this condition variable comes from the owner managing this class
+ // instance.
+ stdx::condition_variable _indexBuildFinishedCondVar;
};
} // namespace mongo