Unify CollectEntry method
This commit is contained in:
parent
859dfb28eb
commit
7d0e885f9a
@ -325,7 +325,7 @@ void LabelIndex::RemoveObsoleteEntries(const uint64_t clean_up_before_timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
LabelIndex::Iterable::Iterator::Iterator(Iterable *self, LabelIndexContainer::iterator index_iterator)
|
||||
LabelIndex::Iterable::Iterator::Iterator(Iterable *self, IndexContainer::iterator index_iterator)
|
||||
: self_(self),
|
||||
index_iterator_(index_iterator),
|
||||
current_vertex_accessor_(nullptr, nullptr, nullptr, self_->config_, *self_->vertex_validator_),
|
||||
@ -353,7 +353,7 @@ void LabelIndex::Iterable::Iterator::AdvanceUntilValid() {
|
||||
}
|
||||
}
|
||||
|
||||
LabelIndex::Iterable::Iterable(LabelIndexContainer &index_container, LabelId label, View view, Transaction *transaction,
|
||||
LabelIndex::Iterable::Iterable(IndexContainer &index_container, LabelId label, View view, Transaction *transaction,
|
||||
Indices *indices, Config::Items config, const VertexValidator &vertex_validator)
|
||||
: index_container_(&index_container),
|
||||
label_(label),
|
||||
@ -465,7 +465,7 @@ void LabelPropertyIndex::RemoveObsoleteEntries(const uint64_t clean_up_before_ti
|
||||
}
|
||||
}
|
||||
|
||||
LabelPropertyIndex::Iterable::Iterator::Iterator(Iterable *self, LabelPropertyIndexContainer::iterator index_iterator)
|
||||
LabelPropertyIndex::Iterable::Iterator::Iterator(Iterable *self, IndexContainer::iterator index_iterator)
|
||||
: self_(self),
|
||||
index_iterator_(index_iterator),
|
||||
current_vertex_accessor_(nullptr, nullptr, nullptr, self_->config_, *self_->vertex_validator_),
|
||||
@ -526,7 +526,7 @@ const PropertyValue kSmallestMap = PropertyValue(std::map<std::string, PropertyV
|
||||
const PropertyValue kSmallestTemporalData =
|
||||
PropertyValue(TemporalData{static_cast<TemporalType>(0), std::numeric_limits<int64_t>::min()});
|
||||
|
||||
LabelPropertyIndex::Iterable::Iterable(LabelPropertyIndexContainer &index_container, LabelId label, PropertyId property,
|
||||
LabelPropertyIndex::Iterable::Iterable(IndexContainer &index_container, LabelId label, PropertyId property,
|
||||
const std::optional<utils::Bound<PropertyValue>> &lower_bound,
|
||||
const std::optional<utils::Bound<PropertyValue>> &upper_bound, View view,
|
||||
Transaction *transaction, Indices *indices, Config::Items config,
|
||||
|
@ -41,13 +41,13 @@ class LabelIndex {
|
||||
bool operator==(const Entry &rhs) const { return vertex == rhs.vertex && timestamp == rhs.timestamp; }
|
||||
};
|
||||
|
||||
using LabelIndexContainer = std::set<Entry>;
|
||||
using IndexContainer = std::set<Entry>;
|
||||
|
||||
LabelIndex(Indices *indices, Config::Items config, const VertexValidator &vertex_validator)
|
||||
: indices_(indices), config_(config), vertex_validator_{&vertex_validator} {}
|
||||
|
||||
LabelIndex(Indices *indices, Config::Items config, const VertexValidator &vertex_validator,
|
||||
std::map<LabelId, LabelIndexContainer> &data)
|
||||
std::map<LabelId, IndexContainer> &data)
|
||||
: index_{std::move(data)}, indices_(indices), config_(config), vertex_validator_{&vertex_validator} {}
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
@ -67,12 +67,12 @@ class LabelIndex {
|
||||
|
||||
class Iterable {
|
||||
public:
|
||||
Iterable(LabelIndexContainer &index_container, LabelId label, View view, Transaction *transaction, Indices *indices,
|
||||
Iterable(IndexContainer &index_container, LabelId label, View view, Transaction *transaction, Indices *indices,
|
||||
Config::Items config, const VertexValidator &vertex_validator);
|
||||
|
||||
class Iterator {
|
||||
public:
|
||||
Iterator(Iterable *self, LabelIndexContainer::iterator index_iterator);
|
||||
Iterator(Iterable *self, IndexContainer::iterator index_iterator);
|
||||
|
||||
VertexAccessor operator*() const { return current_vertex_accessor_; }
|
||||
|
||||
@ -85,7 +85,7 @@ class LabelIndex {
|
||||
void AdvanceUntilValid();
|
||||
|
||||
Iterable *self_;
|
||||
LabelIndexContainer::iterator index_iterator_;
|
||||
IndexContainer::iterator index_iterator_;
|
||||
VertexAccessor current_vertex_accessor_;
|
||||
Vertex *current_vertex_;
|
||||
};
|
||||
@ -94,7 +94,7 @@ class LabelIndex {
|
||||
Iterator end() { return {this, index_container_->end()}; }
|
||||
|
||||
private:
|
||||
LabelIndexContainer *index_container_;
|
||||
IndexContainer *index_container_;
|
||||
LabelId label_;
|
||||
View view_;
|
||||
Transaction *transaction_;
|
||||
@ -120,10 +120,10 @@ class LabelIndex {
|
||||
|
||||
[[nodiscard]] bool Empty() const noexcept { return index_.empty(); }
|
||||
|
||||
std::map<LabelId, LabelIndexContainer> &GetIndex() { return index_; }
|
||||
std::map<LabelId, IndexContainer> &GetIndex() { return index_; }
|
||||
|
||||
private:
|
||||
std::map<LabelId, LabelIndexContainer> index_;
|
||||
std::map<LabelId, IndexContainer> index_;
|
||||
Indices *indices_;
|
||||
Config::Items config_;
|
||||
const VertexValidator *vertex_validator_;
|
||||
@ -143,7 +143,7 @@ class LabelPropertyIndex {
|
||||
bool operator==(const PropertyValue &rhs) const;
|
||||
};
|
||||
|
||||
using LabelPropertyIndexContainer = std::set<Entry>;
|
||||
using IndexContainer = std::set<Entry>;
|
||||
|
||||
LabelPropertyIndex(Indices *indices, Config::Items config, const VertexValidator &vertex_validator)
|
||||
: indices_(indices), config_(config), vertex_validator_{&vertex_validator} {}
|
||||
@ -167,14 +167,14 @@ class LabelPropertyIndex {
|
||||
|
||||
class Iterable {
|
||||
public:
|
||||
Iterable(LabelPropertyIndexContainer &index_container, LabelId label, PropertyId property,
|
||||
Iterable(IndexContainer &index_container, LabelId label, PropertyId property,
|
||||
const std::optional<utils::Bound<PropertyValue>> &lower_bound,
|
||||
const std::optional<utils::Bound<PropertyValue>> &upper_bound, View view, Transaction *transaction,
|
||||
Indices *indices, Config::Items config, const VertexValidator &vertex_validator);
|
||||
|
||||
class Iterator {
|
||||
public:
|
||||
Iterator(Iterable *self, LabelPropertyIndexContainer::iterator index_iterator);
|
||||
Iterator(Iterable *self, IndexContainer::iterator index_iterator);
|
||||
|
||||
VertexAccessor operator*() const { return current_vertex_accessor_; }
|
||||
|
||||
@ -187,7 +187,7 @@ class LabelPropertyIndex {
|
||||
void AdvanceUntilValid();
|
||||
|
||||
Iterable *self_;
|
||||
LabelPropertyIndexContainer::iterator index_iterator_;
|
||||
IndexContainer::iterator index_iterator_;
|
||||
VertexAccessor current_vertex_accessor_;
|
||||
Vertex *current_vertex_;
|
||||
};
|
||||
@ -196,7 +196,7 @@ class LabelPropertyIndex {
|
||||
Iterator end();
|
||||
|
||||
private:
|
||||
LabelPropertyIndexContainer *index_container_;
|
||||
IndexContainer *index_container_;
|
||||
LabelId label_;
|
||||
PropertyId property_;
|
||||
std::optional<utils::Bound<PropertyValue>> lower_bound_;
|
||||
@ -239,10 +239,10 @@ class LabelPropertyIndex {
|
||||
|
||||
[[nodiscard]] bool Empty() const noexcept { return index_.empty(); }
|
||||
|
||||
std::map<std::pair<LabelId, PropertyId>, LabelPropertyIndexContainer> &GetIndex() { return index_; }
|
||||
std::map<std::pair<LabelId, PropertyId>, IndexContainer> &GetIndex() { return index_; }
|
||||
|
||||
private:
|
||||
std::map<std::pair<LabelId, PropertyId>, LabelPropertyIndexContainer> index_;
|
||||
std::map<std::pair<LabelId, PropertyId>, IndexContainer> index_;
|
||||
Indices *indices_;
|
||||
Config::Items config_;
|
||||
const VertexValidator *vertex_validator_;
|
||||
|
@ -51,51 +51,6 @@ void Splitter::ScanDeltas(std::set<uint64_t> &collected_transactions_start_id, D
|
||||
}
|
||||
}
|
||||
|
||||
std::map<LabelId, LabelIndex::LabelIndexContainer> Splitter::CollectLabelIndices(
|
||||
const PrimaryKey &split_key,
|
||||
std::map<LabelId, std::multimap<const Vertex *, LabelIndex::Entry *>> &vertex_entry_map) {
|
||||
if (indices_.label_index.Empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Space O(i * n/2 * 2), i number of indexes, n number of vertices
|
||||
std::map<LabelId, LabelIndex::LabelIndexContainer> cloned_indices;
|
||||
for (auto &[label, index] : indices_.label_index.GetIndex()) {
|
||||
for (const auto &entry : index) {
|
||||
if (entry.vertex->first > split_key) {
|
||||
[[maybe_unused]] auto [it, inserted, node] = cloned_indices[label].insert(index.extract(entry));
|
||||
vertex_entry_map[label].insert({entry.vertex, &node.value()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cloned_indices;
|
||||
}
|
||||
|
||||
std::map<std::pair<LabelId, PropertyId>, LabelPropertyIndex::LabelPropertyIndexContainer>
|
||||
Splitter::CollectLabelPropertyIndices(
|
||||
const PrimaryKey &split_key,
|
||||
std::map<std::pair<LabelId, PropertyId>, std::multimap<const Vertex *, LabelPropertyIndex::Entry *>>
|
||||
&vertex_entry_map) {
|
||||
if (indices_.label_property_index.Empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::map<std::pair<LabelId, PropertyId>, LabelPropertyIndex::LabelPropertyIndexContainer> cloned_indices;
|
||||
for (auto &[label_prop_pair, index] : indices_.label_property_index.GetIndex()) {
|
||||
cloned_indices[label_prop_pair] = LabelPropertyIndex::LabelPropertyIndexContainer{};
|
||||
for (const auto &entry : index) {
|
||||
if (entry.vertex->first > split_key) {
|
||||
// We get this entry
|
||||
[[maybe_unused]] const auto [it, inserted, node] = cloned_indices[label_prop_pair].insert(index.extract(entry));
|
||||
vertex_entry_map[label_prop_pair].insert({entry.vertex, &node.value()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cloned_indices;
|
||||
}
|
||||
|
||||
VertexContainer Splitter::CollectVertices(SplitData &data, std::set<uint64_t> &collected_transactions_start_id,
|
||||
const PrimaryKey &split_key) {
|
||||
// Collection of indices is here since it heavily depends on vertices
|
||||
@ -103,8 +58,10 @@ VertexContainer Splitter::CollectVertices(SplitData &data, std::set<uint64_t> &c
|
||||
std::map<LabelId, std::multimap<const Vertex *, LabelIndex::Entry *>> label_index_vertex_entry_map;
|
||||
std::map<std::pair<LabelId, PropertyId>, std::multimap<const Vertex *, LabelPropertyIndex::Entry *>>
|
||||
label_property_vertex_entry_map;
|
||||
data.label_indices = CollectLabelIndices(split_key, label_index_vertex_entry_map);
|
||||
data.label_property_indices = CollectLabelPropertyIndices(split_key, label_property_vertex_entry_map);
|
||||
data.label_indices =
|
||||
CollectIndexEntries<LabelIndex, LabelId>(indices_.label_index, split_key, label_index_vertex_entry_map);
|
||||
data.label_property_indices = CollectIndexEntries<LabelPropertyIndex, std::pair<LabelId, PropertyId>>(
|
||||
indices_.label_property_index, split_key, label_property_vertex_entry_map);
|
||||
const auto update_indices = [](auto &index_map, const auto *old_vertex_ptr, auto &splitted_vertex_it) {
|
||||
for (auto &[label, vertex_entry_mappings] : index_map) {
|
||||
auto [it, end] = vertex_entry_mappings.equal_range(old_vertex_ptr);
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "storage/v3/indices.hpp"
|
||||
#include "storage/v3/transaction.hpp"
|
||||
#include "storage/v3/vertex.hpp"
|
||||
#include "utils/concepts.hpp"
|
||||
|
||||
namespace memgraph::storage::v3 {
|
||||
|
||||
@ -29,8 +30,8 @@ struct SplitData {
|
||||
VertexContainer vertices;
|
||||
std::optional<EdgeContainer> edges;
|
||||
std::map<uint64_t, Transaction> transactions;
|
||||
std::map<LabelId, LabelIndex::LabelIndexContainer> label_indices;
|
||||
std::map<std::pair<LabelId, PropertyId>, LabelPropertyIndex::LabelPropertyIndexContainer> label_property_indices;
|
||||
std::map<LabelId, LabelIndex::IndexContainer> label_indices;
|
||||
std::map<std::pair<LabelId, PropertyId>, LabelPropertyIndex::IndexContainer> label_property_indices;
|
||||
};
|
||||
|
||||
class Splitter final {
|
||||
@ -57,14 +58,30 @@ class Splitter final {
|
||||
std::optional<EdgeContainer> CollectEdges(std::set<uint64_t> &collected_transactions_start_id,
|
||||
const VertexContainer &split_vertices, const PrimaryKey &split_key);
|
||||
|
||||
std::map<LabelId, LabelIndex::LabelIndexContainer> CollectLabelIndices(
|
||||
const PrimaryKey &split_key,
|
||||
std::map<LabelId, std::multimap<const Vertex *, LabelIndex::Entry *>> &vertex_entry_map);
|
||||
template <typename IndexMap, typename IndexType>
|
||||
requires utils::SameAsAnyOf<IndexMap, LabelPropertyIndex, LabelIndex>
|
||||
std::map<IndexType, typename IndexMap::IndexContainer> CollectIndexEntries(
|
||||
IndexMap &index, const PrimaryKey &split_key,
|
||||
std::map<IndexType, std::multimap<const Vertex *, typename IndexMap::Entry *>> &vertex_entry_map) {
|
||||
if (index.Empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::map<std::pair<LabelId, PropertyId>, LabelPropertyIndex::LabelPropertyIndexContainer> CollectLabelPropertyIndices(
|
||||
const PrimaryKey &split_key,
|
||||
std::map<std::pair<LabelId, PropertyId>, std::multimap<const Vertex *, LabelPropertyIndex::Entry *>>
|
||||
&vertex_entry_map);
|
||||
std::map<IndexType, typename IndexMap::IndexContainer> cloned_indices;
|
||||
for (auto &[label_prop_pair, index] : index.GetIndex()) {
|
||||
cloned_indices[label_prop_pair] = typename IndexMap::IndexContainer{};
|
||||
for (const auto &entry : index) {
|
||||
if (entry.vertex->first > split_key) {
|
||||
// We get this entry
|
||||
[[maybe_unused]] const auto [it, inserted, node] =
|
||||
cloned_indices[label_prop_pair].insert(index.extract(entry));
|
||||
vertex_entry_map[label_prop_pair].insert({entry.vertex, &node.value()});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cloned_indices;
|
||||
}
|
||||
|
||||
static void ScanDeltas(std::set<uint64_t> &collected_transactions_start_id, Delta *delta);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user