From a2735c8953b531e1d0f9bbf7b348862444225bc2 Mon Sep 17 00:00:00 2001 From: jbajic Date: Wed, 9 Nov 2022 12:10:46 +0100 Subject: [PATCH 01/10] Add label add/remove in UpdateVertex req --- src/query/v2/requests.hpp | 8 +++--- src/storage/v3/shard_rsm.cpp | 47 +++++++++++++++++++++++++++++++++- tests/simulation/shard_rsm.cpp | 6 ++--- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/query/v2/requests.hpp b/src/query/v2/requests.hpp index 2ea4efb57..fe2851893 100644 --- a/src/query/v2/requests.hpp +++ b/src/query/v2/requests.hpp @@ -450,10 +450,12 @@ struct ExpandOneResponse { std::vector result; }; -struct UpdateVertexProp { +struct UpdateVertex { PrimaryKey primary_key; // This should be a map - std::vector> property_updates; + std::vector add_labels; + std::vector remove_labels; + std::map property_updates; }; struct UpdateEdgeProp { @@ -496,7 +498,7 @@ struct DeleteVerticesResponse { struct UpdateVerticesRequest { Hlc transaction_id; - std::vector new_properties; + std::vector update_vertices; }; struct UpdateVerticesResponse { diff --git a/src/storage/v3/shard_rsm.cpp b/src/storage/v3/shard_rsm.cpp index f288e5e27..bf66bc463 100644 --- a/src/storage/v3/shard_rsm.cpp +++ b/src/storage/v3/shard_rsm.cpp @@ -535,12 +535,46 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateVerticesRequest &&req) { return msgs::CreateVerticesResponse{.success = action_successful}; } +void HandleError(const ResultErrorType &error, const std::string_view action) { + std::visit( + [action](T &&error) { + using ErrorType = std::remove_cvref_t; + if constexpr (std::is_same_v) { + spdlog::debug("{} failed with error: SchemaViolation", action); + } else if constexpr (std::is_same_v) { + switch (error) { + case Error::DELETED_OBJECT: + spdlog::debug("{} failed with error: DELETED_OBJECT", action); + break; + case Error::NONEXISTENT_OBJECT: + spdlog::debug("{} failed with error: NONEXISTENT_OBJECT", action); + break; + case Error::SERIALIZATION_ERROR: + spdlog::debug("{} failed with error: SERIALIZATION_ERROR", action); + break; + case Error::PROPERTIES_DISABLED: + spdlog::debug("{} failed with error: PROPERTIES_DISABLED", action); + break; + case Error::VERTEX_HAS_EDGES: + spdlog::debug("{} failed with error: VERTEX_HAS_EDGES", action); + break; + case Error::VERTEX_ALREADY_INSERTED: + spdlog::debug("{} failed with error: VERTEX_ALREADY_INSERTED", action); + break; + } + } else { + static_assert(kAlwaysFalse, "Missing type from variant visitor"); + } + }, + error); +} + msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { auto acc = shard_->Access(req.transaction_id); bool action_successful = true; - for (auto &vertex : req.new_properties) { + for (auto &vertex : req.update_vertices) { if (!action_successful) { break; } @@ -553,6 +587,17 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { continue; } + for (const auto label : vertex.add_labels) { + if (const auto maybe_error = vertex_to_update->AddLabelAndValidate(label); maybe_error.HasError()) { + HandleError(maybe_error.GetError(), "Update Vertex"); + } + } + for (const auto label : vertex.remove_labels) { + if (const auto maybe_error = vertex_to_update->RemoveLabelAndValidate(label); maybe_error.HasError()) { + HandleError(maybe_error.GetError(), "Update Vertex"); + } + } + for (auto &update_prop : vertex.property_updates) { auto result_schema = vertex_to_update->SetPropertyAndValidate(update_prop.first, ToPropertyValue(std::move(update_prop.second))); diff --git a/tests/simulation/shard_rsm.cpp b/tests/simulation/shard_rsm.cpp index 64d0a0861..23dfecac1 100644 --- a/tests/simulation/shard_rsm.cpp +++ b/tests/simulation/shard_rsm.cpp @@ -189,13 +189,13 @@ bool AttemptToUpdateVertex(ShardClient &client, int64_t value) { std::vector> property_updates; auto property_update = std::make_pair(PropertyId::FromUint(5), msgs::Value(static_cast(10000))); - auto vertex_prop = msgs::UpdateVertexProp{}; + msgs::UpdateVertex vertex_prop; vertex_prop.primary_key = vertex_id; vertex_prop.property_updates = {property_update}; - auto update_req = msgs::UpdateVerticesRequest{}; + msgs::UpdateVerticesRequest update_req; update_req.transaction_id.logical_id = GetTransactionId(); - update_req.new_properties = {vertex_prop}; + update_req.update_vertices = {vertex_prop}; while (true) { auto write_res = client.SendWriteRequest(update_req); From 23f1536eac5e72fb4710bf1dd55168937842a3af Mon Sep 17 00:00:00 2001 From: jbajic Date: Wed, 9 Nov 2022 15:42:09 +0100 Subject: [PATCH 02/10] Add tests --- src/storage/v3/shard_rsm.cpp | 44 ++++-------------------------- tests/simulation/shard_rsm.cpp | 50 +++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/storage/v3/shard_rsm.cpp b/src/storage/v3/shard_rsm.cpp index bf66bc463..18e4a6911 100644 --- a/src/storage/v3/shard_rsm.cpp +++ b/src/storage/v3/shard_rsm.cpp @@ -590,6 +590,8 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { for (const auto label : vertex.add_labels) { if (const auto maybe_error = vertex_to_update->AddLabelAndValidate(label); maybe_error.HasError()) { HandleError(maybe_error.GetError(), "Update Vertex"); + action_successful = false; + break; } } for (const auto label : vertex.remove_labels) { @@ -599,45 +601,11 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { } for (auto &update_prop : vertex.property_updates) { - auto result_schema = - vertex_to_update->SetPropertyAndValidate(update_prop.first, ToPropertyValue(std::move(update_prop.second))); - if (result_schema.HasError()) { - auto &error = result_schema.GetError(); - - std::visit( - [](T &&error) { - using ErrorType = std::remove_cvref_t; - if constexpr (std::is_same_v) { - spdlog::debug("Updating vertex failed with error: SchemaViolation"); - } else if constexpr (std::is_same_v) { - switch (error) { - case Error::DELETED_OBJECT: - spdlog::debug("Updating vertex failed with error: DELETED_OBJECT"); - break; - case Error::NONEXISTENT_OBJECT: - spdlog::debug("Updating vertex failed with error: NONEXISTENT_OBJECT"); - break; - case Error::SERIALIZATION_ERROR: - spdlog::debug("Updating vertex failed with error: SERIALIZATION_ERROR"); - break; - case Error::PROPERTIES_DISABLED: - spdlog::debug("Updating vertex failed with error: PROPERTIES_DISABLED"); - break; - case Error::VERTEX_HAS_EDGES: - spdlog::debug("Updating vertex failed with error: VERTEX_HAS_EDGES"); - break; - case Error::VERTEX_ALREADY_INSERTED: - spdlog::debug("Updating vertex failed with error: VERTEX_ALREADY_INSERTED"); - break; - } - } else { - static_assert(kAlwaysFalse, "Missing type from variant visitor"); - } - }, - error); - + if (const auto result_schema = vertex_to_update->SetPropertyAndValidate( + update_prop.first, ToPropertyValue(std::move(update_prop.second))); + result_schema.HasError()) { + HandleError(result_schema.GetError(), "Update Vertex"); action_successful = false; - break; } } diff --git a/tests/simulation/shard_rsm.cpp b/tests/simulation/shard_rsm.cpp index 23dfecac1..500649f4c 100644 --- a/tests/simulation/shard_rsm.cpp +++ b/tests/simulation/shard_rsm.cpp @@ -183,19 +183,53 @@ bool AttemptToDeleteVertex(ShardClient &client, int64_t value) { } } -bool AttemptToUpdateVertex(ShardClient &client, int64_t value) { - auto vertex_id = GetValuePrimaryKeysWithValue(value)[0]; +bool AttemptToUpdateVertex(ShardClient &client, int64_t vertex_primary_key, std::vector add_labels = {}, + std::vector remove_labels = {}) { + auto vertex_id = GetValuePrimaryKeysWithValue(vertex_primary_key)[0]; std::vector> property_updates; auto property_update = std::make_pair(PropertyId::FromUint(5), msgs::Value(static_cast(10000))); - msgs::UpdateVertex vertex_prop; - vertex_prop.primary_key = vertex_id; - vertex_prop.property_updates = {property_update}; + msgs::UpdateVertex update_vertex; + update_vertex.primary_key = vertex_id; + update_vertex.property_updates = {property_update}; + update_vertex.add_labels = add_labels; + update_vertex.remove_labels = remove_labels; msgs::UpdateVerticesRequest update_req; update_req.transaction_id.logical_id = GetTransactionId(); - update_req.update_vertices = {vertex_prop}; + update_req.update_vertices = {update_vertex}; + + while (true) { + auto write_res = client.SendWriteRequest(update_req); + if (write_res.HasError()) { + continue; + } + + auto write_response_result = write_res.GetValue(); + auto write_response = std::get(write_response_result); + + Commit(client, update_req.transaction_id); + return write_response.success; + } +} + +bool AttemptToRemoveVertexProperty(ShardClient &client, int64_t primary_key, std::vector add_labels = {}, + std::vector remove_labels = {}) { + auto vertex_id = GetValuePrimaryKeysWithValue(primary_key)[0]; + + std::vector> property_updates; + auto property_update = std::make_pair(PropertyId::FromUint(5), msgs::Value()); + + msgs::UpdateVertex update_vertex; + update_vertex.primary_key = vertex_id; + update_vertex.property_updates = {property_update}; + update_vertex.add_labels = add_labels; + update_vertex.remove_labels = remove_labels; + + msgs::UpdateVerticesRequest update_req; + update_req.transaction_id.logical_id = GetTransactionId(); + update_req.update_vertices = {update_vertex}; while (true) { auto write_res = client.SendWriteRequest(update_req); @@ -872,7 +906,9 @@ void TestCreateAndUpdateVertices(ShardClient &client) { auto unique_prop_val = GetUniqueInteger(); MG_ASSERT(AttemptToCreateVertex(client, unique_prop_val)); - MG_ASSERT(AttemptToUpdateVertex(client, unique_prop_val)); + MG_ASSERT(AttemptToUpdateVertex(client, unique_prop_val, {LabelId::FromInt(3)})); + MG_ASSERT(AttemptToUpdateVertex(client, unique_prop_val, {}, {LabelId::FromInt(3)})); + MG_ASSERT(AttemptToRemoveVertexProperty(client, unique_prop_val)); } void TestCreateEdge(ShardClient &client) { From 691f6af36df13ca33793c4431a692190353f12b4 Mon Sep 17 00:00:00 2001 From: jbajic Date: Wed, 9 Nov 2022 15:52:08 +0100 Subject: [PATCH 03/10] Remove redundant code --- src/storage/v3/shard_rsm.cpp | 112 +++++++++++++---------------------- 1 file changed, 40 insertions(+), 72 deletions(-) diff --git a/src/storage/v3/shard_rsm.cpp b/src/storage/v3/shard_rsm.cpp index 18e4a6911..9f5c33218 100644 --- a/src/storage/v3/shard_rsm.cpp +++ b/src/storage/v3/shard_rsm.cpp @@ -318,6 +318,40 @@ bool FillEdges(const std::vector &edges, msgs::ExpandOneResultRow return true; } +void LogError(const ResultErrorType &error, const std::string_view action) { + std::visit( + [action](T &&error) { + using ErrorType = std::remove_cvref_t; + if constexpr (std::is_same_v) { + spdlog::debug("{} failed with error: SchemaViolation", action); + } else if constexpr (std::is_same_v) { + switch (error) { + case Error::DELETED_OBJECT: + spdlog::debug("{} failed with error: DELETED_OBJECT", action); + break; + case Error::NONEXISTENT_OBJECT: + spdlog::debug("{} failed with error: NONEXISTENT_OBJECT", action); + break; + case Error::SERIALIZATION_ERROR: + spdlog::debug("{} failed with error: SERIALIZATION_ERROR", action); + break; + case Error::PROPERTIES_DISABLED: + spdlog::debug("{} failed with error: PROPERTIES_DISABLED", action); + break; + case Error::VERTEX_HAS_EDGES: + spdlog::debug("{} failed with error: VERTEX_HAS_EDGES", action); + break; + case Error::VERTEX_ALREADY_INSERTED: + spdlog::debug("{} failed with error: VERTEX_ALREADY_INSERTED", action); + break; + } + } else { + static_assert(kAlwaysFalse, "Missing type from variant visitor"); + } + }, + error); +} + std::optional GetExpandOneResult( Shard::Accessor &acc, msgs::VertexId src_vertex, const msgs::ExpandOneRequest &req, const EdgeUniqunessFunction &maybe_filter_based_on_edge_uniquness, const EdgeFiller &edge_filler, @@ -490,42 +524,10 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateVerticesRequest &&req) { PrimaryKey transformed_pk; std::transform(new_vertex.primary_key.begin(), new_vertex.primary_key.end(), std::back_inserter(transformed_pk), [](msgs::Value &val) { return ToPropertyValue(std::move(val)); }); - auto result_schema = acc.CreateVertexAndValidate(converted_label_ids, transformed_pk, converted_property_map); - if (result_schema.HasError()) { - auto &error = result_schema.GetError(); - - std::visit( - [](T &&error) { - using ErrorType = std::remove_cvref_t; - if constexpr (std::is_same_v) { - spdlog::debug("Creating vertex failed with error: SchemaViolation"); - } else if constexpr (std::is_same_v) { - switch (error) { - case Error::DELETED_OBJECT: - spdlog::debug("Creating vertex failed with error: DELETED_OBJECT"); - break; - case Error::NONEXISTENT_OBJECT: - spdlog::debug("Creating vertex failed with error: NONEXISTENT_OBJECT"); - break; - case Error::SERIALIZATION_ERROR: - spdlog::debug("Creating vertex failed with error: SERIALIZATION_ERROR"); - break; - case Error::PROPERTIES_DISABLED: - spdlog::debug("Creating vertex failed with error: PROPERTIES_DISABLED"); - break; - case Error::VERTEX_HAS_EDGES: - spdlog::debug("Creating vertex failed with error: VERTEX_HAS_EDGES"); - break; - case Error::VERTEX_ALREADY_INSERTED: - spdlog::debug("Creating vertex failed with error: VERTEX_ALREADY_INSERTED"); - break; - } - } else { - static_assert(kAlwaysFalse, "Missing type from variant visitor"); - } - }, - error); + if (auto result_schema = acc.CreateVertexAndValidate(converted_label_ids, transformed_pk, converted_property_map); + result_schema.HasError()) { + LogError(result_schema.GetError(), "Creating Vertex"); action_successful = false; break; @@ -535,40 +537,6 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateVerticesRequest &&req) { return msgs::CreateVerticesResponse{.success = action_successful}; } -void HandleError(const ResultErrorType &error, const std::string_view action) { - std::visit( - [action](T &&error) { - using ErrorType = std::remove_cvref_t; - if constexpr (std::is_same_v) { - spdlog::debug("{} failed with error: SchemaViolation", action); - } else if constexpr (std::is_same_v) { - switch (error) { - case Error::DELETED_OBJECT: - spdlog::debug("{} failed with error: DELETED_OBJECT", action); - break; - case Error::NONEXISTENT_OBJECT: - spdlog::debug("{} failed with error: NONEXISTENT_OBJECT", action); - break; - case Error::SERIALIZATION_ERROR: - spdlog::debug("{} failed with error: SERIALIZATION_ERROR", action); - break; - case Error::PROPERTIES_DISABLED: - spdlog::debug("{} failed with error: PROPERTIES_DISABLED", action); - break; - case Error::VERTEX_HAS_EDGES: - spdlog::debug("{} failed with error: VERTEX_HAS_EDGES", action); - break; - case Error::VERTEX_ALREADY_INSERTED: - spdlog::debug("{} failed with error: VERTEX_ALREADY_INSERTED", action); - break; - } - } else { - static_assert(kAlwaysFalse, "Missing type from variant visitor"); - } - }, - error); -} - msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { auto acc = shard_->Access(req.transaction_id); @@ -589,14 +557,14 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { for (const auto label : vertex.add_labels) { if (const auto maybe_error = vertex_to_update->AddLabelAndValidate(label); maybe_error.HasError()) { - HandleError(maybe_error.GetError(), "Update Vertex"); + LogError(maybe_error.GetError(), "Update Vertex"); action_successful = false; break; } } for (const auto label : vertex.remove_labels) { if (const auto maybe_error = vertex_to_update->RemoveLabelAndValidate(label); maybe_error.HasError()) { - HandleError(maybe_error.GetError(), "Update Vertex"); + LogError(maybe_error.GetError(), "Update Vertex"); } } @@ -604,7 +572,7 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { if (const auto result_schema = vertex_to_update->SetPropertyAndValidate( update_prop.first, ToPropertyValue(std::move(update_prop.second))); result_schema.HasError()) { - HandleError(result_schema.GetError(), "Update Vertex"); + LogError(result_schema.GetError(), "Update Vertex"); action_successful = false; break; } From 8636788ab295a97a52ba8fcddebd528455e4fb46 Mon Sep 17 00:00:00 2001 From: jbajic Date: Wed, 9 Nov 2022 15:55:34 +0100 Subject: [PATCH 04/10] Fix typos --- src/storage/v3/shard_rsm.cpp | 30 ++++++++++++++---------------- tests/simulation/shard_rsm.cpp | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/storage/v3/shard_rsm.cpp b/src/storage/v3/shard_rsm.cpp index 9f5c33218..f59264725 100644 --- a/src/storage/v3/shard_rsm.cpp +++ b/src/storage/v3/shard_rsm.cpp @@ -57,11 +57,11 @@ using conversions::ToPropertyValue; namespace { namespace msgs = msgs; -using AllEdgePropertyDataSructure = std::map; -using SpecificEdgePropertyDataSructure = std::vector; +using AllEdgePropertyDataStructure = std::map; +using SpecificEdgePropertyDataStructure = std::vector; -using AllEdgeProperties = std::tuple; -using SpecificEdgeProperties = std::tuple; +using AllEdgeProperties = std::tuple; +using SpecificEdgeProperties = std::tuple; using SpecificEdgePropertiesVector = std::vector; using AllEdgePropertiesVector = std::vector; @@ -69,7 +69,7 @@ using AllEdgePropertiesVector = std::vector; using EdgeAccessors = std::vector; using EdgeFiller = std::function; -using EdgeUniqunessFunction = std::function; +using EdgeUniquenessFunction = std::function; struct VertexIdCmpr { bool operator()(const storage::v3::VertexId *lhs, const storage::v3::VertexId *rhs) const { return *lhs < *rhs; } @@ -180,8 +180,6 @@ std::vector EvaluateVertexExpressions(DbAccessor &dba, const VertexA return evaluated_expressions; } -struct LocalError {}; - std::optional> FillUpSourceVertexSecondaryLabels(const std::optional &v_acc, const msgs::ExpandOneRequest &req) { auto secondary_labels = v_acc->Labels(View::NEW); @@ -242,7 +240,7 @@ std::optional> FillUpSourceVertexProperties(const st std::optional, 2>> FillUpConnectingEdges( const std::optional &v_acc, const msgs::ExpandOneRequest &req, - const EdgeUniqunessFunction &maybe_filter_based_on_edge_uniquness) { + const EdgeUniquenessFunction &maybe_filter_based_on_edge_uniquness) { std::vector edge_types{}; edge_types.reserve(req.edge_types.size()); std::transform(req.edge_types.begin(), req.edge_types.end(), std::back_inserter(edge_types), @@ -296,11 +294,11 @@ std::optional, 2>> FillUpConnectingEdges( return std::array, 2>{in_edges, out_edges}; } -using AllEdgePropertyDataSructure = std::map; -using SpecificEdgePropertyDataSructure = std::vector; +using AllEdgePropertyDataStructure = std::map; +using SpecificEdgePropertyDataStructure = std::vector; -using AllEdgeProperties = std::tuple; -using SpecificEdgeProperties = std::tuple; +using AllEdgeProperties = std::tuple; +using SpecificEdgeProperties = std::tuple; using SpecificEdgePropertiesVector = std::vector; using AllEdgePropertiesVector = std::vector; @@ -354,7 +352,7 @@ void LogError(const ResultErrorType &error, const std::string_view action) { std::optional GetExpandOneResult( Shard::Accessor &acc, msgs::VertexId src_vertex, const msgs::ExpandOneRequest &req, - const EdgeUniqunessFunction &maybe_filter_based_on_edge_uniquness, const EdgeFiller &edge_filler, + const EdgeUniquenessFunction &maybe_filter_based_on_edge_uniquness, const EdgeFiller &edge_filler, const Schemas::Schema *schema) { /// Fill up source vertex const auto primary_key = ConvertPropertyVector(src_vertex.second); @@ -397,9 +395,9 @@ std::optional GetExpandOneResult( return result_row; } -EdgeUniqunessFunction InitializeEdgeUniqunessFunction(bool only_unique_neighbor_rows) { +EdgeUniquenessFunction InitializeEdgeUniquenessFunction(bool only_unique_neighbor_rows) { // Functions to select connecting edges based on uniquness - EdgeUniqunessFunction maybe_filter_based_on_edge_uniquness; + EdgeUniquenessFunction maybe_filter_based_on_edge_uniquness; if (only_unique_neighbor_rows) { maybe_filter_based_on_edge_uniquness = [](EdgeAccessors &&edges, @@ -871,7 +869,7 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) { std::vector results; - auto maybe_filter_based_on_edge_uniquness = InitializeEdgeUniqunessFunction(req.only_unique_neighbor_rows); + auto maybe_filter_based_on_edge_uniquness = InitializeEdgeUniquenessFunction(req.only_unique_neighbor_rows); auto edge_filler = InitializeEdgeFillerFunction(req); for (auto &src_vertex : req.src_vertices) { diff --git a/tests/simulation/shard_rsm.cpp b/tests/simulation/shard_rsm.cpp index 500649f4c..5405abd8d 100644 --- a/tests/simulation/shard_rsm.cpp +++ b/tests/simulation/shard_rsm.cpp @@ -906,7 +906,7 @@ void TestCreateAndUpdateVertices(ShardClient &client) { auto unique_prop_val = GetUniqueInteger(); MG_ASSERT(AttemptToCreateVertex(client, unique_prop_val)); - MG_ASSERT(AttemptToUpdateVertex(client, unique_prop_val, {LabelId::FromInt(3)})); + MG_ASSERT(AttemptToUpdateVertex(client, unique_prop_val, {LabelId::FromInt(3)}, {})); MG_ASSERT(AttemptToUpdateVertex(client, unique_prop_val, {}, {LabelId::FromInt(3)})); MG_ASSERT(AttemptToRemoveVertexProperty(client, unique_prop_val)); } From a03041956596fe2f4e0972d8de1dbf01c582be0f Mon Sep 17 00:00:00 2001 From: jbajic Date: Wed, 9 Nov 2022 16:07:27 +0100 Subject: [PATCH 05/10] Move LogResultError to helper --- src/storage/v3/request_helper.cpp | 34 +++++++++++++++++++++++++ src/storage/v3/request_helper.hpp | 5 ++++ src/storage/v3/shard_rsm.cpp | 42 +++---------------------------- src/storage/v3/shard_rsm.hpp | 3 --- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/storage/v3/request_helper.cpp b/src/storage/v3/request_helper.cpp index bb1c8bca4..5c0297581 100644 --- a/src/storage/v3/request_helper.cpp +++ b/src/storage/v3/request_helper.cpp @@ -79,4 +79,38 @@ std::vector::const_iterator GetStartOrderedElementsIterator(const std:: return ordered_elements.end(); } +void LogResultError(const ResultErrorType &error, const std::string_view action) { + std::visit( + [action](T &&error) { + using ErrorType = std::remove_cvref_t; + if constexpr (std::is_same_v) { + spdlog::debug("{} failed with error: SchemaViolation", action); + } else if constexpr (std::is_same_v) { + switch (error) { + case Error::DELETED_OBJECT: + spdlog::debug("{} failed with error: DELETED_OBJECT", action); + break; + case Error::NONEXISTENT_OBJECT: + spdlog::debug("{} failed with error: NONEXISTENT_OBJECT", action); + break; + case Error::SERIALIZATION_ERROR: + spdlog::debug("{} failed with error: SERIALIZATION_ERROR", action); + break; + case Error::PROPERTIES_DISABLED: + spdlog::debug("{} failed with error: PROPERTIES_DISABLED", action); + break; + case Error::VERTEX_HAS_EDGES: + spdlog::debug("{} failed with error: VERTEX_HAS_EDGES", action); + break; + case Error::VERTEX_ALREADY_INSERTED: + spdlog::debug("{} failed with error: VERTEX_ALREADY_INSERTED", action); + break; + } + } else { + static_assert(kAlwaysFalse, "Missing type from variant visitor"); + } + }, + error); +} + } // namespace memgraph::storage::v3 diff --git a/src/storage/v3/request_helper.hpp b/src/storage/v3/request_helper.hpp index 24ed40f8c..fc75f7717 100644 --- a/src/storage/v3/request_helper.hpp +++ b/src/storage/v3/request_helper.hpp @@ -18,6 +18,9 @@ namespace memgraph::storage::v3 { +template +constexpr auto kAlwaysFalse{false}; + inline bool TypedValueCompare(const TypedValue &a, const TypedValue &b) { // in ordering null comes after everything else // at the same time Null is not less that null @@ -113,4 +116,6 @@ VerticesIterable::Iterator GetStartVertexIterator(VerticesIterable &vertex_itera std::vector::const_iterator GetStartOrderedElementsIterator(const std::vector &ordered_elements, const std::vector &start_ids, View view); + +void LogResultError(const ResultErrorType &error, std::string_view action); } // namespace memgraph::storage::v3 diff --git a/src/storage/v3/shard_rsm.cpp b/src/storage/v3/shard_rsm.cpp index f59264725..67aefdda6 100644 --- a/src/storage/v3/shard_rsm.cpp +++ b/src/storage/v3/shard_rsm.cpp @@ -316,40 +316,6 @@ bool FillEdges(const std::vector &edges, msgs::ExpandOneResultRow return true; } -void LogError(const ResultErrorType &error, const std::string_view action) { - std::visit( - [action](T &&error) { - using ErrorType = std::remove_cvref_t; - if constexpr (std::is_same_v) { - spdlog::debug("{} failed with error: SchemaViolation", action); - } else if constexpr (std::is_same_v) { - switch (error) { - case Error::DELETED_OBJECT: - spdlog::debug("{} failed with error: DELETED_OBJECT", action); - break; - case Error::NONEXISTENT_OBJECT: - spdlog::debug("{} failed with error: NONEXISTENT_OBJECT", action); - break; - case Error::SERIALIZATION_ERROR: - spdlog::debug("{} failed with error: SERIALIZATION_ERROR", action); - break; - case Error::PROPERTIES_DISABLED: - spdlog::debug("{} failed with error: PROPERTIES_DISABLED", action); - break; - case Error::VERTEX_HAS_EDGES: - spdlog::debug("{} failed with error: VERTEX_HAS_EDGES", action); - break; - case Error::VERTEX_ALREADY_INSERTED: - spdlog::debug("{} failed with error: VERTEX_ALREADY_INSERTED", action); - break; - } - } else { - static_assert(kAlwaysFalse, "Missing type from variant visitor"); - } - }, - error); -} - std::optional GetExpandOneResult( Shard::Accessor &acc, msgs::VertexId src_vertex, const msgs::ExpandOneRequest &req, const EdgeUniquenessFunction &maybe_filter_based_on_edge_uniquness, const EdgeFiller &edge_filler, @@ -525,7 +491,7 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateVerticesRequest &&req) { if (auto result_schema = acc.CreateVertexAndValidate(converted_label_ids, transformed_pk, converted_property_map); result_schema.HasError()) { - LogError(result_schema.GetError(), "Creating Vertex"); + LogResultError(result_schema.GetError(), "Creating Vertex"); action_successful = false; break; @@ -555,14 +521,14 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { for (const auto label : vertex.add_labels) { if (const auto maybe_error = vertex_to_update->AddLabelAndValidate(label); maybe_error.HasError()) { - LogError(maybe_error.GetError(), "Update Vertex"); + LogResultError(maybe_error.GetError(), "Add vertex labels"); action_successful = false; break; } } for (const auto label : vertex.remove_labels) { if (const auto maybe_error = vertex_to_update->RemoveLabelAndValidate(label); maybe_error.HasError()) { - LogError(maybe_error.GetError(), "Update Vertex"); + LogResultError(maybe_error.GetError(), "Remove vertex labels"); } } @@ -570,7 +536,7 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { if (const auto result_schema = vertex_to_update->SetPropertyAndValidate( update_prop.first, ToPropertyValue(std::move(update_prop.second))); result_schema.HasError()) { - LogError(result_schema.GetError(), "Update Vertex"); + LogResultError(result_schema.GetError(), "Update vertex properties"); action_successful = false; break; } diff --git a/src/storage/v3/shard_rsm.hpp b/src/storage/v3/shard_rsm.hpp index 95cad99fd..d301bf40b 100644 --- a/src/storage/v3/shard_rsm.hpp +++ b/src/storage/v3/shard_rsm.hpp @@ -21,9 +21,6 @@ namespace memgraph::storage::v3 { -template -constexpr auto kAlwaysFalse = false; - class ShardRsm { std::unique_ptr shard_; From 6eabceca4aeab81e1104ba09309cd87b56bf6264 Mon Sep 17 00:00:00 2001 From: jbajic Date: Mon, 14 Nov 2022 09:02:55 +0100 Subject: [PATCH 06/10] Add unit tests for UpdateVertex --- src/storage/v3/shard_rsm.cpp | 4 +- tests/unit/CMakeLists.txt | 3 + tests/unit/storage_v3_shard_rsm.cpp | 317 ++++++++++++++++++++++++++++ 3 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 tests/unit/storage_v3_shard_rsm.cpp diff --git a/src/storage/v3/shard_rsm.cpp b/src/storage/v3/shard_rsm.cpp index 67aefdda6..3321754aa 100644 --- a/src/storage/v3/shard_rsm.cpp +++ b/src/storage/v3/shard_rsm.cpp @@ -529,6 +529,8 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { for (const auto label : vertex.remove_labels) { if (const auto maybe_error = vertex_to_update->RemoveLabelAndValidate(label); maybe_error.HasError()) { LogResultError(maybe_error.GetError(), "Remove vertex labels"); + action_successful = false; + break; } } @@ -536,8 +538,8 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { if (const auto result_schema = vertex_to_update->SetPropertyAndValidate( update_prop.first, ToPropertyValue(std::move(update_prop.second))); result_schema.HasError()) { - LogResultError(result_schema.GetError(), "Update vertex properties"); action_successful = false; + LogResultError(result_schema.GetError(), "Update vertex properties"); break; } } diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 0e5824318..b3c8ee06e 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -343,6 +343,9 @@ target_link_libraries(${test_prefix}storage_v3_edge mg-storage-v3) add_unit_test(storage_v3_isolation_level.cpp) target_link_libraries(${test_prefix}storage_v3_isolation_level mg-storage-v3) +add_unit_test(storage_v3_shard_rsm.cpp) +target_link_libraries(${test_prefix}storage_v3_shard_rsm mg-storage-v3) + add_unit_test(replication_persistence_helper.cpp) target_link_libraries(${test_prefix}replication_persistence_helper mg-storage-v2) diff --git a/tests/unit/storage_v3_shard_rsm.cpp b/tests/unit/storage_v3_shard_rsm.cpp new file mode 100644 index 000000000..a45a60db4 --- /dev/null +++ b/tests/unit/storage_v3_shard_rsm.cpp @@ -0,0 +1,317 @@ +// Copyright 2022 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "common/types.hpp" +#include "query/v2/requests.hpp" +#include "storage/v3/id_types.hpp" +#include "storage/v3/property_value.hpp" +#include "storage/v3/schema_validator.hpp" +#include "storage/v3/schemas.hpp" +#include "storage/v3/shard_rsm.hpp" +#include "storage/v3/storage.hpp" +#include "storage/v3/temporal.hpp" +#include "storage/v3/vertex_id.hpp" + +using testing::Pair; +using testing::UnorderedElementsAre; +using SchemaType = memgraph::common::SchemaType; + +namespace memgraph::storage::v3::tests { + +uint64_t GetTransactionId() { + static uint64_t transaction_id = 0; + return transaction_id++; +} + +class ShardRSMTest : public testing::Test { + private: + NameIdMapper id_mapper_{{{1, "primary_label"}, + {2, "primary_label2"}, + {3, "label"}, + {4, "primary_prop1"}, + {5, "primary_prop2"}, + {6, "prop"}}}; + + protected: + ShardRSMTest() { + PropertyValue min_pk(static_cast(0)); + std::vector min_prim_key = {min_pk}; + PropertyValue max_pk(static_cast(10000000)); + std::vector max_prim_key = {max_pk}; + + auto shard_ptr1 = std::make_unique(primary_label, min_prim_key, max_prim_key, std::vector{schema_prop}); + shard_ptr1->StoreMapping({{1, "primary_label"}, + {2, "primary_label2"}, + {3, "label"}, + {4, "primary_prop1"}, + {5, "primary_prop2"}, + {6, "prop"}}); + shard_ptr1->CreateSchema(primary_label2, {{primary_property2, SchemaType::INT}}); + shard_rsm = std::make_unique(std::move(shard_ptr1)); + } + + LabelId NameToLabel(const std::string &name) { return LabelId::FromUint(id_mapper_.NameToId(name)); } + + PropertyId NameToProperty(const std::string &name) { return PropertyId::FromUint(id_mapper_.NameToId(name)); } + + auto Commit(const auto &req) { + const coordinator::Hlc commit_timestamp{GetTransactionId()}; + msgs::CommitRequest commit_req; + commit_req.transaction_id = req.transaction_id; + commit_req.commit_timestamp = commit_timestamp; + return shard_rsm->Apply(commit_req); + } + + void CreateVertex(const msgs::PrimaryKey &primary_key, const std::vector labels, + const std::vector> &properties) { + msgs::NewVertex vertex = {labels, primary_key, properties}; + msgs::CreateVerticesRequest create_req; + create_req.new_vertices = {vertex}; + create_req.new_vertices = {vertex}; + create_req.transaction_id.logical_id = GetTransactionId(); + + auto write_res = shard_rsm->Apply(create_req); + ASSERT_TRUE(std::holds_alternative(write_res)); + + auto commit_res = Commit(create_req); + ASSERT_TRUE(std::holds_alternative(commit_res)); + ASSERT_TRUE(std::get(commit_res).success); + } + + void AssertVertexExists(const msgs::PrimaryKey &primary_key, const std::vector &labels, + const std::vector> &properties) { + msgs::ScanVerticesRequest scan_req; + scan_req.props_to_return = std::nullopt; + scan_req.start_id = msgs::VertexId{msgs::Label{.id = primary_label}, primary_key}; + scan_req.storage_view = msgs::StorageView::OLD; + scan_req.transaction_id.logical_id = GetTransactionId(); + + // Make request + auto maybe_read_res = shard_rsm->Read(scan_req); + ASSERT_TRUE(std::holds_alternative(maybe_read_res)); + const auto read_res = std::get(maybe_read_res); + EXPECT_TRUE(read_res.success); + EXPECT_EQ(read_res.results.size(), 1); + + // Read results + const auto res = read_res.results[0]; + const auto vtx_id = msgs::VertexId{msgs::Label{.id = primary_label}, primary_key}; + EXPECT_EQ(res.vertex.id, vtx_id); + EXPECT_EQ(res.vertex.labels, labels); + EXPECT_EQ(res.props, properties); + } + + LabelId primary_label{NameToLabel("primary_label")}; + LabelId primary_label2{NameToLabel("primary_label2")}; + LabelId label{NameToLabel("label")}; + PropertyId primary_property1{NameToProperty("primary_prop1")}; + PropertyId primary_property2{NameToProperty("primary_prop2")}; + PropertyId prop{NameToProperty("prop")}; + SchemaProperty schema_prop{primary_property1, SchemaType::INT}; + std::unique_ptr shard_rsm; +}; + +TEST_F(ShardRSMTest, TestUpdateVertexSecondaryProperty) { + const msgs::Value primary_key_val{static_cast(1)}; + const msgs::PrimaryKey pk{primary_key_val}; + + // Create Vertex + CreateVertex(pk, {}, {}); + + // Add property prop + static constexpr int64_t updated_vertex_id{10}; + { + msgs::UpdateVerticesRequest update_req; + update_req.transaction_id.logical_id = GetTransactionId(); + + update_req.update_vertices = + std::vector{{pk, {}, {}, {{msgs::PropertyId(prop), msgs::Value(updated_vertex_id)}}}}; + + const auto write_res = shard_rsm->Apply(update_req); + ASSERT_TRUE(std::holds_alternative(write_res)); + EXPECT_TRUE(std::get(write_res).success); + + const auto commit_res = Commit(update_req); + ASSERT_TRUE(std::holds_alternative(commit_res)); + EXPECT_TRUE(std::get(commit_res).success); + } + AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}, {prop, msgs::Value(updated_vertex_id)}}); + + // Update property prop + static constexpr int64_t updated_vertex_id_2{101}; + { + msgs::UpdateVerticesRequest update_req; + update_req.transaction_id.logical_id = GetTransactionId(); + + update_req.update_vertices = + std::vector{{pk, {}, {}, {{msgs::PropertyId(prop), msgs::Value(updated_vertex_id_2)}}}}; + + const auto write_res = shard_rsm->Apply(update_req); + ASSERT_TRUE(std::holds_alternative(write_res)); + ASSERT_TRUE(std::get(write_res).success); + + const auto commit_res = Commit(update_req); + ASSERT_TRUE(std::holds_alternative(commit_res)); + EXPECT_TRUE(std::get(commit_res).success); + AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}, {prop, msgs::Value(updated_vertex_id_2)}}); + } + AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}, {prop, msgs::Value(updated_vertex_id_2)}}); + + // Remove property prop + { + msgs::UpdateVerticesRequest update_req; + update_req.transaction_id.logical_id = GetTransactionId(); + + update_req.update_vertices = + std::vector{{pk, {}, {}, {{msgs::PropertyId(prop), msgs::Value()}}}}; + + const auto write_res = shard_rsm->Apply(update_req); + ASSERT_TRUE(std::holds_alternative(write_res)); + EXPECT_TRUE(std::get(write_res).success); + + const auto commit_res = Commit(update_req); + ASSERT_TRUE(std::holds_alternative(commit_res)); + EXPECT_TRUE(std::get(commit_res).success); + } + AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}}); +} + +TEST_F(ShardRSMTest, TestUpdateVertexPrimaryProperty) { + const msgs::Value primary_key_val{static_cast(1)}; + const msgs::PrimaryKey pk{primary_key_val}; + + // Create Vertex + CreateVertex(pk, {}, {}); + + // Try to update primary property + static constexpr int64_t updated_vertex_id{10}; + { + msgs::UpdateVerticesRequest update_req; + update_req.transaction_id.logical_id = GetTransactionId(); + + update_req.update_vertices = std::vector{ + {pk, {}, {}, {{msgs::PropertyId(primary_property1), msgs::Value(updated_vertex_id)}}}}; + + const auto write_res = shard_rsm->Apply(update_req); + ASSERT_TRUE(std::holds_alternative(write_res)); + EXPECT_FALSE(std::get(write_res).success); + } + AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}}); + // Try to update primary property of another schema + { + msgs::UpdateVerticesRequest update_req; + update_req.transaction_id.logical_id = GetTransactionId(); + + update_req.update_vertices = std::vector{ + {pk, {}, {}, {{msgs::PropertyId(primary_property2), msgs::Value(updated_vertex_id)}}}}; + + const auto write_res = shard_rsm->Apply(update_req); + ASSERT_TRUE(std::holds_alternative(write_res)); + EXPECT_TRUE(std::get(write_res).success); + + const auto commit_res = Commit(update_req); + ASSERT_TRUE(std::holds_alternative(commit_res)); + EXPECT_TRUE(std::get(commit_res).success); + } + AssertVertexExists(pk, {}, + {{primary_property1, primary_key_val}, {primary_property2, msgs::Value(updated_vertex_id)}}); +} + +TEST_F(ShardRSMTest, TestUpdateSecondaryLabel) { + const msgs::Value primary_key_val{static_cast(1)}; + const msgs::PrimaryKey pk{primary_key_val}; + + // Create Vertex + CreateVertex(pk, {}, {}); + + // Add label label + const msgs::Label secondary_label{label}; + { + msgs::UpdateVerticesRequest update_req; + update_req.transaction_id.logical_id = GetTransactionId(); + + update_req.update_vertices = std::vector{{pk, {label}, {}, {}}}; + + const auto write_res = shard_rsm->Apply(update_req); + ASSERT_TRUE(std::holds_alternative(write_res)); + ASSERT_TRUE(std::get(write_res).success); + + const auto commit_res = Commit(update_req); + ASSERT_TRUE(std::holds_alternative(commit_res)); + EXPECT_TRUE(std::get(commit_res).success); + } + AssertVertexExists(pk, {secondary_label}, {{primary_property1, primary_key_val}}); + + // Remove primary label + { + msgs::UpdateVerticesRequest update_req; + update_req.transaction_id.logical_id = GetTransactionId(); + + update_req.update_vertices = std::vector{{pk, {}, {label}, {}}}; + + const auto write_res = shard_rsm->Apply(update_req); + ASSERT_TRUE(std::holds_alternative(write_res)); + EXPECT_TRUE(std::get(write_res).success); + + const auto commit_res = Commit(update_req); + ASSERT_TRUE(std::holds_alternative(commit_res)); + EXPECT_TRUE(std::get(commit_res).success); + } + AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}}); +} + +TEST_F(ShardRSMTest, TestUpdatePrimaryLabel) { + const msgs::Value primary_key_val{static_cast(1)}; + const msgs::PrimaryKey pk{primary_key_val}; + + // Create Vertex + CreateVertex(pk, {}, {}); + + // Remove primary label + { + msgs::UpdateVerticesRequest update_req; + update_req.transaction_id.logical_id = GetTransactionId(); + + update_req.update_vertices = std::vector{{pk, {}, {primary_label}, {}}}; + + const auto write_res = shard_rsm->Apply(update_req); + ASSERT_TRUE(std::holds_alternative(write_res)); + EXPECT_FALSE(std::get(write_res).success); + } + AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}}); + + // Add different primary label + { + msgs::UpdateVerticesRequest update_req; + update_req.transaction_id.logical_id = GetTransactionId(); + + update_req.update_vertices = std::vector{{pk, {primary_label2}, {}, {}}}; + + const auto write_res = shard_rsm->Apply(update_req); + ASSERT_TRUE(std::holds_alternative(write_res)); + EXPECT_FALSE(std::get(write_res).success); + } + AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}}); +} + +} // namespace memgraph::storage::v3::tests From 0462b8fc8fd08a0d3d30a23e099422fd3395de50 Mon Sep 17 00:00:00 2001 From: jbajic Date: Mon, 14 Nov 2022 09:15:03 +0100 Subject: [PATCH 07/10] Address review comments --- src/query/v2/requests.hpp | 2 +- src/storage/v3/request_helper.cpp | 2 +- src/storage/v3/request_helper.hpp | 4 +--- src/utils/template_utils.hpp | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 src/utils/template_utils.hpp diff --git a/src/query/v2/requests.hpp b/src/query/v2/requests.hpp index fe2851893..356e2c0da 100644 --- a/src/query/v2/requests.hpp +++ b/src/query/v2/requests.hpp @@ -452,7 +452,7 @@ struct ExpandOneResponse { struct UpdateVertex { PrimaryKey primary_key; - // This should be a map + // Labels are first added and then removed from vertices std::vector add_labels; std::vector remove_labels; std::map property_updates; diff --git a/src/storage/v3/request_helper.cpp b/src/storage/v3/request_helper.cpp index 5c0297581..0be659c43 100644 --- a/src/storage/v3/request_helper.cpp +++ b/src/storage/v3/request_helper.cpp @@ -107,7 +107,7 @@ void LogResultError(const ResultErrorType &error, const std::string_view action) break; } } else { - static_assert(kAlwaysFalse, "Missing type from variant visitor"); + static_assert(utils::kAlwaysFalse, "Missing type from variant visitor"); } }, error); diff --git a/src/storage/v3/request_helper.hpp b/src/storage/v3/request_helper.hpp index fc75f7717..1d26e338d 100644 --- a/src/storage/v3/request_helper.hpp +++ b/src/storage/v3/request_helper.hpp @@ -15,12 +15,10 @@ #include "storage/v3/bindings/typed_value.hpp" #include "storage/v3/shard.hpp" #include "storage/v3/vertex_accessor.hpp" +#include "utils/template_utils.hpp" namespace memgraph::storage::v3 { -template -constexpr auto kAlwaysFalse{false}; - inline bool TypedValueCompare(const TypedValue &a, const TypedValue &b) { // in ordering null comes after everything else // at the same time Null is not less that null diff --git a/src/utils/template_utils.hpp b/src/utils/template_utils.hpp new file mode 100644 index 000000000..e84cbc652 --- /dev/null +++ b/src/utils/template_utils.hpp @@ -0,0 +1,18 @@ +// Copyright 2022 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. +#pragma once + +namespace memgraph::utils { + +template +constexpr auto kAlwaysFalse{false}; + +} // namespace memgraph::utils From b4c24f450609fdac9155860ca50490ff145147b0 Mon Sep 17 00:00:00 2001 From: jbajic Date: Mon, 14 Nov 2022 10:23:48 +0100 Subject: [PATCH 08/10] Remvoe storage.hpp and storage.cpp files --- src/query/v2/db_accessor.hpp | 2 +- src/query/v2/interpreter.cpp | 1 - src/storage/v3/CMakeLists.txt | 4 +-- src/storage/v3/shard_rsm.cpp | 1 - src/storage/v3/storage.cpp | 20 ----------- src/storage/v3/storage.hpp | 34 ------------------- tests/unit/query_v2_query_plan_common.hpp | 2 +- ...v2_query_plan_create_set_remove_delete.cpp | 2 +- tests/unit/query_v2_query_plan_edge_cases.cpp | 2 +- ...query_plan_v2_create_set_remove_delete.cpp | 2 +- tests/unit/result_stream_faker.hpp | 2 +- tests/unit/storage_v3_indices.cpp | 2 +- tests/unit/storage_v3_isolation_level.cpp | 2 +- tests/unit/storage_v3_schema.cpp | 2 +- tests/unit/storage_v3_test_utils.hpp | 2 +- 15 files changed, 11 insertions(+), 69 deletions(-) delete mode 100644 src/storage/v3/storage.cpp delete mode 100644 src/storage/v3/storage.hpp diff --git a/src/query/v2/db_accessor.hpp b/src/query/v2/db_accessor.hpp index b76da6131..29bbbb7fd 100644 --- a/src/query/v2/db_accessor.hpp +++ b/src/query/v2/db_accessor.hpp @@ -37,7 +37,7 @@ // This cannot be avoided by simple include orderings so we // simply undefine those macros as we're sure that libkrb5 // won't and can't be used anywhere in the query engine. -#include "storage/v3/storage.hpp" +#include "storage/v3/shard.hpp" #include "utils/logging.hpp" #include "utils/result.hpp" diff --git a/src/query/v2/interpreter.cpp b/src/query/v2/interpreter.cpp index c835c3d27..94a41aee5 100644 --- a/src/query/v2/interpreter.cpp +++ b/src/query/v2/interpreter.cpp @@ -47,7 +47,6 @@ #include "query/v2/shard_request_manager.hpp" #include "storage/v3/property_value.hpp" #include "storage/v3/shard.hpp" -#include "storage/v3/storage.hpp" #include "utils/algorithm.hpp" #include "utils/csv_parsing.hpp" #include "utils/event_counter.hpp" diff --git a/src/storage/v3/CMakeLists.txt b/src/storage/v3/CMakeLists.txt index 0f359c702..5a824534b 100644 --- a/src/storage/v3/CMakeLists.txt +++ b/src/storage/v3/CMakeLists.txt @@ -16,12 +16,10 @@ set(storage_v3_src_files schemas.cpp schema_validator.cpp shard.cpp - storage.cpp shard_rsm.cpp bindings/typed_value.cpp expr.cpp - request_helper.cpp - storage.cpp) + request_helper.cpp) # ###################### find_package(gflags REQUIRED) diff --git a/src/storage/v3/shard_rsm.cpp b/src/storage/v3/shard_rsm.cpp index f288e5e27..5215db6c3 100644 --- a/src/storage/v3/shard_rsm.cpp +++ b/src/storage/v3/shard_rsm.cpp @@ -37,7 +37,6 @@ #include "storage/v3/schemas.hpp" #include "storage/v3/shard.hpp" #include "storage/v3/shard_rsm.hpp" -#include "storage/v3/storage.hpp" #include "storage/v3/value_conversions.hpp" #include "storage/v3/vertex_accessor.hpp" #include "storage/v3/vertex_id.hpp" diff --git a/src/storage/v3/storage.cpp b/src/storage/v3/storage.cpp deleted file mode 100644 index 28fd8b330..000000000 --- a/src/storage/v3/storage.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2022 Memgraph Ltd. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source -// License, and you may not use this file except in compliance with the Business Source License. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -#include "storage/v3/storage.hpp" - -#include "storage/v3/config.hpp" - -namespace memgraph::storage::v3 { - -Storage::Storage(Config config) : config_{config} {} - -} // namespace memgraph::storage::v3 diff --git a/src/storage/v3/storage.hpp b/src/storage/v3/storage.hpp deleted file mode 100644 index 9305ba707..000000000 --- a/src/storage/v3/storage.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2022 Memgraph Ltd. -// -// Use of this software is governed by the Business Source License -// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source -// License, and you may not use this file except in compliance with the Business Source License. -// -// As of the Change Date specified in that file, in accordance with -// the Business Source License, use of this software will be governed -// by the Apache License, Version 2.0, included in the file -// licenses/APL.txt. - -#pragma once - -#include - -#include - -#include "storage/v3/shard.hpp" - -namespace memgraph::storage::v3 { - -class Storage { - public: - explicit Storage(Config config); - // Interface toward shard manipulation - // Shard handler -> will use rsm client - - private: - std::vector shards_; - boost::asio::thread_pool shard_handlers_; - Config config_; -}; - -} // namespace memgraph::storage::v3 diff --git a/tests/unit/query_v2_query_plan_common.hpp b/tests/unit/query_v2_query_plan_common.hpp index c74f65f60..4f6c1a539 100644 --- a/tests/unit/query_v2_query_plan_common.hpp +++ b/tests/unit/query_v2_query_plan_common.hpp @@ -21,7 +21,7 @@ #include "query/v2/context.hpp" #include "query/v2/db_accessor.hpp" #include "query/v2/plan/operator.hpp" -#include "storage/v3/storage.hpp" +#include "storage/v3/shard.hpp" #include "utils/logging.hpp" #include "query_v2_query_common.hpp" diff --git a/tests/unit/query_v2_query_plan_create_set_remove_delete.cpp b/tests/unit/query_v2_query_plan_create_set_remove_delete.cpp index 78ccc281e..2487e378e 100644 --- a/tests/unit/query_v2_query_plan_create_set_remove_delete.cpp +++ b/tests/unit/query_v2_query_plan_create_set_remove_delete.cpp @@ -30,7 +30,7 @@ #include "storage/v3/id_types.hpp" #include "storage/v3/property_value.hpp" #include "storage/v3/schemas.hpp" -#include "storage/v3/storage.hpp" +#include "storage/v3/shard.hpp" #include "storage/v3/vertex.hpp" #include "storage/v3/view.hpp" diff --git a/tests/unit/query_v2_query_plan_edge_cases.cpp b/tests/unit/query_v2_query_plan_edge_cases.cpp index cf268bc27..2d0a0eef2 100644 --- a/tests/unit/query_v2_query_plan_edge_cases.cpp +++ b/tests/unit/query_v2_query_plan_edge_cases.cpp @@ -21,7 +21,7 @@ #include "query/v2/interpreter.hpp" #include "result_stream_faker.hpp" -#include "storage/v3/storage.hpp" +#include "storage/v3/shard.hpp" DECLARE_bool(query_cost_planner); diff --git a/tests/unit/query_v2_query_plan_v2_create_set_remove_delete.cpp b/tests/unit/query_v2_query_plan_v2_create_set_remove_delete.cpp index 277ca5b6f..c5c9e2001 100644 --- a/tests/unit/query_v2_query_plan_v2_create_set_remove_delete.cpp +++ b/tests/unit/query_v2_query_plan_v2_create_set_remove_delete.cpp @@ -15,7 +15,7 @@ #include "query/v2/plan/operator.hpp" #include "query_v2_query_plan_common.hpp" #include "storage/v3/property_value.hpp" -#include "storage/v3/storage.hpp" +#include "storage/v3/shard.hpp" namespace memgraph::query::v2::tests { diff --git a/tests/unit/result_stream_faker.hpp b/tests/unit/result_stream_faker.hpp index 4aa6a3e1d..b8362db75 100644 --- a/tests/unit/result_stream_faker.hpp +++ b/tests/unit/result_stream_faker.hpp @@ -16,7 +16,7 @@ #include "glue/v2/communication.hpp" #include "query/v2/bindings/typed_value.hpp" -#include "storage/v3/storage.hpp" +#include "storage/v3/shard.hpp" #include "utils/algorithm.hpp" /** diff --git a/tests/unit/storage_v3_indices.cpp b/tests/unit/storage_v3_indices.cpp index 7ff3fa43b..620878fcf 100644 --- a/tests/unit/storage_v3_indices.cpp +++ b/tests/unit/storage_v3_indices.cpp @@ -18,7 +18,7 @@ #include "storage/v3/id_types.hpp" #include "storage/v3/name_id_mapper.hpp" #include "storage/v3/property_value.hpp" -#include "storage/v3/storage.hpp" +#include "storage/v3/shard.hpp" #include "storage/v3/temporal.hpp" #include "storage/v3/view.hpp" diff --git a/tests/unit/storage_v3_isolation_level.cpp b/tests/unit/storage_v3_isolation_level.cpp index 2fe259c00..6b661f632 100644 --- a/tests/unit/storage_v3_isolation_level.cpp +++ b/tests/unit/storage_v3_isolation_level.cpp @@ -13,7 +13,7 @@ #include "storage/v3/isolation_level.hpp" #include "storage/v3/property_value.hpp" -#include "storage/v3/storage.hpp" +#include "storage/v3/shard.hpp" namespace memgraph::storage::v3::tests { int64_t VerticesCount(Shard::Accessor &accessor) { diff --git a/tests/unit/storage_v3_schema.cpp b/tests/unit/storage_v3_schema.cpp index c36b92bc3..5c0d6f1dc 100644 --- a/tests/unit/storage_v3_schema.cpp +++ b/tests/unit/storage_v3_schema.cpp @@ -23,7 +23,7 @@ #include "storage/v3/property_value.hpp" #include "storage/v3/schema_validator.hpp" #include "storage/v3/schemas.hpp" -#include "storage/v3/storage.hpp" +#include "storage/v3/shard.hpp" #include "storage/v3/temporal.hpp" using testing::Pair; diff --git a/tests/unit/storage_v3_test_utils.hpp b/tests/unit/storage_v3_test_utils.hpp index 7cbb7414b..921df0a99 100644 --- a/tests/unit/storage_v3_test_utils.hpp +++ b/tests/unit/storage_v3_test_utils.hpp @@ -11,7 +11,7 @@ #pragma once -#include "storage/v3/storage.hpp" +#include "storage/v3/shard.hpp" #include "storage/v3/view.hpp" namespace memgraph::storage::v3::tests { From a9c5d4072173c375db2ed85c2fd172a523aaea03 Mon Sep 17 00:00:00 2001 From: Jure Bajic Date: Mon, 14 Nov 2022 10:32:18 +0100 Subject: [PATCH 09/10] Update src/utils/template_utils.hpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: János Benjamin Antal --- src/utils/template_utils.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/template_utils.hpp b/src/utils/template_utils.hpp index e84cbc652..4065283b2 100644 --- a/src/utils/template_utils.hpp +++ b/src/utils/template_utils.hpp @@ -8,6 +8,7 @@ // the Business Source License, use of this software will be governed // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. + #pragma once namespace memgraph::utils { From 9b19dd57d3d3c9347be8b00879e30abaf4668ccf Mon Sep 17 00:00:00 2001 From: jbajic Date: Wed, 23 Nov 2022 13:19:25 +0100 Subject: [PATCH 10/10] Remove storage include --- tests/unit/storage_v3_shard_rsm.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/storage_v3_shard_rsm.cpp b/tests/unit/storage_v3_shard_rsm.cpp index a45a60db4..6f8e31d03 100644 --- a/tests/unit/storage_v3_shard_rsm.cpp +++ b/tests/unit/storage_v3_shard_rsm.cpp @@ -28,7 +28,6 @@ #include "storage/v3/schema_validator.hpp" #include "storage/v3/schemas.hpp" #include "storage/v3/shard_rsm.hpp" -#include "storage/v3/storage.hpp" #include "storage/v3/temporal.hpp" #include "storage/v3/vertex_id.hpp"