Move ErrorCode to common

This commit is contained in:
jbajic 2022-11-17 11:03:03 +01:00
parent e98ef634de
commit ec4804b72a
17 changed files with 260 additions and 237 deletions

68
src/common/errors.hpp Normal file
View File

@ -0,0 +1,68 @@
// 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 <cstdint>
#include <string_view>
namespace memgraph::common {
enum class ErrorCode : uint8_t {
SERIALIZATION_ERROR,
NONEXISTENT_OBJECT,
DELETED_OBJECT,
VERTEX_HAS_EDGES,
PROPERTIES_DISABLED,
VERTEX_ALREADY_INSERTED,
// Schema Violations
SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL,
SCHEMA_VERTEX_PROPERTY_WRONG_TYPE,
SCHEMA_VERTEX_UPDATE_PRIMARY_KEY,
SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL,
SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY,
SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED,
OBJECT_NOT_FOUND,
};
constexpr std::string_view ErrorCodeToString(const ErrorCode code) {
switch (code) {
case ErrorCode::SERIALIZATION_ERROR:
return "SERIALIZATION_ERROR";
case ErrorCode::NONEXISTENT_OBJECT:
return "NONEXISTENT_OBJECT";
case ErrorCode::DELETED_OBJECT:
return "DELETED_OBJECT";
case ErrorCode::VERTEX_HAS_EDGES:
return "VERTEX_HAS_EDGES";
case ErrorCode::PROPERTIES_DISABLED:
return "PROPERTIES_DISABLED";
case ErrorCode::VERTEX_ALREADY_INSERTED:
return "VERTEX_ALREADY_INSERTED";
case ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
return "SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL";
case ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
return "SCHEMA_VERTEX_PROPERTY_WRONG_TYPE";
case ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
return "SCHEMA_VERTEX_UPDATE_PRIMARY_KEY";
case ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
return "SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL";
case ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
return "SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY";
case ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
return "SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED";
case ErrorCode::OBJECT_NOT_FOUND:
return "OBJECT_NOT_FOUND";
}
}
} // namespace memgraph::common

View File

@ -15,13 +15,13 @@
#include <string>
#include <vector>
#include "common/errors.hpp"
#include "coordinator/shard_map.hpp"
#include "query/v2/accessors.hpp"
#include "query/v2/requests.hpp"
#include "query/v2/shard_request_manager.hpp"
#include "storage/v3/edge_accessor.hpp"
#include "storage/v3/id_types.hpp"
#include "storage/v3/result.hpp"
#include "storage/v3/shard.hpp"
#include "storage/v3/vertex_accessor.hpp"
#include "storage/v3/view.hpp"
@ -112,7 +112,7 @@ storage::v3::ShardResult<communication::bolt::Path> ToBoltPath(
const query::v2::accessors::Path & /*edge*/, const msgs::ShardRequestManagerInterface * /*shard_request_manager*/,
storage::v3::View /*view*/) {
// TODO(jbajic) Fix bolt communication
return {SHARD_ERROR(storage::v3::ErrorCode::DELETED_OBJECT)};
return {SHARD_ERROR(common::ErrorCode::DELETED_OBJECT)};
}
storage::v3::ShardResult<Value> ToBoltValue(const query::v2::TypedValue &value,

View File

@ -33,6 +33,7 @@
#include <spdlog/sinks/dist_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include "common/errors.hpp"
#include "communication/bolt/v1/constants.hpp"
#include "communication/websocket/auth.hpp"
#include "communication/websocket/server.hpp"
@ -484,19 +485,19 @@ class BoltSession final : public memgraph::communication::bolt::Session<memgraph
memgraph::storage::v3::View::NEW);
if (maybe_value.HasError()) {
switch (maybe_value.GetError().code) {
case memgraph::storage::v3::ErrorCode::DELETED_OBJECT:
case memgraph::storage::v3::ErrorCode::SERIALIZATION_ERROR:
case memgraph::storage::v3::ErrorCode::VERTEX_HAS_EDGES:
case memgraph::storage::v3::ErrorCode::PROPERTIES_DISABLED:
case memgraph::storage::v3::ErrorCode::NONEXISTENT_OBJECT:
case memgraph::storage::v3::ErrorCode::VERTEX_ALREADY_INSERTED:
case memgraph::storage::v3::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
case memgraph::storage::v3::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
case memgraph::storage::v3::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
case memgraph::storage::v3::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
case memgraph::storage::v3::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
case memgraph::storage::v3::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
case memgraph::storage::v3::ErrorCode::OBJECT_NOT_FOUND:
case memgraph::common::ErrorCode::DELETED_OBJECT:
case memgraph::common::ErrorCode::SERIALIZATION_ERROR:
case memgraph::common::ErrorCode::VERTEX_HAS_EDGES:
case memgraph::common::ErrorCode::PROPERTIES_DISABLED:
case memgraph::common::ErrorCode::NONEXISTENT_OBJECT:
case memgraph::common::ErrorCode::VERTEX_ALREADY_INSERTED:
case memgraph::common::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
case memgraph::common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
case memgraph::common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
case memgraph::common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
case memgraph::common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
case memgraph::common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
case memgraph::common::ErrorCode::OBJECT_NOT_FOUND:
throw memgraph::communication::bolt::ClientError("Unexpected storage error when streaming summary.");
}
}
@ -524,21 +525,21 @@ class BoltSession final : public memgraph::communication::bolt::Session<memgraph
auto maybe_value = memgraph::glue::v2::ToBoltValue(v, shard_request_manager_, memgraph::storage::v3::View::NEW);
if (maybe_value.HasError()) {
switch (maybe_value.GetError().code) {
case memgraph::storage::v3::ErrorCode::DELETED_OBJECT:
case memgraph::common::ErrorCode::DELETED_OBJECT:
throw memgraph::communication::bolt::ClientError("Returning a deleted object as a result.");
case memgraph::storage::v3::ErrorCode::NONEXISTENT_OBJECT:
case memgraph::storage::v3::ErrorCode::OBJECT_NOT_FOUND:
case memgraph::common::ErrorCode::NONEXISTENT_OBJECT:
case memgraph::common::ErrorCode::OBJECT_NOT_FOUND:
throw memgraph::communication::bolt::ClientError("Returning a nonexistent object as a result.");
case memgraph::storage::v3::ErrorCode::VERTEX_HAS_EDGES:
case memgraph::storage::v3::ErrorCode::SERIALIZATION_ERROR:
case memgraph::storage::v3::ErrorCode::PROPERTIES_DISABLED:
case memgraph::storage::v3::ErrorCode::VERTEX_ALREADY_INSERTED:
case memgraph::storage::v3::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
case memgraph::storage::v3::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
case memgraph::storage::v3::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
case memgraph::storage::v3::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
case memgraph::storage::v3::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
case memgraph::storage::v3::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
case memgraph::common::ErrorCode::VERTEX_HAS_EDGES:
case memgraph::common::ErrorCode::SERIALIZATION_ERROR:
case memgraph::common::ErrorCode::PROPERTIES_DISABLED:
case memgraph::common::ErrorCode::VERTEX_ALREADY_INSERTED:
case memgraph::common::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
case memgraph::common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
case memgraph::common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
case memgraph::common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
case memgraph::common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
case memgraph::common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
throw memgraph::communication::bolt::ClientError("Unexpected storage error when streaming results.");
}
}

