From 260660f1dd8708ae2f836c17e7717bd1a2475509 Mon Sep 17 00:00:00 2001 From: gvolfing <107616712+gvolfing@users.noreply.github.com> Date: Sat, 5 Aug 2023 23:20:15 +0200 Subject: [PATCH] Fix sequential label-property index recovery (#1135) The parallel_exec_info should have been passed to this function before, otherwise, the recovery of label-property indices would never have been parallelized. --- src/storage/v2/disk/label_property_index.hpp | 2 +- src/storage/v2/durability/durability.cpp | 6 +++--- src/storage/v2/durability/durability.hpp | 4 ++-- src/storage/v2/inmemory/indices_utils.hpp | 8 ++++---- src/storage/v2/inmemory/label_index.cpp | 10 +++++----- src/storage/v2/inmemory/label_index.hpp | 4 ++-- src/storage/v2/inmemory/label_property_index.cpp | 10 +++++----- src/storage/v2/inmemory/label_property_index.hpp | 4 ++-- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/storage/v2/disk/label_property_index.hpp b/src/storage/v2/disk/label_property_index.hpp index 9be8287f7..ba7f7aaa8 100644 --- a/src/storage/v2/disk/label_property_index.hpp +++ b/src/storage/v2/disk/label_property_index.hpp @@ -15,7 +15,7 @@ namespace memgraph::storage { /// TODO: andi. Too many copies, extract at one place -using ParalellizedIndexCreationInfo = +using ParallelizedIndexCreationInfo = std::pair> /*vertex_recovery_info*/, uint64_t /*thread_count*/>; class DiskLabelPropertyIndex : public storage::LabelPropertyIndex { diff --git a/src/storage/v2/durability/durability.cpp b/src/storage/v2/durability/durability.cpp index 99b286332..3522750d0 100644 --- a/src/storage/v2/durability/durability.cpp +++ b/src/storage/v2/durability/durability.cpp @@ -127,13 +127,13 @@ std::optional> GetWalFiles(const std::filesystem: // recovery process. void RecoverIndicesAndConstraints(const RecoveredIndicesAndConstraints &indices_constraints, Indices *indices, Constraints *constraints, utils::SkipList *vertices, - const std::optional ¶lell_exec_info) { + const std::optional ¶llel_exec_info) { spdlog::info("Recreating indices from metadata."); // Recover label indices. spdlog::info("Recreating {} label indices from metadata.", indices_constraints.indices.label.size()); for (const auto &item : indices_constraints.indices.label) { auto *mem_label_index = static_cast(indices->label_index_.get()); - if (!mem_label_index->CreateIndex(item, vertices->access(), paralell_exec_info)) + if (!mem_label_index->CreateIndex(item, vertices->access(), parallel_exec_info)) throw RecoveryFailure("The label index must be created here!"); spdlog::info("A label index is recreated from metadata."); @@ -145,7 +145,7 @@ void RecoverIndicesAndConstraints(const RecoveredIndicesAndConstraints &indices_ indices_constraints.indices.label_property.size()); auto *mem_label_property_index = static_cast(indices->label_property_index_.get()); for (const auto &item : indices_constraints.indices.label_property) { - if (!mem_label_property_index->CreateIndex(item.first, item.second, vertices->access(), std::nullopt)) + if (!mem_label_property_index->CreateIndex(item.first, item.second, vertices->access(), parallel_exec_info)) throw RecoveryFailure("The label+property index must be created here!"); spdlog::info("A label+property index is recreated from metadata."); } diff --git a/src/storage/v2/durability/durability.hpp b/src/storage/v2/durability/durability.hpp index 2e13a776a..99efde6b6 100644 --- a/src/storage/v2/durability/durability.hpp +++ b/src/storage/v2/durability/durability.hpp @@ -91,7 +91,7 @@ std::optional> GetWalFiles(const std::filesystem: std::string_view uuid = "", std::optional current_seq_num = {}); -using ParalellizedIndexCreationInfo = +using ParallelizedIndexCreationInfo = std::pair> /*vertex_recovery_info*/, uint64_t /*thread_count*/>; // Helper function used to recover all discovered indices and constraints. The @@ -102,7 +102,7 @@ using ParalellizedIndexCreationInfo = void RecoverIndicesAndConstraints( const RecoveredIndicesAndConstraints &indices_constraints, Indices *indices, Constraints *constraints, utils::SkipList *vertices, - const std::optional ¶lell_exec_info = std::nullopt); + const std::optional ¶llel_exec_info = std::nullopt); /// Recovers data either from a snapshot and/or WAL files. /// @throw RecoveryFailure diff --git a/src/storage/v2/inmemory/indices_utils.hpp b/src/storage/v2/inmemory/indices_utils.hpp index dbfc8e80c..25218bdc4 100644 --- a/src/storage/v2/inmemory/indices_utils.hpp +++ b/src/storage/v2/inmemory/indices_utils.hpp @@ -19,7 +19,7 @@ namespace memgraph::storage { -using ParalellizedIndexCreationInfo = +using ParallelizedIndexCreationInfo = std::pair> /*vertex_recovery_info*/, uint64_t /*thread_count*/>; /// Traverses deltas visible from transaction with start timestamp greater than @@ -306,11 +306,11 @@ inline void CreateIndexOnSingleThread(utils::SkipList::Accessor &vertice template inline void CreateIndexOnMultipleThreads(utils::SkipList::Accessor &vertices, TSKiplistIter skiplist_iter, TIndex &index, TIndexKey key, - const ParalellizedIndexCreationInfo ¶lell_exec_info, const TFunc &func) { + const ParallelizedIndexCreationInfo ¶llel_exec_info, const TFunc &func) { utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception; - const auto &vertex_batches = paralell_exec_info.first; - const auto thread_count = std::min(paralell_exec_info.second, vertex_batches.size()); + const auto &vertex_batches = parallel_exec_info.first; + const auto thread_count = std::min(parallel_exec_info.second, vertex_batches.size()); MG_ASSERT(!vertex_batches.empty(), "The size of batches should always be greater than zero if you want to use the parallel version of index " diff --git a/src/storage/v2/inmemory/label_index.cpp b/src/storage/v2/inmemory/label_index.cpp index 625590f5e..9b5e6cb1e 100644 --- a/src/storage/v2/inmemory/label_index.cpp +++ b/src/storage/v2/inmemory/label_index.cpp @@ -25,7 +25,7 @@ void InMemoryLabelIndex::UpdateOnAddLabel(LabelId added_label, Vertex *vertex_af } bool InMemoryLabelIndex::CreateIndex(LabelId label, utils::SkipList::Accessor vertices, - const std::optional ¶lell_exec_info) { + const std::optional ¶llel_exec_info) { const auto create_index_seq = [this](LabelId label, utils::SkipList::Accessor &vertices, std::map>::iterator it) { using IndexAccessor = decltype(it->second.access()); @@ -40,10 +40,10 @@ bool InMemoryLabelIndex::CreateIndex(LabelId label, utils::SkipList::Acc const auto create_index_par = [this](LabelId label, utils::SkipList::Accessor &vertices, std::map>::iterator label_it, - const ParalellizedIndexCreationInfo ¶lell_exec_info) { + const ParallelizedIndexCreationInfo ¶llel_exec_info) { using IndexAccessor = decltype(label_it->second.access()); - CreateIndexOnMultipleThreads(vertices, label_it, index_, label, paralell_exec_info, + CreateIndexOnMultipleThreads(vertices, label_it, index_, label, parallel_exec_info, [](Vertex &vertex, LabelId label, IndexAccessor &index_accessor) { TryInsertLabelIndex(vertex, label, index_accessor); }); @@ -57,8 +57,8 @@ bool InMemoryLabelIndex::CreateIndex(LabelId label, utils::SkipList::Acc return false; } - if (paralell_exec_info) { - return create_index_par(label, vertices, it, *paralell_exec_info); + if (parallel_exec_info) { + return create_index_par(label, vertices, it, *parallel_exec_info); } return create_index_seq(label, vertices, it); } diff --git a/src/storage/v2/inmemory/label_index.hpp b/src/storage/v2/inmemory/label_index.hpp index 4a32640f6..ca06ab79b 100644 --- a/src/storage/v2/inmemory/label_index.hpp +++ b/src/storage/v2/inmemory/label_index.hpp @@ -21,7 +21,7 @@ struct LabelIndexStats { double avg_degree; }; -using ParalellizedIndexCreationInfo = +using ParallelizedIndexCreationInfo = std::pair> /*vertex_recovery_info*/, uint64_t /*thread_count*/>; class InMemoryLabelIndex : public storage::LabelIndex { @@ -46,7 +46,7 @@ class InMemoryLabelIndex : public storage::LabelIndex { /// @throw std::bad_alloc bool CreateIndex(LabelId label, utils::SkipList::Accessor vertices, - const std::optional ¶lell_exec_info); + const std::optional ¶llel_exec_info); /// Returns false if there was no index to drop bool DropIndex(LabelId label) override; diff --git a/src/storage/v2/inmemory/label_property_index.cpp b/src/storage/v2/inmemory/label_property_index.cpp index b19e316f0..a62101ba0 100644 --- a/src/storage/v2/inmemory/label_property_index.cpp +++ b/src/storage/v2/inmemory/label_property_index.cpp @@ -37,7 +37,7 @@ InMemoryLabelPropertyIndex::InMemoryLabelPropertyIndex(Indices *indices, Constra bool InMemoryLabelPropertyIndex::CreateIndex(LabelId label, PropertyId property, utils::SkipList::Accessor vertices, - const std::optional ¶lell_exec_info) { + const std::optional ¶llel_exec_info) { auto create_index_seq = [this](LabelId label, PropertyId property, utils::SkipList::Accessor &vertices, std::map, utils::SkipList>::iterator it) { using IndexAccessor = decltype(it->second.access()); @@ -53,11 +53,11 @@ bool InMemoryLabelPropertyIndex::CreateIndex(LabelId label, PropertyId property, auto create_index_par = [this](LabelId label, PropertyId property, utils::SkipList::Accessor &vertices, std::map, utils::SkipList>::iterator label_property_it, - const ParalellizedIndexCreationInfo ¶lell_exec_info) { + const ParallelizedIndexCreationInfo ¶llel_exec_info) { using IndexAccessor = decltype(label_property_it->second.access()); CreateIndexOnMultipleThreads( - vertices, label_property_it, index_, std::make_pair(label, property), paralell_exec_info, + vertices, label_property_it, index_, std::make_pair(label, property), parallel_exec_info, [](Vertex &vertex, std::pair key, IndexAccessor &index_accessor) { TryInsertLabelPropertyIndex(vertex, key, index_accessor); }); @@ -72,8 +72,8 @@ bool InMemoryLabelPropertyIndex::CreateIndex(LabelId label, PropertyId property, return false; } - if (paralell_exec_info) { - return create_index_par(label, property, vertices, it, *paralell_exec_info); + if (parallel_exec_info) { + return create_index_par(label, property, vertices, it, *parallel_exec_info); } return create_index_seq(label, property, vertices, it); } diff --git a/src/storage/v2/inmemory/label_property_index.hpp b/src/storage/v2/inmemory/label_property_index.hpp index 13db8109e..7557a379c 100644 --- a/src/storage/v2/inmemory/label_property_index.hpp +++ b/src/storage/v2/inmemory/label_property_index.hpp @@ -21,7 +21,7 @@ struct LabelPropertyIndexStats { }; /// TODO: andi. Too many copies, extract at one place -using ParalellizedIndexCreationInfo = +using ParallelizedIndexCreationInfo = std::pair> /*vertex_recovery_info*/, uint64_t /*thread_count*/>; class InMemoryLabelPropertyIndex : public storage::LabelPropertyIndex { @@ -43,7 +43,7 @@ class InMemoryLabelPropertyIndex : public storage::LabelPropertyIndex { /// @throw std::bad_alloc bool CreateIndex(LabelId label, PropertyId property, utils::SkipList::Accessor vertices, - const std::optional ¶lell_exec_info); + const std::optional ¶llel_exec_info); /// @throw std::bad_alloc void UpdateOnAddLabel(LabelId added_label, Vertex *vertex_after_update, const Transaction &tx) override;