Move out index splitting
This commit is contained in:
parent
78b5731a0e
commit
96ac7bd1c5
@ -18,6 +18,8 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "storage/v3/config.hpp"
|
#include "storage/v3/config.hpp"
|
||||||
|
#include "storage/v3/id_types.hpp"
|
||||||
|
#include "storage/v3/key_store.hpp"
|
||||||
#include "storage/v3/property_value.hpp"
|
#include "storage/v3/property_value.hpp"
|
||||||
#include "storage/v3/transaction.hpp"
|
#include "storage/v3/transaction.hpp"
|
||||||
#include "storage/v3/vertex_accessor.hpp"
|
#include "storage/v3/vertex_accessor.hpp"
|
||||||
@ -40,6 +42,8 @@ class LabelIndex {
|
|||||||
bool operator==(const Entry &rhs) const { return vertex == rhs.vertex && timestamp == rhs.timestamp; }
|
bool operator==(const Entry &rhs) const { return vertex == rhs.vertex && timestamp == rhs.timestamp; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using IndexType = LabelId;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using IndexContainer = std::set<Entry>;
|
using IndexContainer = std::set<Entry>;
|
||||||
|
|
||||||
@ -118,9 +122,36 @@ class LabelIndex {
|
|||||||
|
|
||||||
void Clear() { index_.clear(); }
|
void Clear() { index_.clear(); }
|
||||||
|
|
||||||
[[nodiscard]] bool Empty() const noexcept { return index_.empty(); }
|
std::map<IndexType, IndexContainer> SplitIndexEntries(
|
||||||
|
const PrimaryKey &split_key,
|
||||||
|
std::map<IndexType, std::multimap<const Vertex *, const IndexContainer::iterator>> &vertex_entry_map) {
|
||||||
|
if (index_.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
std::map<LabelId, IndexContainer> &GetIndex() noexcept { return index_; }
|
// Cloned index entries will contain new index entry iterators, but old
|
||||||
|
// vertices address which need to be adjusted after extracting vertices
|
||||||
|
std::map<IndexType, IndexContainer> cloned_indices;
|
||||||
|
for (auto &[index_type_val, index] : index_) {
|
||||||
|
auto entry_it = index.begin();
|
||||||
|
auto &cloned_indices_container = cloned_indices[index_type_val];
|
||||||
|
while (entry_it != index.end()) {
|
||||||
|
// We need to save the next pointer since the current one will be
|
||||||
|
// invalidated after extract
|
||||||
|
auto next_entry_it = std::next(entry_it);
|
||||||
|
if (entry_it->vertex->first > split_key) {
|
||||||
|
[[maybe_unused]] const auto &[inserted_entry_it, inserted, node] =
|
||||||
|
cloned_indices_container.insert(index.extract(entry_it));
|
||||||
|
MG_ASSERT(inserted, "Failed to extract index entry!");
|
||||||
|
|
||||||
|
vertex_entry_map[index_type_val].insert({inserted_entry_it->vertex, inserted_entry_it});
|
||||||
|
}
|
||||||
|
entry_it = next_entry_it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cloned_indices;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<LabelId, IndexContainer> index_;
|
std::map<LabelId, IndexContainer> index_;
|
||||||
@ -141,6 +172,7 @@ class LabelPropertyIndex {
|
|||||||
bool operator<(const PropertyValue &rhs) const;
|
bool operator<(const PropertyValue &rhs) const;
|
||||||
bool operator==(const PropertyValue &rhs) const;
|
bool operator==(const PropertyValue &rhs) const;
|
||||||
};
|
};
|
||||||
|
using IndexType = std::pair<LabelId, PropertyId>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using IndexContainer = std::set<Entry>;
|
using IndexContainer = std::set<Entry>;
|
||||||
@ -237,9 +269,36 @@ class LabelPropertyIndex {
|
|||||||
|
|
||||||
void Clear() { index_.clear(); }
|
void Clear() { index_.clear(); }
|
||||||
|
|
||||||
[[nodiscard]] bool Empty() const noexcept { return index_.empty(); }
|
std::map<IndexType, IndexContainer> SplitIndexEntries(
|
||||||
|
const PrimaryKey &split_key,
|
||||||
|
std::map<IndexType, std::multimap<const Vertex *, const IndexContainer::iterator>> &vertex_entry_map) {
|
||||||
|
if (index_.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
std::map<std::pair<LabelId, PropertyId>, IndexContainer> &GetIndex() noexcept { return index_; }
|
// Cloned index entries will contain new index entry iterators, but old
|
||||||
|
// vertices address which need to be adjusted after extracting vertices
|
||||||
|
std::map<IndexType, IndexContainer> cloned_indices;
|
||||||
|
for (auto &[index_type_val, index] : index_) {
|
||||||
|
auto entry_it = index.begin();
|
||||||
|
auto &cloned_index_container = cloned_indices[index_type_val];
|
||||||
|
while (entry_it != index.end()) {
|
||||||
|
// We need to save the next pointer since the current one will be
|
||||||
|
// invalidated after extract
|
||||||
|
auto next_entry_it = std::next(entry_it);
|
||||||
|
if (entry_it->vertex->first > split_key) {
|
||||||
|
[[maybe_unused]] const auto &[inserted_entry_it, inserted, node] =
|
||||||
|
cloned_index_container.insert(index.extract(entry_it));
|
||||||
|
MG_ASSERT(inserted, "Failed to extract index entry!");
|
||||||
|
|
||||||
|
vertex_entry_map[index_type_val].insert({inserted_entry_it->vertex, inserted_entry_it});
|
||||||
|
}
|
||||||
|
entry_it = next_entry_it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cloned_indices;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::pair<LabelId, PropertyId>, IndexContainer> index_;
|
std::map<std::pair<LabelId, PropertyId>, IndexContainer> index_;
|
||||||
|
@ -77,10 +77,9 @@ VertexContainer Splitter::CollectVertices(SplitData &data, std::set<uint64_t> &c
|
|||||||
std::multimap<const Vertex *, const LabelPropertyIndex::IndexContainer::iterator>>
|
std::multimap<const Vertex *, const LabelPropertyIndex::IndexContainer::iterator>>
|
||||||
label_property_vertex_entry_map;
|
label_property_vertex_entry_map;
|
||||||
|
|
||||||
data.label_indices =
|
data.label_indices = indices_.label_index.SplitIndexEntries(split_key, label_index_vertex_entry_map);
|
||||||
CollectIndexEntries<LabelIndex, LabelId>(indices_.label_index, split_key, label_index_vertex_entry_map);
|
data.label_property_indices =
|
||||||
data.label_property_indices = CollectIndexEntries<LabelPropertyIndex, std::pair<LabelId, PropertyId>>(
|
indices_.label_property_index.SplitIndexEntries(split_key, label_property_vertex_entry_map);
|
||||||
indices_.label_property_index, split_key, label_property_vertex_entry_map);
|
|
||||||
// This is needed to replace old vertex pointers in index entries with new ones
|
// This is needed to replace old vertex pointers in index entries with new ones
|
||||||
const auto update_indices = [](auto &entry_vertex_map, auto &updating_index, const auto *old_vertex_ptr,
|
const auto update_indices = [](auto &entry_vertex_map, auto &updating_index, const auto *old_vertex_ptr,
|
||||||
auto &new_vertex_ptr) {
|
auto &new_vertex_ptr) {
|
||||||
|
@ -74,39 +74,6 @@ class Splitter final {
|
|||||||
const std::set<uint64_t> &collected_transactions_start_id, VertexContainer &cloned_vertices,
|
const std::set<uint64_t> &collected_transactions_start_id, VertexContainer &cloned_vertices,
|
||||||
EdgeContainer &cloned_edges);
|
EdgeContainer &cloned_edges);
|
||||||
|
|
||||||
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 *, const typename IndexMap::IndexContainer::iterator>>
|
|
||||||
&vertex_entry_map) {
|
|
||||||
if (index.Empty()) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cloned index entries will contain new index entry iterators, but old
|
|
||||||
// vertices address which need to be adjusted after extracting vertices
|
|
||||||
std::map<IndexType, typename IndexMap::IndexContainer> cloned_indices;
|
|
||||||
for (auto &[index_type_val, index] : index.GetIndex()) {
|
|
||||||
auto entry_it = index.begin();
|
|
||||||
while (entry_it != index.end()) {
|
|
||||||
// We need to save the next pointer since the current one will be
|
|
||||||
// invalidated after extract
|
|
||||||
auto next_entry_it = std::next(entry_it);
|
|
||||||
if (entry_it->vertex->first > split_key) {
|
|
||||||
[[maybe_unused]] const auto &[inserted_entry_it, inserted, node] =
|
|
||||||
cloned_indices[index_type_val].insert(index.extract(entry_it));
|
|
||||||
MG_ASSERT(inserted, "Failed to extract index entry!");
|
|
||||||
|
|
||||||
vertex_entry_map[index_type_val].insert({inserted_entry_it->vertex, inserted_entry_it});
|
|
||||||
}
|
|
||||||
entry_it = next_entry_it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return cloned_indices;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ScanDeltas(std::set<uint64_t> &collected_transactions_start_id, Delta *delta);
|
static void ScanDeltas(std::set<uint64_t> &collected_transactions_start_id, Delta *delta);
|
||||||
|
|
||||||
static void AdjustClonedTransaction(Transaction &cloned_transaction, const Transaction &transaction,
|
static void AdjustClonedTransaction(Transaction &cloned_transaction, const Transaction &transaction,
|
||||||
|
Loading…
Reference in New Issue
Block a user