View File

@ -43,10 +43,8 @@ class Callable {
};
} // namespace detail
using ExpressionEvaluator =
memgraph::expr::ExpressionEvaluator<TypedValue, memgraph::query::v2::EvaluationContext,
memgraph::msgs::ShardRequestManagerInterface, storage::v3::View,
storage::v3::LabelId, msgs::Value, detail::Callable,
memgraph::storage::v3::ErrorCode, memgraph::expr::QueryEngineTag>;
using ExpressionEvaluator = memgraph::expr::ExpressionEvaluator<
TypedValue, memgraph::query::v2::EvaluationContext, memgraph::msgs::ShardRequestManagerInterface, storage::v3::View,
storage::v3::LabelId, msgs::Value, detail::Callable, common::ErrorCode, memgraph::expr::QueryEngineTag>;
} // namespace memgraph::query::v2

View File

@ -26,6 +26,7 @@
#include <cppitertools/chain.hpp>
#include <cppitertools/imap.hpp>
#include "common/errors.hpp"
#include "expr/ast/pretty_print_ast_to_original_expression.hpp"
#include "expr/exceptions.hpp"
#include "query/exceptions.hpp"
@ -42,7 +43,6 @@
#include "query/v2/shard_request_manager.hpp"
#include "storage/v3/conversions.hpp"
#include "storage/v3/property_value.hpp"
#include "storage/v3/result.hpp"
#include "utils/algorithm.hpp"
#include "utils/csv_parsing.hpp"
#include "utils/event_counter.hpp"
@ -570,20 +570,20 @@ template <class TEdges>
auto UnwrapEdgesResult(storage::v3::ShardResult<TEdges> &&result) {
if (result.HasError()) {
switch (result.GetError().code) {
case storage::v3::ErrorCode::DELETED_OBJECT:
case common::ErrorCode::DELETED_OBJECT:
throw QueryRuntimeException("Trying to get relationships of a deleted node.");
case storage::v3::ErrorCode::NONEXISTENT_OBJECT:
case common::ErrorCode::NONEXISTENT_OBJECT:
throw query::v2::QueryRuntimeException("Trying to get relationships from a node that doesn't exist.");
case storage::v3::ErrorCode::VERTEX_HAS_EDGES:
case storage::v3::ErrorCode::SERIALIZATION_ERROR:
case storage::v3::ErrorCode::PROPERTIES_DISABLED:
case common::ErrorCode::VERTEX_HAS_EDGES:
case common::ErrorCode::SERIALIZATION_ERROR:
case common::ErrorCode::PROPERTIES_DISABLED:
throw QueryRuntimeException("Unexpected error when accessing relationships.");
case storage::v3::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
case storage::v3::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
case storage::v3::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
case storage::v3::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
case storage::v3::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
case storage::v3::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
case common::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
case common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
case common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
case common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
case common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
case common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
throw QueryRuntimeException("SchemaViolation occurred when accessing relationships.");
}
}

View File

@ -319,7 +319,7 @@ struct Value {
};
struct ShardError {
storage::v3::ErrorCode code;
common::ErrorCode code;
std::string message;
};

View File

@ -88,6 +88,6 @@ struct EvaluationContext {
using ExpressionEvaluator =
memgraph::expr::ExpressionEvaluator<TypedValue, EvaluationContext, DbAccessor, storage::v3::View,
storage::v3::LabelId, storage::v3::PropertyStore, PropertyToTypedValueConverter,
memgraph::storage::v3::ErrorCode>;
common::ErrorCode>;
} // namespace memgraph::storage::v3

View File

@ -57,11 +57,11 @@ const VertexId &EdgeAccessor::ToVertex() const { return to_vertex_; }
ShardResult<PropertyValue> EdgeAccessor::SetProperty(PropertyId property, const PropertyValue &value) {
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
if (!config_.properties_on_edges) return SHARD_ERROR(ErrorCode::PROPERTIES_DISABLED);
if (!config_.properties_on_edges) return SHARD_ERROR(common::ErrorCode::PROPERTIES_DISABLED);
if (!PrepareForWrite(transaction_, edge_.ptr)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, edge_.ptr)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (edge_.ptr->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (edge_.ptr->deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
auto current_value = edge_.ptr->properties.GetProperty(property);
// We could skip setting the value if the previous one is the same to the new
@ -77,11 +77,11 @@ ShardResult<PropertyValue> EdgeAccessor::SetProperty(PropertyId property, const
}
ShardResult<std::map<PropertyId, PropertyValue>> EdgeAccessor::ClearProperties() {
if (!config_.properties_on_edges) return SHARD_ERROR(ErrorCode::PROPERTIES_DISABLED);
if (!config_.properties_on_edges) return SHARD_ERROR(common::ErrorCode::PROPERTIES_DISABLED);
if (!PrepareForWrite(transaction_, edge_.ptr)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, edge_.ptr)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (edge_.ptr->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (edge_.ptr->deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
auto properties = edge_.ptr->properties.Properties();
for (const auto &property : properties) {
@ -129,8 +129,8 @@ ShardResult<PropertyValue> EdgeAccessor::GetProperty(PropertyId property, View v
break;
}
});
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!exists) return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
return std::move(value);
}
@ -175,8 +175,8 @@ ShardResult<std::map<PropertyId, PropertyValue>> EdgeAccessor::Properties(View v
break;
}
});
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!exists) return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
return std::move(properties);
}

