From 39b40ecf00eb31befdbe14c44ca8af57361b57c4 Mon Sep 17 00:00:00 2001 From: gvolfing Date: Mon, 7 Nov 2022 10:00:34 +0100 Subject: [PATCH] Extend the Error enum instead of a separate type The error representing that a vertex is already inserted into the skip-list was represented by the struct AlreadyInseertedElement. Instead of using that struct, extend the memgraph::storage::v3::Error scoped enum and use that to represent the double-insertion error. --- src/expr/interpret/eval.hpp | 3 ++ src/memgraph.cpp | 2 + src/query/v2/common.hpp | 2 + src/storage/v3/result.hpp | 1 + src/storage/v3/shard.cpp | 2 +- src/storage/v3/shard_operation_result.hpp | 4 +- src/storage/v3/shard_rsm.cpp | 50 +++++++++++++++++++---- 7 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/expr/interpret/eval.hpp b/src/expr/interpret/eval.hpp index 1538028a0..70127c023 100644 --- a/src/expr/interpret/eval.hpp +++ b/src/expr/interpret/eval.hpp @@ -404,6 +404,7 @@ class ExpressionEvaluator : public ExpressionVisitor { case Error::SERIALIZATION_ERROR: case Error::VERTEX_HAS_EDGES: case Error::PROPERTIES_DISABLED: + case Error::VERTEX_ALREADY_INSERTED: throw ExpressionRuntimeException("Unexpected error when accessing labels."); } } @@ -751,6 +752,7 @@ class ExpressionEvaluator : public ExpressionVisitor { case Error::SERIALIZATION_ERROR: case Error::VERTEX_HAS_EDGES: case Error::PROPERTIES_DISABLED: + case Error::VERTEX_ALREADY_INSERTED: throw ExpressionRuntimeException("Unexpected error when getting a property."); } } @@ -779,6 +781,7 @@ class ExpressionEvaluator : public ExpressionVisitor { case Error::SERIALIZATION_ERROR: case Error::VERTEX_HAS_EDGES: case Error::PROPERTIES_DISABLED: + case Error::VERTEX_ALREADY_INSERTED: throw ExpressionRuntimeException("Unexpected error when getting a property."); } } diff --git a/src/memgraph.cpp b/src/memgraph.cpp index 0f80266e5..deaf9e568 100644 --- a/src/memgraph.cpp +++ b/src/memgraph.cpp @@ -489,6 +489,7 @@ class BoltSession final : public memgraph::communication::bolt::Session diff --git a/src/storage/v3/shard.cpp b/src/storage/v3/shard.cpp index 942ce65b2..0e596172d 100644 --- a/src/storage/v3/shard.cpp +++ b/src/storage/v3/shard.cpp @@ -363,7 +363,7 @@ ShardOperationResult Shard::Accessor::CreateVertexAndValidate( VertexAccessor vertex_acc{&it->vertex, transaction_, &shard_->indices_, config_, shard_->vertex_validator_}; if (!inserted) { - return {AlreadyInsertedElement{}}; + return {Error::VERTEX_ALREADY_INSERTED}; } MG_ASSERT(it != acc.end(), "Invalid Vertex accessor!"); diff --git a/src/storage/v3/shard_operation_result.hpp b/src/storage/v3/shard_operation_result.hpp index e055a0022..8de800b83 100644 --- a/src/storage/v3/shard_operation_result.hpp +++ b/src/storage/v3/shard_operation_result.hpp @@ -18,9 +18,7 @@ namespace memgraph::storage::v3 { -struct AlreadyInsertedElement {}; - -using ResultErrorType = std::variant; +using ResultErrorType = std::variant; template using ShardOperationResult = utils::BasicResult; diff --git a/src/storage/v3/shard_rsm.cpp b/src/storage/v3/shard_rsm.cpp index faae52f95..2911e26d6 100644 --- a/src/storage/v3/shard_rsm.cpp +++ b/src/storage/v3/shard_rsm.cpp @@ -492,14 +492,31 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateVerticesRequest &&req) { auto &error = result_schema.GetError(); std::visit( - [](T &&) { + [](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) { - spdlog::debug("Creating vertex failed with error: Error"); - } else if constexpr (std::is_same_v) { - spdlog::debug("Updating vertex failed with error: AlreadyInsertedElement"); + 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"); } @@ -539,14 +556,31 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) { auto &error = result_schema.GetError(); std::visit( - [](T &&) { + [](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) { - spdlog::debug("Updating vertex failed with error: Error"); - } else if constexpr (std::is_same_v) { - spdlog::debug("Updating vertex failed with error: AlreadyInsertedElement"); + 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"); }