From 730bac6b74b4bc948c3a5b3975b7a0cbc4b76b69 Mon Sep 17 00:00:00 2001 From: jbajic Date: Thu, 1 Dec 2022 14:32:33 +0100 Subject: [PATCH] Replace edges skiplist --- ...{vertices_container.hpp => containers.hpp} | 3 +++ src/storage/v3/shard.cpp | 21 ++++++++----------- src/storage/v3/shard.hpp | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) rename src/storage/v3/{vertices_container.hpp => containers.hpp} (87%) diff --git a/src/storage/v3/vertices_container.hpp b/src/storage/v3/containers.hpp similarity index 87% rename from src/storage/v3/vertices_container.hpp rename to src/storage/v3/containers.hpp index c67f78efd..918cf3568 100644 --- a/src/storage/v3/vertices_container.hpp +++ b/src/storage/v3/containers.hpp @@ -13,9 +13,12 @@ #include +#include "storage/v3/edge.hpp" +#include "storage/v3/id_types.hpp" #include "storage/v3/key_store.hpp" #include "storage/v3/vertex.hpp" namespace memgraph::storage::v3 { using VertexContainer = std::map; +using EdgeContainer = std::map; } // namespace memgraph::storage::v3 diff --git a/src/storage/v3/shard.cpp b/src/storage/v3/shard.cpp index cde51739a..a77f42a76 100644 --- a/src/storage/v3/shard.cpp +++ b/src/storage/v3/shard.cpp @@ -26,6 +26,7 @@ #include "io/network/endpoint.hpp" #include "io/time.hpp" +#include "storage/v3/containers.hpp" #include "storage/v3/edge_accessor.hpp" #include "storage/v3/id_types.hpp" #include "storage/v3/indices.hpp" @@ -38,7 +39,6 @@ #include "storage/v3/transaction.hpp" #include "storage/v3/vertex.hpp" #include "storage/v3/vertex_accessor.hpp" -#include "storage/v3/vertices_container.hpp" #include "utils/exceptions.hpp" #include "utils/file.hpp" #include "utils/logging.hpp" @@ -514,13 +514,12 @@ ShardResult Shard::Accessor::CreateEdge(VertexId from_vertex_id, V EdgeRef edge(gid); if (config_.properties_on_edges) { - auto acc = shard_->edges_.access(); auto *delta = CreateDeleteObjectDelta(transaction_); - auto [it, inserted] = acc.insert(Edge(gid, delta)); + auto [it, inserted] = shard_->edges_.emplace(gid, Edge{gid, delta}); MG_ASSERT(inserted, "The edge must be inserted here!"); - MG_ASSERT(it != acc.end(), "Invalid Edge accessor!"); - edge = EdgeRef(&*it); - delta->prev.Set(&*it); + MG_ASSERT(it != shard_->edges_.end(), "Invalid Edge accessor!"); + edge = EdgeRef(&it->second); + delta->prev.Set(&it->second); } if (from_is_local) { @@ -579,10 +578,9 @@ ShardResult> Shard::Accessor::DeleteEdge(VertexId fr if (!config_.properties_on_edges) { return EdgeRef(edge_id); } - auto edge_acc = shard_->edges_.access(); - auto res = edge_acc.find(edge_id); - MG_ASSERT(res != edge_acc.end(), "Cannot find edge"); - return EdgeRef(&*res); + auto res = shard_->edges_.find(edge_id); + MG_ASSERT(res != shard_->edges_.end(), "Cannot find edge"); + return EdgeRef(&res->second); }); std::optional edge_type{}; @@ -1021,9 +1019,8 @@ void Shard::CollectGarbage(const io::Time current_time) { } deleted_vertices_.clear(); { - auto edge_acc = edges_.access(); for (auto edge : deleted_edges_) { - MG_ASSERT(edge_acc.remove(edge), "Invalid database state!"); + MG_ASSERT(edges_.erase(edge), "Invalid database state!"); } } deleted_edges_.clear(); diff --git a/src/storage/v3/shard.hpp b/src/storage/v3/shard.hpp index 858dd351e..d41ca3105 100644 --- a/src/storage/v3/shard.hpp +++ b/src/storage/v3/shard.hpp @@ -25,6 +25,7 @@ #include "io/time.hpp" #include "kvstore/kvstore.hpp" #include "storage/v3/config.hpp" +#include "storage/v3/containers.hpp" #include "storage/v3/edge.hpp" #include "storage/v3/edge_accessor.hpp" #include "storage/v3/id_types.hpp" @@ -41,7 +42,6 @@ #include "storage/v3/vertex.hpp" #include "storage/v3/vertex_accessor.hpp" #include "storage/v3/vertex_id.hpp" -#include "storage/v3/vertices_container.hpp" #include "storage/v3/view.hpp" #include "utils/exceptions.hpp" #include "utils/file_locker.hpp" @@ -374,7 +374,7 @@ class Shard final { PrimaryKey min_primary_key_; std::optional max_primary_key_; VertexContainer vertices_; - utils::SkipList edges_; + EdgeContainer edges_; // Even though the edge count is already kept in the `edges_` SkipList, the // list is used only when properties are enabled for edges. Because of that we // keep a separate count of edges that is always updated.