View File

@ -16,68 +16,20 @@
#include <string_view>
#include <type_traits>
#include "common/errors.hpp"
#include "utils/result.hpp"
namespace memgraph::storage::v3 {
static_assert(std::is_same_v<uint8_t, unsigned char>);
enum class ErrorCode : uint8_t {
SERIALIZATION_ERROR,
NONEXISTENT_OBJECT,
DELETED_OBJECT,
VERTEX_HAS_EDGES,
PROPERTIES_DISABLED,
VERTEX_ALREADY_INSERTED,
// Schema Violations
SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL,
SCHEMA_VERTEX_PROPERTY_WRONG_TYPE,
SCHEMA_VERTEX_UPDATE_PRIMARY_KEY,
SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL,
SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY,
SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED,
OBJECT_NOT_FOUND,
};
constexpr std::string_view ErrorCodeToString(const ErrorCode code) {
switch (code) {
case ErrorCode::SERIALIZATION_ERROR:
return "SERIALIZATION_ERROR";
case ErrorCode::NONEXISTENT_OBJECT:
return "NONEXISTENT_OBJECT";
case ErrorCode::DELETED_OBJECT:
return "DELETED_OBJECT";
case ErrorCode::VERTEX_HAS_EDGES:
return "VERTEX_HAS_EDGES";
case ErrorCode::PROPERTIES_DISABLED:
return "PROPERTIES_DISABLED";
case ErrorCode::VERTEX_ALREADY_INSERTED:
return "VERTEX_ALREADY_INSERTED";
case ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
return "SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL";
case ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
return "SCHEMA_VERTEX_PROPERTY_WRONG_TYPE";
case ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
return "SCHEMA_VERTEX_UPDATE_PRIMARY_KEY";
case ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
return "SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL";
case ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
return "SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY";
case ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
return "SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED";
case ErrorCode::OBJECT_NOT_FOUND:
return "OBJECT_NOT_FOUND";
}
}
struct ShardError {
ShardError(ErrorCode code, std::string message, std::string source)
ShardError(common::ErrorCode code, std::string message, std::string source)
: code{code}, message{std::move(message)}, source{std::move(source)} {}
ShardError(ErrorCode code, std::string source) : code{code}, source{std::move(source)} {}
ShardError(common::ErrorCode code, std::string source) : code{code}, source{std::move(source)} {}
ErrorCode code;
common::ErrorCode code;
// TODO Maybe add category
std::string message;
std::string source;

View File

@ -31,14 +31,14 @@ std::optional<ShardError> SchemaValidator::ValidateVertexCreate(
// Schema on primary label
const auto *schema = schemas_->GetSchema(primary_label);
if (schema == nullptr) {
return SHARD_ERROR(ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL,
return SHARD_ERROR(common::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL,
fmt::format("Schema not defined for label :{}", name_id_mapper_->IdToName(primary_label)));
}
// Is there another primary label among secondary labels
for (const auto &secondary_label : labels) {
if (schemas_->GetSchema(secondary_label)) {
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY,
return SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY,
fmt::format("Cannot add label :{}, since it is defined as a primary label",
name_id_mapper_->IdToName(secondary_label)));
}
@ -46,7 +46,7 @@ std::optional<ShardError> SchemaValidator::ValidateVertexCreate(
// Quick size check
if (schema->second.size() != primary_properties.size()) {
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED,
return SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED,
fmt::format("Not all primary properties have been specified for :{} vertex",
name_id_mapper_->IdToName(primary_label)));
}
@ -56,7 +56,7 @@ std::optional<ShardError> SchemaValidator::ValidateVertexCreate(
if (auto property_schema_type = PropertyTypeToSchemaType(primary_properties[i]);
property_schema_type && *property_schema_type != schema->second[i].type) {
return SHARD_ERROR(
ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE,
common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE,
fmt::format("Property {} is of wrong type, expected {}, actual {}",
name_id_mapper_->IdToName(schema->second[i].property_id),
SchemaTypeToString(schema->second[i].type), SchemaTypeToString(*property_schema_type)));
@ -78,7 +78,7 @@ std::optional<ShardError> SchemaValidator::ValidatePropertyUpdate(const LabelId
[property_id](const auto &schema_property) { return property_id == schema_property.property_id; });
schema_property != schema->second.end()) {
return SHARD_ERROR(
ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY,
common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY,
fmt::format("Cannot update primary property {} of schema on label :{}",
name_id_mapper_->IdToName(schema_property->property_id), name_id_mapper_->IdToName(primary_label)));
}
@ -88,7 +88,7 @@ std::optional<ShardError> SchemaValidator::ValidatePropertyUpdate(const LabelId
std::optional<ShardError> SchemaValidator::ValidateLabelUpdate(const LabelId label) const {
const auto *schema = schemas_->GetSchema(label);
if (schema) {
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL,
return SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL,
fmt::format("Cannot add/remove primary label :{}", name_id_mapper_->IdToName(label)));
}
return std::nullopt;

View File

@ -364,7 +364,7 @@ ShardResult<VertexAccessor> Shard::Accessor::CreateVertexAndValidate(
VertexAccessor vertex_acc{&it->vertex, transaction_, &shard_->indices_, config_, shard_->vertex_validator_};
if (!inserted) {
return SHARD_ERROR(ErrorCode::VERTEX_ALREADY_INSERTED);
return SHARD_ERROR(common::ErrorCode::VERTEX_ALREADY_INSERTED);
}
MG_ASSERT(it != acc.end(), "Invalid Vertex accessor!");
@ -401,13 +401,14 @@ ShardResult<std::optional<VertexAccessor>> Shard::Accessor::DeleteVertex(VertexA
"accessor when deleting a vertex!");
auto *vertex_ptr = vertex->vertex_;
if (!PrepareForWrite(transaction_, vertex_ptr)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, vertex_ptr)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (vertex_ptr->deleted) {
return std::optional<VertexAccessor>{};
}
if (!vertex_ptr->in_edges.empty() || !vertex_ptr->out_edges.empty()) return SHARD_ERROR(ErrorCode::VERTEX_HAS_EDGES);
if (!vertex_ptr->in_edges.empty() || !vertex_ptr->out_edges.empty())
return SHARD_ERROR(common::ErrorCode::VERTEX_HAS_EDGES);
CreateAndLinkDelta(transaction_, vertex_ptr, Delta::RecreateObjectTag());
vertex_ptr->deleted = true;
@ -429,7 +430,7 @@ ShardResult<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>>
std::vector<Vertex::EdgeLink> out_edges;
{
if (!PrepareForWrite(transaction_, vertex_ptr)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, vertex_ptr)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (vertex_ptr->deleted) return std::optional<ReturnType>{};
@ -444,7 +445,7 @@ ShardResult<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>>
EdgeAccessor e(edge, edge_type, from_vertex, vertex_id, transaction_, &shard_->indices_, config_);
auto ret = DeleteEdge(e.FromVertex(), e.ToVertex(), e.Gid());
if (ret.HasError()) {
MG_ASSERT(ret.GetError().code == ErrorCode::SERIALIZATION_ERROR, "Invalid database state!");
MG_ASSERT(ret.GetError().code == common::ErrorCode::SERIALIZATION_ERROR, "Invalid database state!");
return ret.GetError();
}
@ -457,7 +458,7 @@ ShardResult<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>>
EdgeAccessor e(edge, edge_type, vertex_id, to_vertex, transaction_, &shard_->indices_, config_);
auto ret = DeleteEdge(e.FromVertex(), e.ToVertex(), e.Gid());
if (ret.HasError()) {
MG_ASSERT(ret.GetError().code == ErrorCode::SERIALIZATION_ERROR, "Invalid database state!");
MG_ASSERT(ret.GetError().code == common::ErrorCode::SERIALIZATION_ERROR, "Invalid database state!");
return ret.GetError();
}
@ -470,7 +471,7 @@ ShardResult<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>>
// vertex. Some other transaction could have modified the vertex in the
// meantime if we didn't have any edges to delete.
if (!PrepareForWrite(transaction_, vertex_ptr)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, vertex_ptr)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
MG_ASSERT(!vertex_ptr->deleted, "Invalid database state!");
@ -507,12 +508,12 @@ ShardResult<EdgeAccessor> Shard::Accessor::CreateEdge(VertexId from_vertex_id, V
}
if (from_is_local) {
if (!PrepareForWrite(transaction_, from_vertex)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (from_vertex->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!PrepareForWrite(transaction_, from_vertex)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (from_vertex->deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
}
if (to_is_local && to_vertex != from_vertex) {
if (!PrepareForWrite(transaction_, to_vertex)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (to_vertex->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!PrepareForWrite(transaction_, to_vertex)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (to_vertex->deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
}
EdgeRef edge(gid);
@ -567,13 +568,13 @@ ShardResult<std::optional<EdgeAccessor>> Shard::Accessor::DeleteEdge(VertexId fr
if (from_is_local) {
if (!PrepareForWrite(transaction_, from_vertex)) {
return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
}
MG_ASSERT(!from_vertex->deleted, "Invalid database state!");
}
if (to_is_local && to_vertex != from_vertex) {
if (!PrepareForWrite(transaction_, to_vertex)) {
return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
}
MG_ASSERT(!to_vertex->deleted, "Invalid database state!");
}

View File

@ -532,7 +532,7 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) {
auto vertex_to_update = acc.FindVertex(ConvertPropertyVector(std::move(vertex.primary_key)), View::OLD);
if (!vertex_to_update) {
action_successful = false;
shard_error.emplace(msgs::ShardError{ErrorCode::OBJECT_NOT_FOUND});
shard_error.emplace(msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND});
spdlog::debug("In transaction {} vertex could not be found while trying to update its properties.",
req.transaction_id.logical_id);
continue;
@ -564,7 +564,7 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::DeleteVerticesRequest &&req) {
spdlog::debug("Error while trying to delete vertex. Vertex to delete does not exist. Transaction id: {}",
req.transaction_id.logical_id);
action_successful = false;
shard_error.emplace(msgs::ShardError{ErrorCode::OBJECT_NOT_FOUND});
shard_error.emplace(msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND});
spdlog::debug("In transaction {} vertex could not be found while trying to delete it.",
req.transaction_id.logical_id);
break;
@ -612,7 +612,7 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateExpandRequest &&req) {
if (!(shard_->IsVertexBelongToShard(from_vertex_id) || shard_->IsVertexBelongToShard(to_vertex_id))) {
action_successful = false;
shard_error = msgs::ShardError{ErrorCode::OBJECT_NOT_FOUND,
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND,
"Error while trying to insert edge, none of the vertices belong to this shard"};
spdlog::debug("Error while trying to insert edge, none of the vertices belong to this shard. Transaction id: {}",
req.transaction_id.logical_id);
@ -638,7 +638,7 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateExpandRequest &&req) {
} else {
// TODO Code for this
action_successful = false;
shard_error = msgs::ShardError{ErrorCode::OBJECT_NOT_FOUND};
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND};
spdlog::debug("Creating edge was not successful. Transaction id: {}", req.transaction_id.logical_id);
break;
}
@ -697,7 +697,7 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateEdgesRequest &&req) {
auto vertex_acc = acc.FindVertex(ConvertPropertyVector(std::move(edge.src.second)), View::OLD);
if (!vertex_acc) {
action_successful = false;
shard_error = msgs::ShardError{ErrorCode::OBJECT_NOT_FOUND, "Source vertex was not found"};
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND, "Source vertex was not found"};
spdlog::debug("Encountered an error while trying to acquire VertexAccessor with transaction id: {}",
req.transaction_id.logical_id);
continue;
@ -733,7 +733,7 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateEdgesRequest &&req) {
if (!edge_accessor_did_match) {
// TODO(jbajic) Do we need this
shard_error = msgs::ShardError{ErrorCode::OBJECT_NOT_FOUND, "Edge was not found"};
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND, "Edge was not found"};
action_successful = false;
spdlog::debug("Could not find the Edge with the specified Gid. Transaction id: {}",
req.transaction_id.logical_id);
@ -785,7 +785,7 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ScanVerticesRequest &&req) {
// Vertex is separated from the properties in the response.
// Is it useful to return just a vertex without the properties?
if (!found_props) {
shard_error = msgs::ShardError{ErrorCode::OBJECT_NOT_FOUND, "Requested properties were not found!"};
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND, "Requested properties were not found!"};
action_successful = false;
}
@ -858,7 +858,7 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) {
// Get Vertex acc
auto src_vertex_acc_opt = acc.FindVertex(ConvertPropertyVector((src_vertex.second)), View::NEW);
if (!src_vertex_acc_opt) {
shard_error = msgs::ShardError{ErrorCode::OBJECT_NOT_FOUND, "Source vertex was not found."};
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND, "Source vertex was not found."};
action_successful = false;
spdlog::debug("Encountered an error while trying to obtain VertexAccessor. Transaction id: {}",
req.transaction_id.logical_id);
@ -878,7 +878,7 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) {
if (result.HasError()) {
// Code Error
shard_error = msgs::ShardError{ErrorCode::OBJECT_NOT_FOUND, "Source vertex was not found."};
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND, "Source vertex was not found."};
action_successful = false;
break;
}

View File

@ -83,9 +83,9 @@ bool VertexAccessor::IsVisible(View view) const {
ShardResult<bool> VertexAccessor::AddLabel(LabelId label) {
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (vertex_->deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
if (std::find(vertex_->labels.begin(), vertex_->labels.end(), label) != vertex_->labels.end()) return false;
@ -104,9 +104,9 @@ ShardResult<bool> VertexAccessor::AddLabelAndValidate(LabelId label) {
}
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (vertex_->deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
if (std::find(vertex_->labels.begin(), vertex_->labels.end(), label) != vertex_->labels.end()) return false;
@ -120,9 +120,9 @@ ShardResult<bool> VertexAccessor::AddLabelAndValidate(LabelId label) {
}
ShardResult<bool> VertexAccessor::RemoveLabel(LabelId label) {
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (vertex_->deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
auto it = std::find(vertex_->labels.begin(), vertex_->labels.end(), label);
if (it == vertex_->labels.end()) return false;
@ -139,9 +139,9 @@ ShardResult<bool> VertexAccessor::RemoveLabelAndValidate(LabelId label) {
return {*maybe_violation_error};
}
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (vertex_->deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
auto it = std::find(vertex_->labels.begin(), vertex_->labels.end(), label);
if (it == vertex_->labels.end()) return false;
@ -197,8 +197,8 @@ ShardResult<bool> VertexAccessor::HasLabel(LabelId label, View view) const {
break;
}
});
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!exists) return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
return has_label;
}
@ -267,17 +267,17 @@ ShardResult<std::vector<LabelId>> VertexAccessor::Labels(View view) const {
break;
}
});
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!exists) return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
return std::move(labels);
}
ShardResult<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const PropertyValue &value) {
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (vertex_->deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
auto current_value = vertex_->properties.GetProperty(property);
// We could skip setting the value if the previous one is the same to the new
@ -323,10 +323,10 @@ ShardResult<void> VertexAccessor::CheckVertexExistence(View view) const {
}
});
if (!exists) {
return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
}
if (!for_deleted_ && deleted) {
return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
}
return {};
}
@ -338,11 +338,11 @@ ShardResult<PropertyValue> VertexAccessor::SetPropertyAndValidate(PropertyId pro
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
if (!PrepareForWrite(transaction_, vertex_)) {
return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
}
if (vertex_->deleted) {
return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
}
auto current_value = vertex_->properties.GetProperty(property);
@ -361,9 +361,9 @@ ShardResult<PropertyValue> VertexAccessor::SetPropertyAndValidate(PropertyId pro
}
ShardResult<std::map<PropertyId, PropertyValue>> VertexAccessor::ClearProperties() {
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR);
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (vertex_->deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
auto properties = vertex_->properties.Properties();
for (const auto &property : properties) {
@ -441,8 +441,8 @@ ShardResult<PropertyValue> VertexAccessor::GetProperty(PropertyId property, View
break;
}
});
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!exists) return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
return std::move(value);
}
@ -491,8 +491,8 @@ ShardResult<std::map<PropertyId, PropertyValue>> VertexAccessor::Properties(View
break;
}
});
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!exists) return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
return std::move(properties);
}
@ -563,8 +563,8 @@ ShardResult<std::vector<EdgeAccessor>> VertexAccessor::InEdges(View view, const
break;
}
});
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
if (deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!exists) return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
if (deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
std::vector<EdgeAccessor> ret;
if (in_edges.empty()) {
return ret;
@ -643,8 +643,8 @@ ShardResult<std::vector<EdgeAccessor>> VertexAccessor::OutEdges(View view, const
break;
}
});
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
if (deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!exists) return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
if (deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
std::vector<EdgeAccessor> ret;
if (out_edges.empty()) {
return ret;
@ -690,8 +690,8 @@ ShardResult<size_t> VertexAccessor::InDegree(View view) const {
break;
}
});
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!exists) return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
return degree;
}
@ -727,8 +727,8 @@ ShardResult<size_t> VertexAccessor::OutDegree(View view) const {
break;
}
});
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
if (!exists) return SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT);
if (!for_deleted_ && deleted) return SHARD_ERROR(common::ErrorCode::DELETED_OBJECT);
return degree;
}

View File

@ -17,6 +17,7 @@
#include <gtest/gtest-death-test.h>
#include <gtest/gtest.h>
#include "common/errors.hpp"
#include "coordinator/hybrid_logical_clock.hpp"
#include "io/time.hpp"
#include "storage/v3/delta.hpp"
@ -579,7 +580,7 @@ TEST_P(StorageV3, VertexDeleteSerializationError) {
EXPECT_EQ(CountVertices(acc2, View::NEW), 1U);
auto res = acc2.DeleteVertex(&*vertex);
ASSERT_TRUE(res.HasError());
ASSERT_EQ(res.GetError(), SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR));
ASSERT_EQ(res.GetError(), SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR));
EXPECT_EQ(CountVertices(acc2, View::OLD), 1U);
EXPECT_EQ(CountVertices(acc2, View::NEW), 1U);
acc2.AdvanceCommand();
@ -710,20 +711,20 @@ TEST_P(StorageV3, VertexDeleteLabel) {
// Check whether label 5 exists
ASSERT_FALSE(vertex->HasLabel(label5, View::OLD).GetValue());
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Labels(View::OLD)->size(), 0);
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
// Try to add the label
{
auto ret = vertex->AddLabelAndValidate(label5);
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
AssertShardErrorEqual(ret, SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
}
// Try to remove the label
{
auto ret = vertex->RemoveLabelAndValidate(label5);
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
AssertShardErrorEqual(ret, SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
}
acc.Abort();
@ -778,33 +779,33 @@ TEST_P(StorageV3, VertexDeleteLabel) {
// Check whether label 5 exists
ASSERT_TRUE(vertex->HasLabel(label5, View::OLD).GetValue());
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
{
auto labels = vertex->Labels(View::OLD).GetValue();
ASSERT_EQ(labels.size(), 1);
ASSERT_EQ(labels[0], label5);
}
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
// Advance command
acc.AdvanceCommand();
// Check whether label 5 exists
ASSERT_EQ(vertex->HasLabel(label5, View::OLD).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Labels(View::OLD).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->HasLabel(label5, View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Labels(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
// Try to add the label
{
auto ret = vertex->AddLabelAndValidate(label5);
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
AssertShardErrorEqual(ret, SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
}
// Try to remove the label
{
auto ret = vertex->RemoveLabelAndValidate(label5);
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
AssertShardErrorEqual(ret, SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
}
acc.Abort();
@ -854,14 +855,14 @@ TEST_P(StorageV3, VertexDeleteProperty) {
// Check whether label 5 exists
ASSERT_TRUE(vertex->GetProperty(property5, View::OLD)->IsNull());
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Properties(View::OLD)->size(), 0);
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
// Try to set the property5
{
auto ret = vertex->SetPropertyAndValidate(property5, PropertyValue("haihai"));
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
AssertShardErrorEqual(ret, SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
}
acc.Abort();
@ -917,27 +918,27 @@ TEST_P(StorageV3, VertexDeleteProperty) {
// Check whether property 5 exists
ASSERT_EQ(vertex->GetProperty(property5, View::OLD)->ValueString(), "nandare");
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
{
auto properties = vertex->Properties(View::OLD).GetValue();
ASSERT_EQ(properties.size(), 1);
ASSERT_EQ(properties[property5].ValueString(), "nandare");
}
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
// Advance command
acc.AdvanceCommand();
// Check whether property 5 exists
ASSERT_EQ(vertex->GetProperty(property5, View::OLD).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Properties(View::OLD).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->GetProperty(property5, View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Properties(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
// Try to set the property
{
auto ret = vertex->SetPropertyAndValidate(property5, PropertyValue("haihai"));
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
AssertShardErrorEqual(ret, SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
}
acc.Abort();
@ -1370,7 +1371,7 @@ TEST_P(StorageV3, VertexLabelSerializationError) {
{
auto res = vertex->AddLabelAndValidate(label1);
AssertShardErrorEqual(res, SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR));
AssertShardErrorEqual(res, SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR));
}
}
@ -1864,7 +1865,7 @@ TEST_P(StorageV3, VertexPropertySerializationError) {
{
auto res = vertex->SetPropertyAndValidate(property2, PropertyValue("nandare"));
AssertShardErrorEqual(res, SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR));
AssertShardErrorEqual(res, SHARD_ERROR(common::ErrorCode::SERIALIZATION_ERROR));
}
}
@ -2254,14 +2255,14 @@ TEST_P(StorageV3, VertexNonexistentLabelPropertyEdgeAPI) {
auto vertex = CreateVertexAndValidate(acc, {}, PropertyValue{0}, {});
// Check state before (OLD view).
ASSERT_EQ(vertex.Labels(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.HasLabel(label1, View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.Properties(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.GetProperty(property1, View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.InEdges(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.OutEdges(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.InDegree(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.OutDegree(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.Labels(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.HasLabel(label1, View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.Properties(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.GetProperty(property1, View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.InEdges(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.OutEdges(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.InDegree(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.OutDegree(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
// Check state before (NEW view).
ASSERT_EQ(vertex.Labels(View::NEW)->size(), 0);
@ -2281,14 +2282,14 @@ TEST_P(StorageV3, VertexNonexistentLabelPropertyEdgeAPI) {
.HasValue());
// Check state after (OLD view).
ASSERT_EQ(vertex.Labels(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.HasLabel(label1, View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.Properties(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.GetProperty(property1, View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.InEdges(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.OutEdges(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.InDegree(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.OutDegree(View::OLD).GetError(), SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.Labels(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.HasLabel(label1, View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.Properties(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.GetProperty(property1, View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.InEdges(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.OutEdges(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.InDegree(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
ASSERT_EQ(vertex.OutDegree(View::OLD).GetError(), SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
// Check state after (NEW view).
ASSERT_EQ(vertex.Labels(View::NEW)->size(), 1);
@ -2656,31 +2657,31 @@ TEST_P(StorageV3, TestCreateVertexAndValidate) {
ASSERT_TRUE(vertex2.HasError());
auto error = vertex2.GetError();
ASSERT_TRUE(error.code == storage::v3::ErrorCode::VERTEX_ALREADY_INSERTED);
ASSERT_TRUE(error.code == common::ErrorCode::VERTEX_ALREADY_INSERTED);
}
{
auto acc = store.Access(GetNextHlc());
auto vertex = acc.CreateVertexAndValidate({primary_label}, {PropertyValue{0}}, {});
ASSERT_TRUE(vertex.HasError());
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
}
{
auto acc = store.Access(GetNextHlc());
auto vertex = acc.CreateVertexAndValidate({primary_label}, {PropertyValue{0}}, {});
ASSERT_TRUE(vertex.HasError());
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
}
{
auto acc = store.Access(GetNextHlc());
auto vertex = acc.CreateVertexAndValidate({}, {}, {});
ASSERT_TRUE(vertex.HasError());
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED));
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED));
}
{
auto acc = store.Access(GetNextHlc());
auto vertex = acc.CreateVertexAndValidate({}, {PropertyValue{"test"}}, {});
ASSERT_TRUE(vertex.HasError());
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
}
}
} // namespace memgraph::storage::v3::tests

View File

@ -3242,7 +3242,7 @@ TEST_P(StorageEdgeTest, VertexDetachDeleteSingleCommit) {
{
auto ret = acc.DeleteVertex(&vertex_from.value());
ASSERT_TRUE(ret.HasError());
ASSERT_EQ(ret.GetError(), SHARD_ERROR(ErrorCode::VERTEX_HAS_EDGES));
ASSERT_EQ(ret.GetError(), SHARD_ERROR(common::ErrorCode::VERTEX_HAS_EDGES));
}
// Detach delete vertex
@ -3255,8 +3255,8 @@ TEST_P(StorageEdgeTest, VertexDetachDeleteSingleCommit) {
// Check edges
ASSERT_EQ(vertex_from->InEdges(View::OLD)->size(), 0);
ASSERT_EQ(*vertex_from->InDegree(View::OLD), 0);
ASSERT_EQ(vertex_from->InEdges(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex_from->InDegree(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex_from->InEdges(View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex_from->InDegree(View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
{
auto ret = vertex_from->OutEdges(View::OLD);
ASSERT_TRUE(ret.HasValue());
@ -3269,8 +3269,8 @@ TEST_P(StorageEdgeTest, VertexDetachDeleteSingleCommit) {
ASSERT_EQ(e.FromVertex(), from_id);
ASSERT_EQ(e.ToVertex(), to_id);
}
ASSERT_EQ(vertex_from->OutEdges(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex_from->OutDegree(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex_from->OutEdges(View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
ASSERT_EQ(vertex_from->OutDegree(View::NEW).GetError(), SHARD_ERROR(common::ErrorCode::DELETED_OBJECT));
{
auto ret = vertex_to->InEdges(View::OLD);
ASSERT_TRUE(ret.HasValue());

View File

@ -18,6 +18,7 @@
#include <string>
#include <vector>
#include "common/errors.hpp"
#include "common/types.hpp"
#include "storage/v3/id_types.hpp"
#include "storage/v3/property_value.hpp"
@ -187,43 +188,43 @@ TEST_F(SchemaValidatorTest, TestSchemaValidateVertexCreate) {
{
const auto schema_violation = schema_validator.ValidateVertexCreate(NameToLabel("test"), {}, {PropertyValue(1)});
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL));
}
{
const auto schema_violation = schema_validator.ValidateVertexCreate(label2, {}, {});
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED));
}
// Validate wrong secondary label
{
const auto schema_violation = schema_validator.ValidateVertexCreate(label1, {label1}, {PropertyValue("test")});
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
}
{
const auto schema_violation = schema_validator.ValidateVertexCreate(label1, {label2}, {PropertyValue("test")});
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
}
// Validate wrong property type
{
const auto schema_violation = schema_validator.ValidateVertexCreate(label1, {}, {PropertyValue(1)});
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
}
{
const auto schema_violation =
schema_validator.ValidateVertexCreate(label2, {}, {PropertyValue("test"), PropertyValue(12), PropertyValue(1)});
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
}
{
const auto wrong_prop = PropertyValue(TemporalData(TemporalType::Date, 1234));
const auto schema_violation =
schema_validator.ValidateVertexCreate(label2, {}, {PropertyValue("test"), PropertyValue(12), wrong_prop});
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
}
// Passing validations
EXPECT_EQ(schema_validator.ValidateVertexCreate(label1, {}, {PropertyValue("test")}), std::nullopt);
@ -245,12 +246,12 @@ TEST_F(SchemaValidatorTest, TestSchemaValidatePropertyUpdate) {
{
const auto schema_violation = schema_validator.ValidatePropertyUpdate(label1, prop_string);
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
}
{
const auto schema_violation = schema_validator.ValidatePropertyUpdate(label2, prop_duration);
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
}
EXPECT_EQ(schema_validator.ValidatePropertyUpdate(label1, prop_int), std::nullopt);
EXPECT_EQ(schema_validator.ValidatePropertyUpdate(label1, prop_duration), std::nullopt);
@ -262,12 +263,12 @@ TEST_F(SchemaValidatorTest, TestSchemaValidatePropertyUpdateLabel) {
{
const auto schema_violation = schema_validator.ValidateLabelUpdate(label1);
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
}
{
const auto schema_violation = schema_validator.ValidateLabelUpdate(label2);
ASSERT_NE(schema_violation, std::nullopt);
EXPECT_EQ(*schema_violation, SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
EXPECT_EQ(*schema_violation, SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
}
EXPECT_EQ(schema_validator.ValidateLabelUpdate(NameToLabel("test")), std::nullopt);
}

View File

@ -16,6 +16,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "common/errors.hpp"
#include "common/types.hpp"
#include "storage/v3/delta.hpp"
#include "storage/v3/id_types.hpp"
@ -76,7 +77,7 @@ TEST_F(StorageV3Accessor, TestPrimaryLabel) {
ASSERT_TRUE(vertex.PrimaryLabel(View::OLD).HasError());
const auto error_primary_label = vertex.PrimaryLabel(View::OLD).GetError();
ASSERT_FALSE(vertex.PrimaryLabel(View::NEW).HasError());
EXPECT_EQ(error_primary_label, SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
EXPECT_EQ(error_primary_label, SHARD_ERROR(common::ErrorCode::NONEXISTENT_OBJECT));
}
{
auto acc = storage.Access(GetNextHlc());
@ -127,7 +128,7 @@ TEST_F(StorageV3Accessor, TestAddLabels) {
const auto label1 = NameToLabelId("label");
auto vertex = acc.CreateVertexAndValidate({label1}, {PropertyValue{2}}, {});
ASSERT_TRUE(vertex.HasError());
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
}
{
auto acc = storage.Access(GetNextHlc());
@ -136,7 +137,7 @@ TEST_F(StorageV3Accessor, TestAddLabels) {
ASSERT_TRUE(vertex.HasValue());
const auto schema_violation = vertex->AddLabelAndValidate(label1);
ASSERT_TRUE(schema_violation.HasError());
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
}
}
@ -180,7 +181,7 @@ TEST_F(StorageV3Accessor, TestRemoveLabels) {
auto vertex = CreateVertexAndValidate(acc, {}, PropertyValue{2});
const auto res1 = vertex.RemoveLabelAndValidate(primary_label);
ASSERT_TRUE(res1.HasError());
EXPECT_EQ(res1.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
EXPECT_EQ(res1.GetError(), SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
}
}
@ -199,14 +200,14 @@ TEST_F(StorageV3Accessor, TestSetKeysAndProperties) {
auto vertex = CreateVertexAndValidate(acc, {}, PropertyValue{1});
const auto res = vertex.SetPropertyAndValidate(primary_property, PropertyValue(1));
ASSERT_TRUE(res.HasError());
EXPECT_EQ(res.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
EXPECT_EQ(res.GetError(), SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
}
{
auto acc = storage.Access(GetNextHlc());
auto vertex = CreateVertexAndValidate(acc, {}, PropertyValue{2});
const auto res = vertex.SetPropertyAndValidate(primary_property, PropertyValue());
ASSERT_TRUE(res.HasError());
EXPECT_EQ(res.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
EXPECT_EQ(res.GetError(), SHARD_ERROR(common::ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
}
}