Merge branch 'project-pineapples' into MG-implicit-fallthrough-as-error
This commit is contained in:
commit
3b798ab313
68
src/common/errors.hpp
Normal file
68
src/common/errors.hpp
Normal 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
|
@ -100,6 +100,28 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
#undef BINARY_OPERATOR_VISITOR
|
||||
#undef UNARY_OPERATOR_VISITOR
|
||||
|
||||
void HandleObjectAccessError(Error &shard_error, const std::string_view accessed_object) {
|
||||
switch (shard_error) {
|
||||
case Error::DELETED_OBJECT:
|
||||
throw ExpressionRuntimeException("Trying to access {} on a deleted object.", accessed_object);
|
||||
case Error::NONEXISTENT_OBJECT:
|
||||
throw ExpressionRuntimeException("Trying to access {} from a node object doesn't exist.", accessed_object);
|
||||
case Error::SERIALIZATION_ERROR:
|
||||
case Error::VERTEX_HAS_EDGES:
|
||||
case Error::PROPERTIES_DISABLED:
|
||||
case Error::VERTEX_ALREADY_INSERTED:
|
||||
case Error::OBJECT_NOT_FOUND:
|
||||
throw ExpressionRuntimeException("Unexpected error when accessing {}.", accessed_object);
|
||||
case Error::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL:
|
||||
case Error::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE:
|
||||
case Error::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY:
|
||||
case Error::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL:
|
||||
case Error::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY:
|
||||
case Error::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED:
|
||||
throw ExpressionRuntimeException("Unexpected schema violation when accessing {}.", accessed_object);
|
||||
}
|
||||
}
|
||||
|
||||
TypedValue Visit(AndOperator &op) override {
|
||||
auto value1 = op.expression1_->Accept(*this);
|
||||
if (value1.IsBool() && !value1.ValueBool()) {
|
||||
@ -396,17 +418,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
has_label = vertex.HasLabel(StorageView::NEW, GetLabel(label));
|
||||
}
|
||||
if (has_label.HasError()) {
|
||||
switch (has_label.GetError()) {
|
||||
case Error::DELETED_OBJECT:
|
||||
throw ExpressionRuntimeException("Trying to access labels on a deleted node.");
|
||||
case Error::NONEXISTENT_OBJECT:
|
||||
throw ExpressionRuntimeException("Trying to access labels from a node that doesn't exist.");
|
||||
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.");
|
||||
}
|
||||
HandleObjectAccessError(has_label.GetError().code, "labels");
|
||||
}
|
||||
return *has_label;
|
||||
}
|
||||
@ -744,17 +756,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
maybe_prop = record_accessor.GetProperty(StorageView::NEW, ctx_->properties[prop.ix]);
|
||||
}
|
||||
if (maybe_prop.HasError()) {
|
||||
switch (maybe_prop.GetError()) {
|
||||
case Error::DELETED_OBJECT:
|
||||
throw ExpressionRuntimeException("Trying to get a property from a deleted object.");
|
||||
case Error::NONEXISTENT_OBJECT:
|
||||
throw ExpressionRuntimeException("Trying to get a property from an object that doesn't exist.");
|
||||
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.");
|
||||
}
|
||||
HandleObjectAccessError(maybe_prop.GetError().code, "property");
|
||||
}
|
||||
return conv_(*maybe_prop, ctx_->memory);
|
||||
}
|
||||
@ -773,17 +775,7 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
|
||||
maybe_prop = record_accessor.GetProperty(view_, dba_->NameToProperty(name));
|
||||
}
|
||||
if (maybe_prop.HasError()) {
|
||||
switch (maybe_prop.GetError()) {
|
||||
case Error::DELETED_OBJECT:
|
||||
throw ExpressionRuntimeException("Trying to get a property from a deleted object.");
|
||||
case Error::NONEXISTENT_OBJECT:
|
||||
throw ExpressionRuntimeException("Trying to get a property from an object that doesn't exist.");
|
||||
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.");
|
||||
}
|
||||
HandleObjectAccessError(maybe_prop.GetError().code, "property");
|
||||
}
|
||||
return conv_(*maybe_prop, ctx_->memory);
|
||||
}
|
||||
|
@ -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"
|
||||
@ -71,9 +71,9 @@ query::v2::TypedValue ToTypedValue(const Value &value) {
|
||||
}
|
||||
}
|
||||
|
||||
storage::v3::Result<communication::bolt::Vertex> ToBoltVertex(
|
||||
const query::v2::accessors::VertexAccessor &vertex, const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View /*view*/) {
|
||||
communication::bolt::Vertex ToBoltVertex(const query::v2::accessors::VertexAccessor &vertex,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View /*view*/) {
|
||||
auto id = communication::bolt::Id::FromUint(0);
|
||||
|
||||
auto labels = vertex.Labels();
|
||||
@ -91,9 +91,9 @@ storage::v3::Result<communication::bolt::Vertex> ToBoltVertex(
|
||||
return communication::bolt::Vertex{id, new_labels, new_properties};
|
||||
}
|
||||
|
||||
storage::v3::Result<communication::bolt::Edge> ToBoltEdge(
|
||||
const query::v2::accessors::EdgeAccessor &edge, const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View /*view*/) {
|
||||
communication::bolt::Edge ToBoltEdge(const query::v2::accessors::EdgeAccessor &edge,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View /*view*/) {
|
||||
// TODO(jbajic) Fix bolt communication
|
||||
auto id = communication::bolt::Id::FromUint(0);
|
||||
auto from = communication::bolt::Id::FromUint(0);
|
||||
@ -108,69 +108,64 @@ storage::v3::Result<communication::bolt::Edge> ToBoltEdge(
|
||||
return communication::bolt::Edge{id, from, to, type, new_properties};
|
||||
}
|
||||
|
||||
storage::v3::Result<communication::bolt::Path> ToBoltPath(
|
||||
const query::v2::accessors::Path & /*edge*/, const msgs::ShardRequestManagerInterface * /*shard_request_manager*/,
|
||||
storage::v3::View /*view*/) {
|
||||
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 {storage::v3::Error::DELETED_OBJECT};
|
||||
MG_ASSERT(false, "Path is unimplemented!");
|
||||
return {};
|
||||
}
|
||||
|
||||
storage::v3::Result<Value> ToBoltValue(const query::v2::TypedValue &value,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view) {
|
||||
Value ToBoltValue(const query::v2::TypedValue &value, const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view) {
|
||||
switch (value.type()) {
|
||||
case query::v2::TypedValue::Type::Null:
|
||||
return Value();
|
||||
return {};
|
||||
case query::v2::TypedValue::Type::Bool:
|
||||
return Value(value.ValueBool());
|
||||
return {value.ValueBool()};
|
||||
case query::v2::TypedValue::Type::Int:
|
||||
return Value(value.ValueInt());
|
||||
return {value.ValueInt()};
|
||||
case query::v2::TypedValue::Type::Double:
|
||||
return Value(value.ValueDouble());
|
||||
return {value.ValueDouble()};
|
||||
case query::v2::TypedValue::Type::String:
|
||||
return Value(std::string(value.ValueString()));
|
||||
return {std::string(value.ValueString())};
|
||||
case query::v2::TypedValue::Type::List: {
|
||||
std::vector<Value> values;
|
||||
values.reserve(value.ValueList().size());
|
||||
for (const auto &v : value.ValueList()) {
|
||||
auto maybe_value = ToBoltValue(v, shard_request_manager, view);
|
||||
if (maybe_value.HasError()) return maybe_value.GetError();
|
||||
values.emplace_back(std::move(*maybe_value));
|
||||
auto value = ToBoltValue(v, shard_request_manager, view);
|
||||
values.emplace_back(std::move(value));
|
||||
}
|
||||
return Value(std::move(values));
|
||||
return {std::move(values)};
|
||||
}
|
||||
case query::v2::TypedValue::Type::Map: {
|
||||
std::map<std::string, Value> map;
|
||||
for (const auto &kv : value.ValueMap()) {
|
||||
auto maybe_value = ToBoltValue(kv.second, shard_request_manager, view);
|
||||
if (maybe_value.HasError()) return maybe_value.GetError();
|
||||
map.emplace(kv.first, std::move(*maybe_value));
|
||||
auto value = ToBoltValue(kv.second, shard_request_manager, view);
|
||||
map.emplace(kv.first, std::move(value));
|
||||
}
|
||||
return Value(std::move(map));
|
||||
return {std::move(map)};
|
||||
}
|
||||
case query::v2::TypedValue::Type::Vertex: {
|
||||
auto maybe_vertex = ToBoltVertex(value.ValueVertex(), shard_request_manager, view);
|
||||
if (maybe_vertex.HasError()) return maybe_vertex.GetError();
|
||||
return Value(std::move(*maybe_vertex));
|
||||
auto vertex = ToBoltVertex(value.ValueVertex(), shard_request_manager, view);
|
||||
return {std::move(vertex)};
|
||||
}
|
||||
case query::v2::TypedValue::Type::Edge: {
|
||||
auto maybe_edge = ToBoltEdge(value.ValueEdge(), shard_request_manager, view);
|
||||
if (maybe_edge.HasError()) return maybe_edge.GetError();
|
||||
return Value(std::move(*maybe_edge));
|
||||
auto edge = ToBoltEdge(value.ValueEdge(), shard_request_manager, view);
|
||||
return {std::move(edge)};
|
||||
}
|
||||
case query::v2::TypedValue::Type::Path: {
|
||||
auto maybe_path = ToBoltPath(value.ValuePath(), shard_request_manager, view);
|
||||
if (maybe_path.HasError()) return maybe_path.GetError();
|
||||
return Value(std::move(*maybe_path));
|
||||
auto path = ToBoltPath(value.ValuePath(), shard_request_manager, view);
|
||||
return {std::move(path)};
|
||||
}
|
||||
case query::v2::TypedValue::Type::Date:
|
||||
return Value(value.ValueDate());
|
||||
return {value.ValueDate()};
|
||||
case query::v2::TypedValue::Type::LocalTime:
|
||||
return Value(value.ValueLocalTime());
|
||||
return {value.ValueLocalTime()};
|
||||
case query::v2::TypedValue::Type::LocalDateTime:
|
||||
return Value(value.ValueLocalDateTime());
|
||||
return {value.ValueLocalDateTime()};
|
||||
case query::v2::TypedValue::Type::Duration:
|
||||
return Value(value.ValueDuration());
|
||||
return {value.ValueDuration()};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/shard.hpp"
|
||||
#include "storage/v3/view.hpp"
|
||||
#include "utils/result.hpp"
|
||||
|
||||
namespace memgraph::storage::v3 {
|
||||
class EdgeAccessor;
|
||||
@ -35,36 +36,36 @@ namespace memgraph::glue::v2 {
|
||||
/// @param storage::v3::View for deciding which vertex attributes are visible.
|
||||
///
|
||||
/// @throw std::bad_alloc
|
||||
storage::v3::Result<communication::bolt::Vertex> ToBoltVertex(
|
||||
const storage::v3::VertexAccessor &vertex, const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
communication::bolt::Vertex ToBoltVertex(const storage::v3::VertexAccessor &vertex,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
|
||||
/// @param storage::v3::EdgeAccessor for converting to communication::bolt::Edge.
|
||||
/// @param msgs::ShardRequestManagerInterface *shard_request_manager getting edge type and property names.
|
||||
/// @param storage::v3::View for deciding which edge attributes are visible.
|
||||
///
|
||||
/// @throw std::bad_alloc
|
||||
storage::v3::Result<communication::bolt::Edge> ToBoltEdge(
|
||||
const storage::v3::EdgeAccessor &edge, const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
communication::bolt::Edge ToBoltEdge(const storage::v3::EdgeAccessor &edge,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
|
||||
/// @param query::v2::Path for converting to communication::bolt::Path.
|
||||
/// @param msgs::ShardRequestManagerInterface *shard_request_manager ToBoltVertex and ToBoltEdge.
|
||||
/// @param storage::v3::View for ToBoltVertex and ToBoltEdge.
|
||||
///
|
||||
/// @throw std::bad_alloc
|
||||
storage::v3::Result<communication::bolt::Path> ToBoltPath(
|
||||
const query::v2::accessors::Path &path, const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
communication::bolt::Path ToBoltPath(const query::v2::accessors::Path &path,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
|
||||
/// @param query::v2::TypedValue for converting to communication::bolt::Value.
|
||||
/// @param msgs::ShardRequestManagerInterface *shard_request_manager ToBoltVertex and ToBoltEdge.
|
||||
/// @param storage::v3::View for ToBoltVertex and ToBoltEdge.
|
||||
///
|
||||
/// @throw std::bad_alloc
|
||||
storage::v3::Result<communication::bolt::Value> ToBoltValue(
|
||||
const query::v2::TypedValue &value, const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
communication::bolt::Value ToBoltValue(const query::v2::TypedValue &value,
|
||||
const msgs::ShardRequestManagerInterface *shard_request_manager,
|
||||
storage::v3::View view);
|
||||
|
||||
query::v2::TypedValue ToTypedValue(const communication::bolt::Value &value);
|
||||
|
||||
|
@ -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"
|
||||
@ -480,20 +481,9 @@ class BoltSession final : public memgraph::communication::bolt::Session<memgraph
|
||||
const auto &summary = interpreter_.Pull(&stream, n, qid);
|
||||
std::map<std::string, memgraph::communication::bolt::Value> decoded_summary;
|
||||
for (const auto &kv : summary) {
|
||||
auto maybe_value = memgraph::glue::v2::ToBoltValue(kv.second, interpreter_.GetShardRequestManager(),
|
||||
memgraph::storage::v3::View::NEW);
|
||||
if (maybe_value.HasError()) {
|
||||
switch (maybe_value.GetError()) {
|
||||
case memgraph::storage::v3::Error::DELETED_OBJECT:
|
||||
case memgraph::storage::v3::Error::SERIALIZATION_ERROR:
|
||||
case memgraph::storage::v3::Error::VERTEX_HAS_EDGES:
|
||||
case memgraph::storage::v3::Error::PROPERTIES_DISABLED:
|
||||
case memgraph::storage::v3::Error::NONEXISTENT_OBJECT:
|
||||
case memgraph::storage::v3::Error::VERTEX_ALREADY_INSERTED:
|
||||
throw memgraph::communication::bolt::ClientError("Unexpected storage error when streaming summary.");
|
||||
}
|
||||
}
|
||||
decoded_summary.emplace(kv.first, std::move(*maybe_value));
|
||||
auto bolt_value = memgraph::glue::v2::ToBoltValue(kv.second, interpreter_.GetShardRequestManager(),
|
||||
memgraph::storage::v3::View::NEW);
|
||||
decoded_summary.emplace(kv.first, std::move(bolt_value));
|
||||
}
|
||||
return decoded_summary;
|
||||
} catch (const memgraph::query::v2::QueryException &e) {
|
||||
@ -514,21 +504,8 @@ class BoltSession final : public memgraph::communication::bolt::Session<memgraph
|
||||
std::vector<memgraph::communication::bolt::Value> decoded_values;
|
||||
decoded_values.reserve(values.size());
|
||||
for (const auto &v : values) {
|
||||
auto maybe_value = memgraph::glue::v2::ToBoltValue(v, shard_request_manager_, memgraph::storage::v3::View::NEW);
|
||||
if (maybe_value.HasError()) {
|
||||
switch (maybe_value.GetError()) {
|
||||
case memgraph::storage::v3::Error::DELETED_OBJECT:
|
||||
throw memgraph::communication::bolt::ClientError("Returning a deleted object as a result.");
|
||||
case memgraph::storage::v3::Error::NONEXISTENT_OBJECT:
|
||||
throw memgraph::communication::bolt::ClientError("Returning a nonexistent object as a result.");
|
||||
case memgraph::storage::v3::Error::VERTEX_HAS_EDGES:
|
||||
case memgraph::storage::v3::Error::SERIALIZATION_ERROR:
|
||||
case memgraph::storage::v3::Error::PROPERTIES_DISABLED:
|
||||
case memgraph::storage::v3::Error::VERTEX_ALREADY_INSERTED:
|
||||
throw memgraph::communication::bolt::ClientError("Unexpected storage error when streaming results.");
|
||||
}
|
||||
}
|
||||
decoded_values.emplace_back(std::move(*maybe_value));
|
||||
auto bolt_value = memgraph::glue::v2::ToBoltValue(v, shard_request_manager_, memgraph::storage::v3::View::NEW);
|
||||
decoded_values.emplace_back(std::move(bolt_value));
|
||||
}
|
||||
encoder_->MessageRecord(decoded_values);
|
||||
}
|
||||
|
@ -21,11 +21,12 @@
|
||||
#include "query/v2/requests.hpp"
|
||||
#include "storage/v3/conversions.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/view.hpp"
|
||||
|
||||
namespace memgraph::msgs {
|
||||
class ShardRequestManagerInterface;
|
||||
} // namespace memgraph::msgs
|
||||
} // namespace memgraph::msgs
|
||||
|
||||
namespace memgraph::query::v2 {
|
||||
|
||||
@ -44,6 +45,6 @@ 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::Error, memgraph::expr::QueryEngineTag>;
|
||||
storage::v3::LabelId, msgs::Value, detail::Callable, common::ErrorCode, memgraph::expr::QueryEngineTag>;
|
||||
|
||||
} // namespace memgraph::query::v2
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "query/v2/bindings/symbol.hpp"
|
||||
#include "query/v2/bindings/typed_value.hpp"
|
||||
#include "query/v2/db_accessor.hpp"
|
||||
#include "query/v2/exceptions.hpp"
|
||||
#include "query/v2/frontend/ast/ast.hpp"
|
||||
#include "query/v2/path.hpp"
|
||||
@ -28,7 +27,6 @@
|
||||
#include "storage/v3/id_types.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/shard_operation_result.hpp"
|
||||
#include "storage/v3/view.hpp"
|
||||
#include "utils/exceptions.hpp"
|
||||
#include "utils/logging.hpp"
|
||||
@ -82,39 +80,5 @@ inline void ExpectType(const Symbol &symbol, const TypedValue &value, TypedValue
|
||||
throw QueryRuntimeException("Expected a {} for '{}', but got {}.", expected, symbol.name(), value.type());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
concept AccessorWithSetProperty = requires(T accessor, const storage::v3::PropertyId key,
|
||||
const storage::v3::PropertyValue new_value) {
|
||||
{ accessor.SetProperty(key, new_value) } -> std::same_as<storage::v3::Result<storage::v3::PropertyValue>>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
concept AccessorWithSetPropertyAndValidate = requires(T accessor, const storage::v3::PropertyId key,
|
||||
const storage::v3::PropertyValue new_value) {
|
||||
{
|
||||
accessor.SetPropertyAndValidate(key, new_value)
|
||||
} -> std::same_as<storage::v3::ShardOperationResult<storage::v3::PropertyValue>>;
|
||||
};
|
||||
|
||||
template <typename TRecordAccessor>
|
||||
concept RecordAccessor =
|
||||
AccessorWithSetProperty<TRecordAccessor> || AccessorWithSetPropertyAndValidate<TRecordAccessor>;
|
||||
|
||||
inline void HandleErrorOnPropertyUpdate(const storage::v3::Error error) {
|
||||
switch (error) {
|
||||
case storage::v3::Error::SERIALIZATION_ERROR:
|
||||
throw TransactionSerializationException();
|
||||
case storage::v3::Error::DELETED_OBJECT:
|
||||
throw QueryRuntimeException("Trying to set properties on a deleted object.");
|
||||
case storage::v3::Error::PROPERTIES_DISABLED:
|
||||
throw QueryRuntimeException("Can't set property because properties on edges are disabled.");
|
||||
case storage::v3::Error::VERTEX_HAS_EDGES:
|
||||
case storage::v3::Error::NONEXISTENT_OBJECT:
|
||||
case storage::v3::Error::VERTEX_ALREADY_INSERTED:
|
||||
|
||||
throw QueryRuntimeException("Unexpected error when setting a property.");
|
||||
}
|
||||
}
|
||||
|
||||
int64_t QueryTimestamp();
|
||||
} // namespace memgraph::query::v2
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "storage/v3/key_store.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/shard_operation_result.hpp"
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Our communication layer and query engine don't mix
|
||||
@ -65,24 +64,11 @@ class EdgeAccessor final {
|
||||
|
||||
auto Properties(storage::v3::View view) const { return impl_.Properties(view); }
|
||||
|
||||
storage::v3::Result<storage::v3::PropertyValue> GetProperty(storage::v3::View view,
|
||||
storage::v3::PropertyId key) const {
|
||||
storage::v3::ShardResult<storage::v3::PropertyValue> GetProperty(storage::v3::View view,
|
||||
storage::v3::PropertyId key) const {
|
||||
return impl_.GetProperty(key, view);
|
||||
}
|
||||
|
||||
storage::v3::Result<storage::v3::PropertyValue> SetProperty(storage::v3::PropertyId key,
|
||||
const storage::v3::PropertyValue &value) {
|
||||
return impl_.SetProperty(key, value);
|
||||
}
|
||||
|
||||
storage::v3::Result<storage::v3::PropertyValue> RemoveProperty(storage::v3::PropertyId key) {
|
||||
return SetProperty(key, storage::v3::PropertyValue());
|
||||
}
|
||||
|
||||
storage::v3::Result<std::map<storage::v3::PropertyId, storage::v3::PropertyValue>> ClearProperties() {
|
||||
return impl_.ClearProperties();
|
||||
}
|
||||
|
||||
VertexAccessor To() const;
|
||||
|
||||
VertexAccessor From() const;
|
||||
@ -114,53 +100,19 @@ class VertexAccessor final {
|
||||
|
||||
auto PrimaryKey(storage::v3::View view) const { return impl_.PrimaryKey(view); }
|
||||
|
||||
storage::v3::ShardOperationResult<bool> AddLabel(storage::v3::LabelId label) {
|
||||
return impl_.AddLabelAndValidate(label);
|
||||
}
|
||||
|
||||
storage::v3::ShardOperationResult<bool> AddLabelAndValidate(storage::v3::LabelId label) {
|
||||
return impl_.AddLabelAndValidate(label);
|
||||
}
|
||||
|
||||
storage::v3::ShardOperationResult<bool> RemoveLabel(storage::v3::LabelId label) {
|
||||
return impl_.RemoveLabelAndValidate(label);
|
||||
}
|
||||
|
||||
storage::v3::ShardOperationResult<bool> RemoveLabelAndValidate(storage::v3::LabelId label) {
|
||||
return impl_.RemoveLabelAndValidate(label);
|
||||
}
|
||||
|
||||
storage::v3::Result<bool> HasLabel(storage::v3::View view, storage::v3::LabelId label) const {
|
||||
storage::v3::ShardResult<bool> HasLabel(storage::v3::View view, storage::v3::LabelId label) const {
|
||||
return impl_.HasLabel(label, view);
|
||||
}
|
||||
|
||||
auto Properties(storage::v3::View view) const { return impl_.Properties(view); }
|
||||
|
||||
storage::v3::Result<storage::v3::PropertyValue> GetProperty(storage::v3::View view,
|
||||
storage::v3::PropertyId key) const {
|
||||
storage::v3::ShardResult<storage::v3::PropertyValue> GetProperty(storage::v3::View view,
|
||||
storage::v3::PropertyId key) const {
|
||||
return impl_.GetProperty(key, view);
|
||||
}
|
||||
|
||||
storage::v3::ShardOperationResult<storage::v3::PropertyValue> SetProperty(storage::v3::PropertyId key,
|
||||
const storage::v3::PropertyValue &value) {
|
||||
return impl_.SetPropertyAndValidate(key, value);
|
||||
}
|
||||
|
||||
storage::v3::ShardOperationResult<storage::v3::PropertyValue> SetPropertyAndValidate(
|
||||
storage::v3::PropertyId key, const storage::v3::PropertyValue &value) {
|
||||
return impl_.SetPropertyAndValidate(key, value);
|
||||
}
|
||||
|
||||
storage::v3::ShardOperationResult<storage::v3::PropertyValue> RemovePropertyAndValidate(storage::v3::PropertyId key) {
|
||||
return SetPropertyAndValidate(key, storage::v3::PropertyValue{});
|
||||
}
|
||||
|
||||
storage::v3::Result<std::map<storage::v3::PropertyId, storage::v3::PropertyValue>> ClearProperties() {
|
||||
return impl_.ClearProperties();
|
||||
}
|
||||
|
||||
auto InEdges(storage::v3::View view, const std::vector<storage::v3::EdgeTypeId> &edge_types) const
|
||||
-> storage::v3::Result<decltype(iter::imap(MakeEdgeAccessor, *impl_.InEdges(view)))> {
|
||||
-> storage::v3::ShardResult<decltype(iter::imap(MakeEdgeAccessor, *impl_.InEdges(view)))> {
|
||||
auto maybe_edges = impl_.InEdges(view, edge_types);
|
||||
if (maybe_edges.HasError()) return maybe_edges.GetError();
|
||||
return iter::imap(MakeEdgeAccessor, std::move(*maybe_edges));
|
||||
@ -170,7 +122,7 @@ class VertexAccessor final {
|
||||
|
||||
auto InEdges(storage::v3::View view, const std::vector<storage::v3::EdgeTypeId> &edge_types,
|
||||
const VertexAccessor &dest) const
|
||||
-> storage::v3::Result<decltype(iter::imap(MakeEdgeAccessor, *impl_.InEdges(view)))> {
|
||||
-> storage::v3::ShardResult<decltype(iter::imap(MakeEdgeAccessor, *impl_.InEdges(view)))> {
|
||||
const auto dest_id = dest.impl_.Id(view).GetValue();
|
||||
auto maybe_edges = impl_.InEdges(view, edge_types, &dest_id);
|
||||
if (maybe_edges.HasError()) return maybe_edges.GetError();
|
||||
@ -178,7 +130,7 @@ class VertexAccessor final {
|
||||
}
|
||||
|
||||
auto OutEdges(storage::v3::View view, const std::vector<storage::v3::EdgeTypeId> &edge_types) const
|
||||
-> storage::v3::Result<decltype(iter::imap(MakeEdgeAccessor, *impl_.OutEdges(view)))> {
|
||||
-> storage::v3::ShardResult<decltype(iter::imap(MakeEdgeAccessor, *impl_.OutEdges(view)))> {
|
||||
auto maybe_edges = impl_.OutEdges(view, edge_types);
|
||||
if (maybe_edges.HasError()) return maybe_edges.GetError();
|
||||
return iter::imap(MakeEdgeAccessor, std::move(*maybe_edges));
|
||||
@ -188,16 +140,16 @@ class VertexAccessor final {
|
||||
|
||||
auto OutEdges(storage::v3::View view, const std::vector<storage::v3::EdgeTypeId> &edge_types,
|
||||
const VertexAccessor &dest) const
|
||||
-> storage::v3::Result<decltype(iter::imap(MakeEdgeAccessor, *impl_.OutEdges(view)))> {
|
||||
-> storage::v3::ShardResult<decltype(iter::imap(MakeEdgeAccessor, *impl_.OutEdges(view)))> {
|
||||
const auto dest_id = dest.impl_.Id(view).GetValue();
|
||||
auto maybe_edges = impl_.OutEdges(view, edge_types, &dest_id);
|
||||
if (maybe_edges.HasError()) return maybe_edges.GetError();
|
||||
return iter::imap(MakeEdgeAccessor, std::move(*maybe_edges));
|
||||
}
|
||||
|
||||
storage::v3::Result<size_t> InDegree(storage::v3::View view) const { return impl_.InDegree(view); }
|
||||
storage::v3::ShardResult<size_t> InDegree(storage::v3::View view) const { return impl_.InDegree(view); }
|
||||
|
||||
storage::v3::Result<size_t> OutDegree(storage::v3::View view) const { return impl_.OutDegree(view); }
|
||||
storage::v3::ShardResult<size_t> OutDegree(storage::v3::View view) const { return impl_.OutDegree(view); }
|
||||
|
||||
// TODO(jbajic) Fix Remove Gid
|
||||
static int64_t CypherId() { return 1; }
|
||||
|
@ -224,12 +224,4 @@ class VersionInfoInMulticommandTxException : public QueryException {
|
||||
: QueryException("Version info query not allowed in multicommand transactions.") {}
|
||||
};
|
||||
|
||||
/**
|
||||
* An exception for an illegal operation that violates schema
|
||||
*/
|
||||
class SchemaViolationException : public QueryRuntimeException {
|
||||
public:
|
||||
using QueryRuntimeException::QueryRuntimeException;
|
||||
};
|
||||
|
||||
} // namespace memgraph::query::v2
|
||||
|
@ -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"
|
||||
@ -563,27 +564,6 @@ UniqueCursorPtr ScanAllById::MakeCursor(utils::MemoryResource *mem) const {
|
||||
std::move(vertices), "ScanAllById");
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
template <class TEdges>
|
||||
auto UnwrapEdgesResult(storage::v3::Result<TEdges> &&result) {
|
||||
if (result.HasError()) {
|
||||
switch (result.GetError()) {
|
||||
case storage::v3::Error::DELETED_OBJECT:
|
||||
throw QueryRuntimeException("Trying to get relationships of a deleted node.");
|
||||
case storage::v3::Error::NONEXISTENT_OBJECT:
|
||||
throw query::v2::QueryRuntimeException("Trying to get relationships from a node that doesn't exist.");
|
||||
case storage::v3::Error::VERTEX_HAS_EDGES:
|
||||
case storage::v3::Error::SERIALIZATION_ERROR:
|
||||
case storage::v3::Error::PROPERTIES_DISABLED:
|
||||
throw QueryRuntimeException("Unexpected error when accessing relationships.");
|
||||
}
|
||||
}
|
||||
return std::move(*result);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Expand::Expand(const std::shared_ptr<LogicalOperator> &input, Symbol input_symbol, Symbol node_symbol,
|
||||
Symbol edge_symbol, EdgeAtom::Direction direction,
|
||||
const std::vector<storage::v3::EdgeTypeId> &edge_types, bool existing_node, storage::v3::View view)
|
||||
@ -836,45 +816,9 @@ std::vector<Symbol> SetProperties::ModifiedSymbols(const SymbolTable &table) con
|
||||
SetProperties::SetPropertiesCursor::SetPropertiesCursor(const SetProperties &self, utils::MemoryResource *mem)
|
||||
: self_(self), input_cursor_(self.input_->MakeCursor(mem)) {}
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
concept AccessorWithProperties = requires(T value, storage::v3::PropertyId property_id,
|
||||
storage::v3::PropertyValue property_value) {
|
||||
{
|
||||
value.ClearProperties()
|
||||
} -> std::same_as<storage::v3::Result<std::map<storage::v3::PropertyId, storage::v3::PropertyValue>>>;
|
||||
{value.SetProperty(property_id, property_value)};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
bool SetProperties::SetPropertiesCursor::Pull(Frame &frame, ExecutionContext &context) {
|
||||
SCOPED_PROFILE_OP("SetProperties");
|
||||
return false;
|
||||
// if (!input_cursor_->Pull(frame, context)) return false;
|
||||
//
|
||||
// TypedValue &lhs = frame[self_.input_symbol_];
|
||||
//
|
||||
// // Set, just like Create needs to see the latest changes.
|
||||
// ExpressionEvaluator evaluator(&frame, context.symbol_table, context.evaluation_context, context.db_accessor,
|
||||
// storage::v3::View::NEW);
|
||||
// TypedValue rhs = self_.rhs_->Accept(evaluator);
|
||||
//
|
||||
// switch (lhs.type()) {
|
||||
// case TypedValue::Type::Vertex:
|
||||
// SetPropertiesOnRecord(&lhs.ValueVertex(), rhs, self_.op_, &context);
|
||||
// break;
|
||||
// case TypedValue::Type::Edge:
|
||||
// SetPropertiesOnRecord(&lhs.ValueEdge(), rhs, self_.op_, &context);
|
||||
// break;
|
||||
// case TypedValue::Type::Null:
|
||||
// // Skip setting properties on Null (can occur in optional match).
|
||||
// break;
|
||||
// default:
|
||||
// throw QueryRuntimeException("Properties can only be set on edges and vertices.");
|
||||
// }
|
||||
// return true;
|
||||
}
|
||||
|
||||
void SetProperties::SetPropertiesCursor::Shutdown() { input_cursor_->Shutdown(); }
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "coordinator/hybrid_logical_clock.hpp"
|
||||
#include "storage/v3/id_types.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
|
||||
namespace memgraph::msgs {
|
||||
|
||||
@ -317,6 +318,11 @@ struct Value {
|
||||
}
|
||||
};
|
||||
|
||||
struct ShardError {
|
||||
common::ErrorCode code;
|
||||
std::string message;
|
||||
};
|
||||
|
||||
struct Expression {
|
||||
std::string expression;
|
||||
};
|
||||
@ -361,7 +367,7 @@ struct ScanResultRow {
|
||||
};
|
||||
|
||||
struct ScanVerticesResponse {
|
||||
bool success;
|
||||
std::optional<ShardError> error;
|
||||
std::optional<VertexId> next_start_id;
|
||||
std::vector<ScanResultRow> results;
|
||||
};
|
||||
@ -381,7 +387,7 @@ struct GetPropertiesRequest {
|
||||
};
|
||||
|
||||
struct GetPropertiesResponse {
|
||||
bool success;
|
||||
std::optional<ShardError> error;
|
||||
};
|
||||
|
||||
enum class EdgeDirection : uint8_t { OUT = 1, IN = 2, BOTH = 3 };
|
||||
@ -448,7 +454,7 @@ struct ExpandOneResultRow {
|
||||
};
|
||||
|
||||
struct ExpandOneResponse {
|
||||
bool success;
|
||||
std::optional<ShardError> error;
|
||||
std::vector<ExpandOneResultRow> result;
|
||||
};
|
||||
|
||||
@ -484,7 +490,7 @@ struct CreateVerticesRequest {
|
||||
};
|
||||
|
||||
struct CreateVerticesResponse {
|
||||
bool success;
|
||||
std::optional<ShardError> error;
|
||||
};
|
||||
|
||||
struct DeleteVerticesRequest {
|
||||
@ -495,7 +501,7 @@ struct DeleteVerticesRequest {
|
||||
};
|
||||
|
||||
struct DeleteVerticesResponse {
|
||||
bool success;
|
||||
std::optional<ShardError> error;
|
||||
};
|
||||
|
||||
struct UpdateVerticesRequest {
|
||||
@ -504,7 +510,7 @@ struct UpdateVerticesRequest {
|
||||
};
|
||||
|
||||
struct UpdateVerticesResponse {
|
||||
bool success;
|
||||
std::optional<ShardError> error;
|
||||
};
|
||||
|
||||
/*
|
||||
@ -526,7 +532,7 @@ struct CreateExpandRequest {
|
||||
};
|
||||
|
||||
struct CreateExpandResponse {
|
||||
bool success;
|
||||
std::optional<ShardError> error;
|
||||
};
|
||||
|
||||
struct DeleteEdgesRequest {
|
||||
@ -535,7 +541,7 @@ struct DeleteEdgesRequest {
|
||||
};
|
||||
|
||||
struct DeleteEdgesResponse {
|
||||
bool success;
|
||||
std::optional<ShardError> error;
|
||||
};
|
||||
|
||||
struct UpdateEdgesRequest {
|
||||
@ -544,7 +550,7 @@ struct UpdateEdgesRequest {
|
||||
};
|
||||
|
||||
struct UpdateEdgesResponse {
|
||||
bool success;
|
||||
std::optional<ShardError> error;
|
||||
};
|
||||
|
||||
struct CommitRequest {
|
||||
@ -553,7 +559,7 @@ struct CommitRequest {
|
||||
};
|
||||
|
||||
struct CommitResponse {
|
||||
bool success;
|
||||
std::optional<ShardError> error;
|
||||
};
|
||||
|
||||
using ReadRequests = std::variant<ExpandOneRequest, GetPropertiesRequest, ScanVerticesRequest>;
|
||||
|
@ -206,7 +206,7 @@ class ShardRequestManager : public ShardRequestManagerInterface {
|
||||
}
|
||||
WriteResponses write_response_variant = commit_response.GetValue();
|
||||
auto &response = std::get<CommitResponse>(write_response_variant);
|
||||
if (!response.success) {
|
||||
if (response.error) {
|
||||
throw std::runtime_error("Commit request did not succeed");
|
||||
}
|
||||
}
|
||||
@ -311,7 +311,7 @@ class ShardRequestManager : public ShardRequestManagerInterface {
|
||||
WriteResponses response_variant = write_response_result.GetValue();
|
||||
CreateExpandResponse mapped_response = std::get<CreateExpandResponse>(response_variant);
|
||||
|
||||
if (!mapped_response.success) {
|
||||
if (mapped_response.error) {
|
||||
throw std::runtime_error("CreateExpand request did not succeed");
|
||||
}
|
||||
responses.push_back(mapped_response);
|
||||
@ -601,7 +601,7 @@ class ShardRequestManager : public ShardRequestManagerInterface {
|
||||
WriteResponses response_variant = poll_result->GetValue();
|
||||
auto response = std::get<CreateVerticesResponse>(response_variant);
|
||||
|
||||
if (!response.success) {
|
||||
if (response.error) {
|
||||
throw std::runtime_error("CreateVertices request did not succeed");
|
||||
}
|
||||
responses.push_back(response);
|
||||
@ -637,7 +637,7 @@ class ShardRequestManager : public ShardRequestManagerInterface {
|
||||
// Currently a boolean flag for signaling the overall success of the
|
||||
// ExpandOne request does not exist. But it should, so here we assume
|
||||
// that it is already in place.
|
||||
if (!response.success) {
|
||||
if (response.error) {
|
||||
throw std::runtime_error("ExpandOne request did not succeed");
|
||||
}
|
||||
|
||||
@ -680,7 +680,7 @@ class ShardRequestManager : public ShardRequestManagerInterface {
|
||||
|
||||
ReadResponses read_response_variant = await_result->GetValue();
|
||||
auto response = std::get<ScanVerticesResponse>(read_response_variant);
|
||||
if (!response.success) {
|
||||
if (response.error) {
|
||||
throw std::runtime_error("ScanAll request did not succeed");
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ class DbAccessor final {
|
||||
return VerticesIterable(accessor_->Vertices(label, property, lower, upper, view));
|
||||
}
|
||||
|
||||
storage::v3::Result<EdgeAccessor> InsertEdge(VertexAccessor *from, VertexAccessor *to,
|
||||
const storage::v3::EdgeTypeId &edge_type) {
|
||||
storage::v3::ShardResult<EdgeAccessor> InsertEdge(VertexAccessor *from, VertexAccessor *to,
|
||||
const storage::v3::EdgeTypeId &edge_type) {
|
||||
static constexpr auto kDummyGid = storage::v3::Gid::FromUint(0);
|
||||
auto maybe_edge = accessor_->CreateEdge(from->Id(storage::v3::View::NEW).GetValue(),
|
||||
to->Id(storage::v3::View::NEW).GetValue(), edge_type, kDummyGid);
|
||||
@ -87,7 +87,7 @@ class DbAccessor final {
|
||||
return EdgeAccessor(*maybe_edge);
|
||||
}
|
||||
|
||||
storage::v3::Result<std::optional<EdgeAccessor>> RemoveEdge(EdgeAccessor *edge) {
|
||||
storage::v3::ShardResult<std::optional<EdgeAccessor>> RemoveEdge(EdgeAccessor *edge) {
|
||||
auto res = accessor_->DeleteEdge(edge->FromVertex(), edge->ToVertex(), edge->Gid());
|
||||
if (res.HasError()) {
|
||||
return res.GetError();
|
||||
@ -101,7 +101,7 @@ class DbAccessor final {
|
||||
return std::make_optional<EdgeAccessor>(*value);
|
||||
}
|
||||
|
||||
storage::v3::Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> DetachRemoveVertex(
|
||||
storage::v3::ShardResult<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> DetachRemoveVertex(
|
||||
VertexAccessor *vertex_accessor) {
|
||||
using ReturnType = std::pair<VertexAccessor, std::vector<EdgeAccessor>>;
|
||||
|
||||
@ -125,7 +125,7 @@ class DbAccessor final {
|
||||
return std::make_optional<ReturnType>(vertex, std::move(deleted_edges));
|
||||
}
|
||||
|
||||
storage::v3::Result<std::optional<VertexAccessor>> RemoveVertex(VertexAccessor *vertex_accessor) {
|
||||
storage::v3::ShardResult<std::optional<VertexAccessor>> RemoveVertex(VertexAccessor *vertex_accessor) {
|
||||
auto res = accessor_->DeleteVertex(vertex_accessor);
|
||||
if (res.HasError()) {
|
||||
return res.GetError();
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "storage/v3/id_types.hpp"
|
||||
#include "storage/v3/property_store.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/view.hpp"
|
||||
#include "utils/memory.hpp"
|
||||
|
||||
@ -87,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::Error>;
|
||||
common::ErrorCode>;
|
||||
|
||||
} // namespace memgraph::storage::v3
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "storage/v3/mvcc.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/schema_validator.hpp"
|
||||
#include "storage/v3/vertex_accessor.hpp"
|
||||
#include "utils/memory_tracker.hpp"
|
||||
@ -54,13 +55,13 @@ const VertexId &EdgeAccessor::FromVertex() const { return from_vertex_; }
|
||||
|
||||
const VertexId &EdgeAccessor::ToVertex() const { return to_vertex_; }
|
||||
|
||||
Result<PropertyValue> EdgeAccessor::SetProperty(PropertyId property, const PropertyValue &value) {
|
||||
ShardResult<PropertyValue> EdgeAccessor::SetProperty(PropertyId property, const PropertyValue &value) {
|
||||
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
|
||||
if (!config_.properties_on_edges) return Error::PROPERTIES_DISABLED;
|
||||
if (!config_.properties_on_edges) return SHARD_ERROR(ErrorCode::PROPERTIES_DISABLED);
|
||||
|
||||
if (!PrepareForWrite(transaction_, edge_.ptr)) return Error::SERIALIZATION_ERROR;
|
||||
if (!PrepareForWrite(transaction_, edge_.ptr)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
if (edge_.ptr->deleted) return Error::DELETED_OBJECT;
|
||||
if (edge_.ptr->deleted) return SHARD_ERROR(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
|
||||
@ -75,12 +76,12 @@ Result<PropertyValue> EdgeAccessor::SetProperty(PropertyId property, const Prope
|
||||
return std::move(current_value);
|
||||
}
|
||||
|
||||
Result<std::map<PropertyId, PropertyValue>> EdgeAccessor::ClearProperties() {
|
||||
if (!config_.properties_on_edges) return Error::PROPERTIES_DISABLED;
|
||||
ShardResult<std::map<PropertyId, PropertyValue>> EdgeAccessor::ClearProperties() {
|
||||
if (!config_.properties_on_edges) return SHARD_ERROR(ErrorCode::PROPERTIES_DISABLED);
|
||||
|
||||
if (!PrepareForWrite(transaction_, edge_.ptr)) return Error::SERIALIZATION_ERROR;
|
||||
if (!PrepareForWrite(transaction_, edge_.ptr)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
if (edge_.ptr->deleted) return Error::DELETED_OBJECT;
|
||||
if (edge_.ptr->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
|
||||
auto properties = edge_.ptr->properties.Properties();
|
||||
for (const auto &property : properties) {
|
||||
@ -92,11 +93,11 @@ Result<std::map<PropertyId, PropertyValue>> EdgeAccessor::ClearProperties() {
|
||||
return std::move(properties);
|
||||
}
|
||||
|
||||
Result<PropertyValue> EdgeAccessor::GetProperty(View view, PropertyId property) const {
|
||||
ShardResult<PropertyValue> EdgeAccessor::GetProperty(View view, PropertyId property) const {
|
||||
return GetProperty(property, view);
|
||||
}
|
||||
|
||||
Result<PropertyValue> EdgeAccessor::GetProperty(PropertyId property, View view) const {
|
||||
ShardResult<PropertyValue> EdgeAccessor::GetProperty(PropertyId property, View view) const {
|
||||
if (!config_.properties_on_edges) return PropertyValue();
|
||||
auto exists = true;
|
||||
auto deleted = edge_.ptr->deleted;
|
||||
@ -128,12 +129,12 @@ Result<PropertyValue> EdgeAccessor::GetProperty(PropertyId property, View view)
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!exists) return Error::NONEXISTENT_OBJECT;
|
||||
if (!for_deleted_ && deleted) return Error::DELETED_OBJECT;
|
||||
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
Result<std::map<PropertyId, PropertyValue>> EdgeAccessor::Properties(View view) const {
|
||||
ShardResult<std::map<PropertyId, PropertyValue>> EdgeAccessor::Properties(View view) const {
|
||||
if (!config_.properties_on_edges) return std::map<PropertyId, PropertyValue>{};
|
||||
auto exists = true;
|
||||
auto deleted = edge_.ptr->deleted;
|
||||
@ -174,8 +175,8 @@ Result<std::map<PropertyId, PropertyValue>> EdgeAccessor::Properties(View view)
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!exists) return Error::NONEXISTENT_OBJECT;
|
||||
if (!for_deleted_ && deleted) return Error::DELETED_OBJECT;
|
||||
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
return std::move(properties);
|
||||
}
|
||||
|
||||
|
@ -56,19 +56,19 @@ class EdgeAccessor final {
|
||||
|
||||
/// Set a property value and return the old value.
|
||||
/// @throw std::bad_alloc
|
||||
Result<PropertyValue> SetProperty(PropertyId property, const PropertyValue &value);
|
||||
ShardResult<PropertyValue> SetProperty(PropertyId property, const PropertyValue &value);
|
||||
|
||||
/// Remove all properties and return old values for each removed property.
|
||||
/// @throw std::bad_alloc
|
||||
Result<std::map<PropertyId, PropertyValue>> ClearProperties();
|
||||
ShardResult<std::map<PropertyId, PropertyValue>> ClearProperties();
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
Result<PropertyValue> GetProperty(PropertyId property, View view) const;
|
||||
ShardResult<PropertyValue> GetProperty(PropertyId property, View view) const;
|
||||
|
||||
Result<PropertyValue> GetProperty(View view, PropertyId property) const;
|
||||
ShardResult<PropertyValue> GetProperty(View view, PropertyId property) const;
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
Result<std::map<PropertyId, PropertyValue>> Properties(View view) const;
|
||||
ShardResult<std::map<PropertyId, PropertyValue>> Properties(View view) const;
|
||||
|
||||
Gid Gid() const noexcept {
|
||||
if (config_.properties_on_edges) {
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "storage/v3/bindings/db_accessor.hpp"
|
||||
#include "storage/v3/bindings/pretty_print_ast_to_original_expression.hpp"
|
||||
#include "storage/v3/expr.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/value_conversions.hpp"
|
||||
|
||||
namespace memgraph::storage::v3 {
|
||||
@ -28,11 +29,11 @@ using conversions::ToMsgsVertexId;
|
||||
|
||||
namespace {
|
||||
|
||||
using AllEdgePropertyDataSructure = std::map<PropertyId, msgs::Value>;
|
||||
using SpecificEdgePropertyDataSructure = std::vector<msgs::Value>;
|
||||
using AllEdgePropertyDataStucture = std::map<PropertyId, msgs::Value>;
|
||||
using SpecificEdgePropertyDataStucture = std::vector<msgs::Value>;
|
||||
|
||||
using AllEdgeProperties = std::tuple<msgs::VertexId, msgs::Gid, AllEdgePropertyDataSructure>;
|
||||
using SpecificEdgeProperties = std::tuple<msgs::VertexId, msgs::Gid, SpecificEdgePropertyDataSructure>;
|
||||
using AllEdgeProperties = std::tuple<msgs::VertexId, msgs::Gid, AllEdgePropertyDataStucture>;
|
||||
using SpecificEdgeProperties = std::tuple<msgs::VertexId, msgs::Gid, SpecificEdgePropertyDataStucture>;
|
||||
|
||||
using SpecificEdgePropertiesVector = std::vector<SpecificEdgeProperties>;
|
||||
using AllEdgePropertiesVector = std::vector<AllEdgeProperties>;
|
||||
@ -59,13 +60,13 @@ std::optional<std::map<PropertyId, Value>> PrimaryKeysFromAccessor(const VertexA
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::optional<std::vector<msgs::Label>> FillUpSourceVertexSecondaryLabels(const std::optional<VertexAccessor> &v_acc,
|
||||
const msgs::ExpandOneRequest &req) {
|
||||
ShardResult<std::vector<msgs::Label>> FillUpSourceVertexSecondaryLabels(const std::optional<VertexAccessor> &v_acc,
|
||||
const msgs::ExpandOneRequest &req) {
|
||||
auto secondary_labels = v_acc->Labels(View::NEW);
|
||||
if (secondary_labels.HasError()) {
|
||||
spdlog::debug("Encountered an error while trying to get the secondary labels of a vertex. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
return std::nullopt;
|
||||
return secondary_labels.GetError();
|
||||
}
|
||||
|
||||
auto &sec_labels = secondary_labels.GetValue();
|
||||
@ -78,10 +79,10 @@ std::optional<std::vector<msgs::Label>> FillUpSourceVertexSecondaryLabels(const
|
||||
return msgs_secondary_labels;
|
||||
}
|
||||
|
||||
std::optional<std::map<PropertyId, Value>> FillUpSourceVertexProperties(const std::optional<VertexAccessor> &v_acc,
|
||||
const msgs::ExpandOneRequest &req,
|
||||
storage::v3::View view,
|
||||
const Schemas::Schema &schema) {
|
||||
ShardResult<std::map<PropertyId, Value>> FillUpSourceVertexProperties(const std::optional<VertexAccessor> &v_acc,
|
||||
const msgs::ExpandOneRequest &req,
|
||||
storage::v3::View view,
|
||||
const Schemas::Schema &schema) {
|
||||
std::map<PropertyId, Value> src_vertex_properties;
|
||||
|
||||
if (!req.src_vertex_properties) {
|
||||
@ -89,7 +90,7 @@ std::optional<std::map<PropertyId, Value>> FillUpSourceVertexProperties(const st
|
||||
if (props.HasError()) {
|
||||
spdlog::debug("Encountered an error while trying to access vertex properties. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
return std::nullopt;
|
||||
return props.GetError();
|
||||
}
|
||||
|
||||
for (auto &[key, val] : props.GetValue()) {
|
||||
@ -108,7 +109,7 @@ std::optional<std::map<PropertyId, Value>> FillUpSourceVertexProperties(const st
|
||||
if (prop_val.HasError()) {
|
||||
spdlog::debug("Encountered an error while trying to access vertex properties. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
return std::nullopt;
|
||||
return prop_val.GetError();
|
||||
}
|
||||
src_vertex_properties.insert(std::make_pair(prop, FromPropertyValueToValue(std::move(prop_val.GetValue()))));
|
||||
}
|
||||
@ -117,9 +118,9 @@ std::optional<std::map<PropertyId, Value>> FillUpSourceVertexProperties(const st
|
||||
return src_vertex_properties;
|
||||
}
|
||||
|
||||
std::optional<std::array<std::vector<EdgeAccessor>, 2>> FillUpConnectingEdges(
|
||||
ShardResult<std::array<std::vector<EdgeAccessor>, 2>> FillUpConnectingEdges(
|
||||
const std::optional<VertexAccessor> &v_acc, const msgs::ExpandOneRequest &req,
|
||||
const EdgeUniqunessFunction &maybe_filter_based_on_edge_uniquness) {
|
||||
const EdgeUniquenessFunction &maybe_filter_based_on_edge_uniqueness) {
|
||||
std::vector<EdgeTypeId> edge_types{};
|
||||
edge_types.reserve(req.edge_types.size());
|
||||
std::transform(req.edge_types.begin(), req.edge_types.end(), std::back_inserter(edge_types),
|
||||
@ -134,10 +135,10 @@ std::optional<std::array<std::vector<EdgeAccessor>, 2>> FillUpConnectingEdges(
|
||||
if (out_edges_result.HasError()) {
|
||||
spdlog::debug("Encountered an error while trying to get out-going EdgeAccessors. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
return std::nullopt;
|
||||
return out_edges_result.GetError();
|
||||
}
|
||||
out_edges =
|
||||
maybe_filter_based_on_edge_uniquness(std::move(out_edges_result.GetValue()), msgs::EdgeDirection::OUT);
|
||||
maybe_filter_based_on_edge_uniqueness(std::move(out_edges_result.GetValue()), msgs::EdgeDirection::OUT);
|
||||
break;
|
||||
}
|
||||
case msgs::EdgeDirection::IN: {
|
||||
@ -146,9 +147,9 @@ std::optional<std::array<std::vector<EdgeAccessor>, 2>> FillUpConnectingEdges(
|
||||
spdlog::debug(
|
||||
"Encountered an error while trying to get in-going EdgeAccessors. Transaction id: {}"[req.transaction_id
|
||||
.logical_id]);
|
||||
return std::nullopt;
|
||||
return in_edges_result.GetError();
|
||||
}
|
||||
in_edges = maybe_filter_based_on_edge_uniquness(std::move(in_edges_result.GetValue()), msgs::EdgeDirection::IN);
|
||||
in_edges = maybe_filter_based_on_edge_uniqueness(std::move(in_edges_result.GetValue()), msgs::EdgeDirection::IN);
|
||||
break;
|
||||
}
|
||||
case msgs::EdgeDirection::BOTH: {
|
||||
@ -156,17 +157,17 @@ std::optional<std::array<std::vector<EdgeAccessor>, 2>> FillUpConnectingEdges(
|
||||
if (in_edges_result.HasError()) {
|
||||
spdlog::debug("Encountered an error while trying to get in-going EdgeAccessors. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
return std::nullopt;
|
||||
return in_edges_result.GetError();
|
||||
}
|
||||
in_edges = maybe_filter_based_on_edge_uniquness(std::move(in_edges_result.GetValue()), msgs::EdgeDirection::IN);
|
||||
in_edges = maybe_filter_based_on_edge_uniqueness(std::move(in_edges_result.GetValue()), msgs::EdgeDirection::IN);
|
||||
auto out_edges_result = v_acc->OutEdges(View::NEW, edge_types);
|
||||
if (out_edges_result.HasError()) {
|
||||
spdlog::debug("Encountered an error while trying to get out-going EdgeAccessors. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
return std::nullopt;
|
||||
return out_edges_result.GetError();
|
||||
}
|
||||
out_edges =
|
||||
maybe_filter_based_on_edge_uniquness(std::move(out_edges_result.GetValue()), msgs::EdgeDirection::OUT);
|
||||
maybe_filter_based_on_edge_uniqueness(std::move(out_edges_result.GetValue()), msgs::EdgeDirection::OUT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -174,28 +175,29 @@ std::optional<std::array<std::vector<EdgeAccessor>, 2>> FillUpConnectingEdges(
|
||||
}
|
||||
|
||||
template <bool are_in_edges>
|
||||
bool FillEdges(const std::vector<EdgeAccessor> &edges, msgs::ExpandOneResultRow &row, const EdgeFiller &edge_filler) {
|
||||
ShardResult<void> FillEdges(const std::vector<EdgeAccessor> &edges, msgs::ExpandOneResultRow &row,
|
||||
const EdgeFiller &edge_filler) {
|
||||
for (const auto &edge : edges) {
|
||||
if (!edge_filler(edge, are_in_edges, row)) {
|
||||
return false;
|
||||
if (const auto res = edge_filler(edge, are_in_edges, row); res.HasError()) {
|
||||
return res.GetError();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}; // namespace
|
||||
|
||||
std::optional<std::map<PropertyId, Value>> CollectSpecificPropertiesFromAccessor(const VertexAccessor &acc,
|
||||
const std::vector<PropertyId> &props,
|
||||
View view) {
|
||||
ShardResult<std::map<PropertyId, Value>> CollectSpecificPropertiesFromAccessor(const VertexAccessor &acc,
|
||||
const std::vector<PropertyId> &props,
|
||||
View view) {
|
||||
std::map<PropertyId, Value> ret;
|
||||
|
||||
for (const auto &prop : props) {
|
||||
auto result = acc.GetProperty(prop, view);
|
||||
if (result.HasError()) {
|
||||
spdlog::debug("Encountered an Error while trying to get a vertex property.");
|
||||
return std::nullopt;
|
||||
return result.GetError();
|
||||
}
|
||||
auto &value = result.GetValue();
|
||||
ret.emplace(std::make_pair(prop, FromPropertyValueToValue(std::move(value))));
|
||||
@ -218,13 +220,13 @@ std::vector<TypedValue> EvaluateVertexExpressions(DbAccessor &dba, const VertexA
|
||||
return evaluated_expressions;
|
||||
}
|
||||
|
||||
std::optional<std::map<PropertyId, Value>> CollectAllPropertiesFromAccessor(const VertexAccessor &acc, View view,
|
||||
const Schemas::Schema &schema) {
|
||||
ShardResult<std::map<PropertyId, Value>> CollectAllPropertiesFromAccessor(const VertexAccessor &acc, View view,
|
||||
const Schemas::Schema &schema) {
|
||||
std::map<PropertyId, Value> ret;
|
||||
auto props = acc.Properties(view);
|
||||
if (props.HasError()) {
|
||||
spdlog::debug("Encountered an error while trying to get vertex properties.");
|
||||
return std::nullopt;
|
||||
return props.GetError();
|
||||
}
|
||||
|
||||
auto &properties = props.GetValue();
|
||||
@ -242,9 +244,9 @@ std::optional<std::map<PropertyId, Value>> CollectAllPropertiesFromAccessor(cons
|
||||
return ret;
|
||||
}
|
||||
|
||||
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,
|
||||
@ -295,12 +297,13 @@ EdgeFiller InitializeEdgeFillerFunction(const msgs::ExpandOneRequest &req) {
|
||||
EdgeFiller edge_filler;
|
||||
|
||||
if (!req.edge_properties) {
|
||||
edge_filler = [transaction_id = req.transaction_id.logical_id](const EdgeAccessor &edge, const bool is_in_edge,
|
||||
msgs::ExpandOneResultRow &result_row) -> bool {
|
||||
edge_filler = [transaction_id = req.transaction_id.logical_id](
|
||||
const EdgeAccessor &edge, const bool is_in_edge,
|
||||
msgs::ExpandOneResultRow &result_row) -> ShardResult<void> {
|
||||
auto properties_results = edge.Properties(View::NEW);
|
||||
if (properties_results.HasError()) {
|
||||
spdlog::debug("Encountered an error while trying to get edge properties. Transaction id: {}", transaction_id);
|
||||
return false;
|
||||
return properties_results.GetError();
|
||||
}
|
||||
|
||||
std::map<PropertyId, msgs::Value> value_properties;
|
||||
@ -315,12 +318,12 @@ EdgeFiller InitializeEdgeFillerFunction(const msgs::ExpandOneRequest &req) {
|
||||
} else {
|
||||
result_row.out_edges_with_all_properties.push_back(std::move(edges));
|
||||
}
|
||||
return true;
|
||||
return {};
|
||||
};
|
||||
} else {
|
||||
// TODO(gvolfing) - do we want to set the action_successful here?
|
||||
edge_filler = [&req](const EdgeAccessor &edge, const bool is_in_edge,
|
||||
msgs::ExpandOneResultRow &result_row) -> bool {
|
||||
msgs::ExpandOneResultRow &result_row) -> ShardResult<void> {
|
||||
std::vector<msgs::Value> value_properties;
|
||||
value_properties.reserve(req.edge_properties.value().size());
|
||||
for (const auto &edge_prop : req.edge_properties.value()) {
|
||||
@ -328,7 +331,7 @@ EdgeFiller InitializeEdgeFillerFunction(const msgs::ExpandOneRequest &req) {
|
||||
if (property_result.HasError()) {
|
||||
spdlog::debug("Encountered an error while trying to get edge properties. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
return false;
|
||||
return property_result.GetError();
|
||||
}
|
||||
value_properties.emplace_back(FromPropertyValueToValue(std::move(property_result.GetValue())));
|
||||
}
|
||||
@ -340,7 +343,7 @@ EdgeFiller InitializeEdgeFillerFunction(const msgs::ExpandOneRequest &req) {
|
||||
} else {
|
||||
result_row.out_edges_with_specific_properties.push_back(std::move(edges));
|
||||
}
|
||||
return true;
|
||||
return {};
|
||||
};
|
||||
}
|
||||
|
||||
@ -355,83 +358,81 @@ bool FilterOnVertex(DbAccessor &dba, const storage::v3::VertexAccessor &v_acc, c
|
||||
});
|
||||
}
|
||||
|
||||
std::optional<msgs::ExpandOneResultRow> GetExpandOneResult(
|
||||
ShardResult<msgs::ExpandOneResultRow> 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_uniqueness, const EdgeFiller &edge_filler,
|
||||
const Schemas::Schema &schema) {
|
||||
/// Fill up source vertex
|
||||
const auto primary_key = ConvertPropertyVector(src_vertex.second);
|
||||
auto v_acc = acc.FindVertex(primary_key, View::NEW);
|
||||
|
||||
msgs::Vertex source_vertex = {.id = src_vertex};
|
||||
if (const auto maybe_secondary_labels = FillUpSourceVertexSecondaryLabels(v_acc, req); maybe_secondary_labels) {
|
||||
source_vertex.labels = *maybe_secondary_labels;
|
||||
} else {
|
||||
return std::nullopt;
|
||||
auto maybe_secondary_labels = FillUpSourceVertexSecondaryLabels(v_acc, req);
|
||||
if (maybe_secondary_labels.HasError()) {
|
||||
return maybe_secondary_labels.GetError();
|
||||
}
|
||||
source_vertex.labels = std::move(*maybe_secondary_labels);
|
||||
|
||||
auto src_vertex_properties = FillUpSourceVertexProperties(v_acc, req, storage::v3::View::NEW, schema);
|
||||
|
||||
if (!src_vertex_properties) {
|
||||
return std::nullopt;
|
||||
if (src_vertex_properties.HasError()) {
|
||||
return src_vertex_properties.GetError();
|
||||
}
|
||||
|
||||
/// Fill up connecting edges
|
||||
auto fill_up_connecting_edges = FillUpConnectingEdges(v_acc, req, maybe_filter_based_on_edge_uniquness);
|
||||
if (!fill_up_connecting_edges) {
|
||||
return std::nullopt;
|
||||
auto fill_up_connecting_edges = FillUpConnectingEdges(v_acc, req, maybe_filter_based_on_edge_uniqueness);
|
||||
if (fill_up_connecting_edges.HasError()) {
|
||||
return fill_up_connecting_edges.GetError();
|
||||
}
|
||||
|
||||
auto [in_edges, out_edges] = fill_up_connecting_edges.value();
|
||||
auto [in_edges, out_edges] = fill_up_connecting_edges.GetValue();
|
||||
|
||||
msgs::ExpandOneResultRow result_row;
|
||||
result_row.src_vertex = std::move(source_vertex);
|
||||
result_row.src_vertex_properties = std::move(*src_vertex_properties);
|
||||
static constexpr bool kInEdges = true;
|
||||
static constexpr bool kOutEdges = false;
|
||||
if (!in_edges.empty() && !FillEdges<kInEdges>(in_edges, result_row, edge_filler)) {
|
||||
return std::nullopt;
|
||||
if (const auto fill_edges_res = FillEdges<kInEdges>(in_edges, result_row, edge_filler); fill_edges_res.HasError()) {
|
||||
return fill_edges_res.GetError();
|
||||
}
|
||||
if (!out_edges.empty() && !FillEdges<kOutEdges>(out_edges, result_row, edge_filler)) {
|
||||
return std::nullopt;
|
||||
if (const auto fill_edges_res = FillEdges<kOutEdges>(out_edges, result_row, edge_filler); fill_edges_res.HasError()) {
|
||||
return fill_edges_res.GetError();
|
||||
}
|
||||
|
||||
return result_row;
|
||||
}
|
||||
|
||||
std::optional<msgs::ExpandOneResultRow> GetExpandOneResult(
|
||||
ShardResult<msgs::ExpandOneResultRow> GetExpandOneResult(
|
||||
VertexAccessor v_acc, msgs::VertexId src_vertex, const msgs::ExpandOneRequest &req,
|
||||
std::vector<EdgeAccessor> in_edge_accessors, std::vector<EdgeAccessor> out_edge_accessors,
|
||||
const EdgeUniqunessFunction &maybe_filter_based_on_edge_uniquness, const EdgeFiller &edge_filler,
|
||||
const EdgeUniquenessFunction &maybe_filter_based_on_edge_uniqueness, const EdgeFiller &edge_filler,
|
||||
const Schemas::Schema &schema) {
|
||||
/// Fill up source vertex
|
||||
msgs::Vertex source_vertex = {.id = src_vertex};
|
||||
if (const auto maybe_secondary_labels = FillUpSourceVertexSecondaryLabels(v_acc, req); maybe_secondary_labels) {
|
||||
source_vertex.labels = *maybe_secondary_labels;
|
||||
} else {
|
||||
return std::nullopt;
|
||||
auto maybe_secondary_labels = FillUpSourceVertexSecondaryLabels(v_acc, req);
|
||||
if (maybe_secondary_labels.HasError()) {
|
||||
return maybe_secondary_labels.GetError();
|
||||
}
|
||||
source_vertex.labels = std::move(*maybe_secondary_labels);
|
||||
|
||||
/// Fill up source vertex properties
|
||||
auto src_vertex_properties = FillUpSourceVertexProperties(v_acc, req, storage::v3::View::NEW, schema);
|
||||
if (!src_vertex_properties) {
|
||||
return std::nullopt;
|
||||
if (src_vertex_properties.HasError()) {
|
||||
return src_vertex_properties.GetError();
|
||||
}
|
||||
|
||||
/// Fill up connecting edges
|
||||
auto in_edges = maybe_filter_based_on_edge_uniquness(std::move(in_edge_accessors), msgs::EdgeDirection::IN);
|
||||
auto out_edges = maybe_filter_based_on_edge_uniquness(std::move(out_edge_accessors), msgs::EdgeDirection::OUT);
|
||||
auto in_edges = maybe_filter_based_on_edge_uniqueness(std::move(in_edge_accessors), msgs::EdgeDirection::IN);
|
||||
auto out_edges = maybe_filter_based_on_edge_uniqueness(std::move(out_edge_accessors), msgs::EdgeDirection::OUT);
|
||||
|
||||
msgs::ExpandOneResultRow result_row;
|
||||
result_row.src_vertex = std::move(source_vertex);
|
||||
result_row.src_vertex_properties = std::move(*src_vertex_properties);
|
||||
static constexpr bool kInEdges = true;
|
||||
static constexpr bool kOutEdges = false;
|
||||
if (!in_edges.empty() && !FillEdges<kInEdges>(in_edges, result_row, edge_filler)) {
|
||||
return std::nullopt;
|
||||
if (const auto fill_edges_res = FillEdges<kInEdges>(in_edges, result_row, edge_filler); fill_edges_res.HasError()) {
|
||||
return fill_edges_res.GetError();
|
||||
}
|
||||
if (!out_edges.empty() && !FillEdges<kOutEdges>(out_edges, result_row, edge_filler)) {
|
||||
return std::nullopt;
|
||||
if (const auto fill_edges_res = FillEdges<kOutEdges>(out_edges, result_row, edge_filler); fill_edges_res.HasError()) {
|
||||
return fill_edges_res.GetError();
|
||||
}
|
||||
|
||||
return result_row;
|
||||
@ -525,38 +526,4 @@ std::vector<Element<EdgeAccessor>> OrderByEdges(DbAccessor &dba, std::vector<Edg
|
||||
return ordered;
|
||||
}
|
||||
|
||||
void LogResultError(const ResultErrorType &error, const std::string_view action) {
|
||||
std::visit(
|
||||
[action]<typename T>(T &&error) {
|
||||
using ErrorType = std::remove_cvref_t<T>;
|
||||
if constexpr (std::is_same_v<ErrorType, SchemaViolation>) {
|
||||
spdlog::debug("{} failed with error: SchemaViolation", action);
|
||||
} else if constexpr (std::is_same_v<ErrorType, Error>) {
|
||||
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(utils::kAlwaysFalse<T>, "Missing type from variant visitor");
|
||||
}
|
||||
},
|
||||
error);
|
||||
}
|
||||
|
||||
} // namespace memgraph::storage::v3
|
||||
|
@ -25,8 +25,9 @@
|
||||
|
||||
namespace memgraph::storage::v3 {
|
||||
using EdgeAccessors = std::vector<storage::v3::EdgeAccessor>;
|
||||
using EdgeUniqunessFunction = std::function<EdgeAccessors(EdgeAccessors &&, msgs::EdgeDirection)>;
|
||||
using EdgeFiller = std::function<bool(const EdgeAccessor &edge, bool is_in_edge, msgs::ExpandOneResultRow &result_row)>;
|
||||
using EdgeUniquenessFunction = std::function<EdgeAccessors(EdgeAccessors &&, msgs::EdgeDirection)>;
|
||||
using EdgeFiller =
|
||||
std::function<ShardResult<void>(const EdgeAccessor &edge, bool is_in_edge, msgs::ExpandOneResultRow &result_row)>;
|
||||
using msgs::Value;
|
||||
|
||||
template <typename T>
|
||||
@ -162,8 +163,6 @@ std::vector<Element<VertexAccessor>> OrderByVertices(DbAccessor &dba, TIterable
|
||||
return ordered;
|
||||
}
|
||||
|
||||
void LogResultError(const ResultErrorType &error, std::string_view action);
|
||||
|
||||
std::vector<Element<EdgeAccessor>> OrderByEdges(DbAccessor &dba, std::vector<EdgeAccessor> &iterable,
|
||||
std::vector<msgs::OrderBy> &order_by_edges,
|
||||
const VertexAccessor &vertex_acc);
|
||||
@ -185,25 +184,25 @@ std::vector<TypedValue> EvaluateVertexExpressions(DbAccessor &dba, const VertexA
|
||||
const std::vector<std::string> &expressions,
|
||||
std::string_view node_name);
|
||||
|
||||
std::optional<std::map<PropertyId, Value>> CollectSpecificPropertiesFromAccessor(const VertexAccessor &acc,
|
||||
const std::vector<PropertyId> &props,
|
||||
View view);
|
||||
ShardResult<std::map<PropertyId, Value>> CollectSpecificPropertiesFromAccessor(const VertexAccessor &acc,
|
||||
const std::vector<PropertyId> &props,
|
||||
View view);
|
||||
|
||||
std::optional<std::map<PropertyId, Value>> CollectAllPropertiesFromAccessor(const VertexAccessor &acc, View view,
|
||||
const Schemas::Schema &schema);
|
||||
ShardResult<std::map<PropertyId, Value>> CollectAllPropertiesFromAccessor(const VertexAccessor &acc, View view,
|
||||
const Schemas::Schema &schema);
|
||||
|
||||
EdgeUniqunessFunction InitializeEdgeUniqunessFunction(bool only_unique_neighbor_rows);
|
||||
EdgeUniquenessFunction InitializeEdgeUniquenessFunction(bool only_unique_neighbor_rows);
|
||||
|
||||
EdgeFiller InitializeEdgeFillerFunction(const msgs::ExpandOneRequest &req);
|
||||
|
||||
std::optional<msgs::ExpandOneResultRow> GetExpandOneResult(
|
||||
ShardResult<msgs::ExpandOneResultRow> 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_uniqueness, const EdgeFiller &edge_filler,
|
||||
const Schemas::Schema &schema);
|
||||
|
||||
std::optional<msgs::ExpandOneResultRow> GetExpandOneResult(
|
||||
ShardResult<msgs::ExpandOneResultRow> GetExpandOneResult(
|
||||
VertexAccessor v_acc, msgs::VertexId src_vertex, const msgs::ExpandOneRequest &req,
|
||||
std::vector<EdgeAccessor> in_edge_accessors, std::vector<EdgeAccessor> out_edge_accessors,
|
||||
const EdgeUniqunessFunction &maybe_filter_based_on_edge_uniquness, const EdgeFiller &edge_filler,
|
||||
const EdgeUniquenessFunction &maybe_filter_based_on_edge_uniqueness, const EdgeFiller &edge_filler,
|
||||
const Schemas::Schema &schema);
|
||||
} // namespace memgraph::storage::v3
|
||||
|
@ -11,24 +11,43 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <experimental/source_location>
|
||||
#include <string>
|
||||
#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 Error : uint8_t {
|
||||
SERIALIZATION_ERROR,
|
||||
NONEXISTENT_OBJECT,
|
||||
DELETED_OBJECT,
|
||||
VERTEX_HAS_EDGES,
|
||||
PROPERTIES_DISABLED,
|
||||
VERTEX_ALREADY_INSERTED
|
||||
struct ShardError {
|
||||
ShardError(common::ErrorCode code, std::string message, const std::experimental::source_location location)
|
||||
: code{code}, message{std::move(message)}, source{fmt::format("{}:{}", location.file_name(), location.line())} {}
|
||||
|
||||
ShardError(common::ErrorCode code, const std::experimental::source_location location)
|
||||
: code{code}, source{fmt::format("{}:{}", location.file_name(), location.line())} {}
|
||||
|
||||
common::ErrorCode code;
|
||||
std::string message;
|
||||
std::string source;
|
||||
|
||||
inline friend bool operator==(const ShardError &lhs, const ShardError &rhs) { return lhs.code == rhs.code; }
|
||||
|
||||
inline friend bool operator==(const ShardError &lhs, const common::ErrorCode rhs) { return lhs.code == rhs; }
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
|
||||
#define SHARD_ERROR(error, ...) \
|
||||
({ \
|
||||
using ErrorCode = memgraph::common::ErrorCode; \
|
||||
memgraph::storage::v3::ShardError(error, GET_MESSAGE(__VA_ARGS__), std::experimental::source_location::current()); \
|
||||
})
|
||||
|
||||
template <class TValue>
|
||||
using Result = utils::BasicResult<Error, TValue>;
|
||||
using ShardResult = utils::BasicResult<ShardError, TValue>;
|
||||
|
||||
} // namespace memgraph::storage::v3
|
||||
|
@ -16,67 +16,58 @@
|
||||
#include <ranges>
|
||||
|
||||
#include "common/types.hpp"
|
||||
#include "storage/v3/name_id_mapper.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/schemas.hpp"
|
||||
|
||||
namespace memgraph::storage::v3 {
|
||||
|
||||
bool operator==(const SchemaViolation &lhs, const SchemaViolation &rhs) {
|
||||
return lhs.status == rhs.status && lhs.label == rhs.label &&
|
||||
lhs.violated_schema_property == rhs.violated_schema_property &&
|
||||
lhs.violated_property_value == rhs.violated_property_value;
|
||||
}
|
||||
SchemaValidator::SchemaValidator(Schemas &schemas, const NameIdMapper &name_id_mapper)
|
||||
: schemas_{&schemas}, name_id_mapper_{&name_id_mapper} {}
|
||||
|
||||
SchemaViolation::SchemaViolation(ValidationStatus status, LabelId label) : status{status}, label{label} {}
|
||||
|
||||
SchemaViolation::SchemaViolation(ValidationStatus status, LabelId label, SchemaProperty violated_schema_property)
|
||||
: status{status}, label{label}, violated_schema_property{violated_schema_property} {}
|
||||
|
||||
SchemaViolation::SchemaViolation(ValidationStatus status, LabelId label, SchemaProperty violated_schema_property,
|
||||
PropertyValue violated_property_value)
|
||||
: status{status},
|
||||
label{label},
|
||||
violated_schema_property{violated_schema_property},
|
||||
violated_property_value{violated_property_value} {}
|
||||
|
||||
SchemaValidator::SchemaValidator(Schemas &schemas) : schemas_{schemas} {}
|
||||
|
||||
std::optional<SchemaViolation> SchemaValidator::ValidateVertexCreate(
|
||||
LabelId primary_label, const std::vector<LabelId> &labels,
|
||||
const std::vector<PropertyValue> &primary_properties) const {
|
||||
ShardResult<void> SchemaValidator::ValidateVertexCreate(LabelId primary_label, const std::vector<LabelId> &labels,
|
||||
const std::vector<PropertyValue> &primary_properties) const {
|
||||
// Schema on primary label
|
||||
const auto *schema = schemas_.GetSchema(primary_label);
|
||||
const auto *schema = schemas_->GetSchema(primary_label);
|
||||
if (schema == nullptr) {
|
||||
return SchemaViolation(SchemaViolation::ValidationStatus::NO_SCHEMA_DEFINED_FOR_LABEL, primary_label);
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_NO_SCHEMA_DEFINED_FOR_LABEL, "Schema not defined for label :{}",
|
||||
name_id_mapper_->IdToName(primary_label.AsInt()));
|
||||
}
|
||||
|
||||
// Is there another primary label among secondary labels
|
||||
for (const auto &secondary_label : labels) {
|
||||
if (schemas_.GetSchema(secondary_label)) {
|
||||
return SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, secondary_label);
|
||||
if (schemas_->GetSchema(secondary_label)) {
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY,
|
||||
"Cannot add label :{}, since it is defined as a primary label",
|
||||
name_id_mapper_->IdToName(secondary_label.AsInt()));
|
||||
}
|
||||
}
|
||||
|
||||
// Quick size check
|
||||
if (schema->second.size() != primary_properties.size()) {
|
||||
return SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PRIMARY_PROPERTIES_UNDEFINED, primary_label);
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED,
|
||||
"Not all primary properties have been specified for :{} vertex",
|
||||
name_id_mapper_->IdToName(primary_label.AsInt()));
|
||||
}
|
||||
// Check only properties defined by schema
|
||||
for (size_t i{0}; i < schema->second.size(); ++i) {
|
||||
// Check schema property type
|
||||
if (auto property_schema_type = PropertyTypeToSchemaType(primary_properties[i]);
|
||||
property_schema_type && *property_schema_type != schema->second[i].type) {
|
||||
return SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PROPERTY_WRONG_TYPE, primary_label,
|
||||
schema->second[i], primary_properties[i]);
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE,
|
||||
"Property {} is of wrong type, expected {}, actual {}",
|
||||
name_id_mapper_->IdToName(schema->second[i].property_id.AsInt()),
|
||||
SchemaTypeToString(schema->second[i].type), SchemaTypeToString(*property_schema_type));
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<SchemaViolation> SchemaValidator::ValidatePropertyUpdate(const LabelId primary_label,
|
||||
const PropertyId property_id) const {
|
||||
ShardResult<void> SchemaValidator::ValidatePropertyUpdate(const LabelId primary_label,
|
||||
const PropertyId property_id) const {
|
||||
// Verify existence of schema on primary label
|
||||
const auto *schema = schemas_.GetSchema(primary_label);
|
||||
const auto *schema = schemas_->GetSchema(primary_label);
|
||||
MG_ASSERT(schema, "Cannot validate against non existing schema!");
|
||||
|
||||
// Verify that updating property is not part of schema
|
||||
@ -84,34 +75,37 @@ std::optional<SchemaViolation> SchemaValidator::ValidatePropertyUpdate(const Lab
|
||||
schema->second,
|
||||
[property_id](const auto &schema_property) { return property_id == schema_property.property_id; });
|
||||
schema_property != schema->second.end()) {
|
||||
return SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_KEY, primary_label,
|
||||
*schema_property);
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY,
|
||||
"Cannot update primary property {} of schema on label :{}",
|
||||
name_id_mapper_->IdToName(schema_property->property_id.AsInt()),
|
||||
name_id_mapper_->IdToName(primary_label.AsInt()));
|
||||
}
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::optional<SchemaViolation> SchemaValidator::ValidateLabelUpdate(const LabelId label) const {
|
||||
const auto *schema = schemas_.GetSchema(label);
|
||||
ShardResult<void> SchemaValidator::ValidateLabelUpdate(const LabelId label) const {
|
||||
const auto *schema = schemas_->GetSchema(label);
|
||||
if (schema) {
|
||||
return SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_LABEL, label);
|
||||
return SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL, "Cannot add/remove primary label :{}",
|
||||
name_id_mapper_->IdToName(label.AsInt()));
|
||||
}
|
||||
return std::nullopt;
|
||||
return {};
|
||||
}
|
||||
|
||||
const Schemas::Schema *SchemaValidator::GetSchema(LabelId label) const { return schemas_.GetSchema(label); }
|
||||
const Schemas::Schema *SchemaValidator::GetSchema(LabelId label) const { return schemas_->GetSchema(label); }
|
||||
|
||||
VertexValidator::VertexValidator(const SchemaValidator &schema_validator, const LabelId primary_label)
|
||||
: schema_validator{&schema_validator}, primary_label_{primary_label} {}
|
||||
|
||||
std::optional<SchemaViolation> VertexValidator::ValidatePropertyUpdate(PropertyId property_id) const {
|
||||
ShardResult<void> VertexValidator::ValidatePropertyUpdate(PropertyId property_id) const {
|
||||
return schema_validator->ValidatePropertyUpdate(primary_label_, property_id);
|
||||
};
|
||||
|
||||
std::optional<SchemaViolation> VertexValidator::ValidateAddLabel(LabelId label) const {
|
||||
ShardResult<void> VertexValidator::ValidateAddLabel(LabelId label) const {
|
||||
return schema_validator->ValidateLabelUpdate(label);
|
||||
}
|
||||
|
||||
std::optional<SchemaViolation> VertexValidator::ValidateRemoveLabel(LabelId label) const {
|
||||
ShardResult<void> VertexValidator::ValidateRemoveLabel(LabelId label) const {
|
||||
return schema_validator->ValidateLabelUpdate(label);
|
||||
}
|
||||
|
||||
|
@ -11,68 +11,43 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <variant>
|
||||
|
||||
#include "storage/v2/result.hpp"
|
||||
#include "storage/v3/id_types.hpp"
|
||||
#include "storage/v3/name_id_mapper.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/schemas.hpp"
|
||||
|
||||
namespace memgraph::storage::v3 {
|
||||
|
||||
struct SchemaViolation {
|
||||
enum class ValidationStatus : uint8_t {
|
||||
NO_SCHEMA_DEFINED_FOR_LABEL,
|
||||
VERTEX_PROPERTY_WRONG_TYPE,
|
||||
VERTEX_UPDATE_PRIMARY_KEY,
|
||||
VERTEX_UPDATE_PRIMARY_LABEL,
|
||||
VERTEX_SECONDARY_LABEL_IS_PRIMARY,
|
||||
VERTEX_PRIMARY_PROPERTIES_UNDEFINED,
|
||||
};
|
||||
|
||||
SchemaViolation(ValidationStatus status, LabelId label);
|
||||
|
||||
SchemaViolation(ValidationStatus status, LabelId label, SchemaProperty violated_schema_property);
|
||||
|
||||
SchemaViolation(ValidationStatus status, LabelId label, SchemaProperty violated_schema_property,
|
||||
PropertyValue violated_property_value);
|
||||
|
||||
friend bool operator==(const SchemaViolation &lhs, const SchemaViolation &rhs);
|
||||
|
||||
ValidationStatus status;
|
||||
LabelId label;
|
||||
std::optional<SchemaProperty> violated_schema_property;
|
||||
std::optional<PropertyValue> violated_property_value;
|
||||
};
|
||||
|
||||
class SchemaValidator {
|
||||
public:
|
||||
explicit SchemaValidator(Schemas &schemas);
|
||||
explicit SchemaValidator(Schemas &schemas, const NameIdMapper &name_id_mapper);
|
||||
|
||||
[[nodiscard]] std::optional<SchemaViolation> ValidateVertexCreate(
|
||||
LabelId primary_label, const std::vector<LabelId> &labels,
|
||||
const std::vector<PropertyValue> &primary_properties) const;
|
||||
[[nodiscard]] ShardResult<void> ValidateVertexCreate(LabelId primary_label, const std::vector<LabelId> &labels,
|
||||
const std::vector<PropertyValue> &primary_properties) const;
|
||||
|
||||
[[nodiscard]] std::optional<SchemaViolation> ValidatePropertyUpdate(LabelId primary_label,
|
||||
PropertyId property_id) const;
|
||||
[[nodiscard]] ShardResult<void> ValidatePropertyUpdate(LabelId primary_label, PropertyId property_id) const;
|
||||
|
||||
[[nodiscard]] std::optional<SchemaViolation> ValidateLabelUpdate(LabelId label) const;
|
||||
[[nodiscard]] ShardResult<void> ValidateLabelUpdate(LabelId label) const;
|
||||
|
||||
const Schemas::Schema *GetSchema(LabelId label) const;
|
||||
|
||||
private:
|
||||
Schemas &schemas_;
|
||||
Schemas *schemas_;
|
||||
const NameIdMapper *name_id_mapper_;
|
||||
};
|
||||
|
||||
struct VertexValidator {
|
||||
explicit VertexValidator(const SchemaValidator &schema_validator, LabelId primary_label);
|
||||
|
||||
[[nodiscard]] std::optional<SchemaViolation> ValidatePropertyUpdate(PropertyId property_id) const;
|
||||
[[nodiscard]] ShardResult<void> ValidatePropertyUpdate(PropertyId property_id) const;
|
||||
|
||||
[[nodiscard]] std::optional<SchemaViolation> ValidateAddLabel(LabelId label) const;
|
||||
[[nodiscard]] ShardResult<void> ValidateAddLabel(LabelId label) const;
|
||||
|
||||
[[nodiscard]] std::optional<SchemaViolation> ValidateRemoveLabel(LabelId label) const;
|
||||
[[nodiscard]] ShardResult<void> ValidateRemoveLabel(LabelId label) const;
|
||||
|
||||
const SchemaValidator *schema_validator;
|
||||
|
||||
|
@ -31,9 +31,10 @@
|
||||
#include "storage/v3/indices.hpp"
|
||||
#include "storage/v3/key_store.hpp"
|
||||
#include "storage/v3/mvcc.hpp"
|
||||
#include "storage/v3/name_id_mapper.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/schema_validator.hpp"
|
||||
#include "storage/v3/shard_operation_result.hpp"
|
||||
#include "storage/v3/transaction.hpp"
|
||||
#include "storage/v3/vertex.hpp"
|
||||
#include "storage/v3/vertex_accessor.hpp"
|
||||
@ -327,7 +328,7 @@ Shard::Shard(const LabelId primary_label, const PrimaryKey min_primary_key,
|
||||
: primary_label_{primary_label},
|
||||
min_primary_key_{min_primary_key},
|
||||
max_primary_key_{max_primary_key},
|
||||
schema_validator_{schemas_},
|
||||
schema_validator_{schemas_, name_id_mapper_},
|
||||
vertex_validator_{schema_validator_, primary_label},
|
||||
indices_{config.items, vertex_validator_},
|
||||
isolation_level_{config.transaction.isolation_level},
|
||||
@ -344,7 +345,7 @@ Shard::~Shard() {}
|
||||
Shard::Accessor::Accessor(Shard &shard, Transaction &transaction)
|
||||
: shard_(&shard), transaction_(&transaction), config_(shard_->config_.items) {}
|
||||
|
||||
ShardOperationResult<VertexAccessor> Shard::Accessor::CreateVertexAndValidate(
|
||||
ShardResult<VertexAccessor> Shard::Accessor::CreateVertexAndValidate(
|
||||
const std::vector<LabelId> &labels, const std::vector<PropertyValue> &primary_properties,
|
||||
const std::vector<std::pair<PropertyId, PropertyValue>> &properties) {
|
||||
OOMExceptionEnabler oom_exception;
|
||||
@ -352,8 +353,8 @@ ShardOperationResult<VertexAccessor> Shard::Accessor::CreateVertexAndValidate(
|
||||
|
||||
auto maybe_schema_violation =
|
||||
GetSchemaValidator().ValidateVertexCreate(shard_->primary_label_, labels, primary_properties);
|
||||
if (maybe_schema_violation) {
|
||||
return {std::move(*maybe_schema_violation)};
|
||||
if (maybe_schema_violation.HasError()) {
|
||||
return {std::move(maybe_schema_violation.GetError())};
|
||||
}
|
||||
|
||||
auto acc = shard_->vertices_.access();
|
||||
@ -363,7 +364,7 @@ ShardOperationResult<VertexAccessor> Shard::Accessor::CreateVertexAndValidate(
|
||||
|
||||
VertexAccessor vertex_acc{&it->vertex, transaction_, &shard_->indices_, config_, shard_->vertex_validator_};
|
||||
if (!inserted) {
|
||||
return {Error::VERTEX_ALREADY_INSERTED};
|
||||
return SHARD_ERROR(ErrorCode::VERTEX_ALREADY_INSERTED);
|
||||
}
|
||||
MG_ASSERT(it != acc.end(), "Invalid Vertex accessor!");
|
||||
|
||||
@ -394,19 +395,19 @@ std::optional<VertexAccessor> Shard::Accessor::FindVertex(std::vector<PropertyVa
|
||||
return VertexAccessor::Create(&it->vertex, transaction_, &shard_->indices_, config_, shard_->vertex_validator_, view);
|
||||
}
|
||||
|
||||
Result<std::optional<VertexAccessor>> Shard::Accessor::DeleteVertex(VertexAccessor *vertex) {
|
||||
ShardResult<std::optional<VertexAccessor>> Shard::Accessor::DeleteVertex(VertexAccessor *vertex) {
|
||||
MG_ASSERT(vertex->transaction_ == transaction_,
|
||||
"VertexAccessor must be from the same transaction as the storage "
|
||||
"accessor when deleting a vertex!");
|
||||
auto *vertex_ptr = vertex->vertex_;
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_ptr)) return Error::SERIALIZATION_ERROR;
|
||||
if (!PrepareForWrite(transaction_, vertex_ptr)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
if (vertex_ptr->deleted) {
|
||||
return std::optional<VertexAccessor>{};
|
||||
}
|
||||
|
||||
if (!vertex_ptr->in_edges.empty() || !vertex_ptr->out_edges.empty()) return Error::VERTEX_HAS_EDGES;
|
||||
if (!vertex_ptr->in_edges.empty() || !vertex_ptr->out_edges.empty()) return SHARD_ERROR(ErrorCode::VERTEX_HAS_EDGES);
|
||||
|
||||
CreateAndLinkDelta(transaction_, vertex_ptr, Delta::RecreateObjectTag());
|
||||
vertex_ptr->deleted = true;
|
||||
@ -415,7 +416,7 @@ Result<std::optional<VertexAccessor>> Shard::Accessor::DeleteVertex(VertexAccess
|
||||
shard_->vertex_validator_, true);
|
||||
}
|
||||
|
||||
Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> Shard::Accessor::DetachDeleteVertex(
|
||||
ShardResult<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> Shard::Accessor::DetachDeleteVertex(
|
||||
VertexAccessor *vertex) {
|
||||
using ReturnType = std::pair<VertexAccessor, std::vector<EdgeAccessor>>;
|
||||
|
||||
@ -428,7 +429,7 @@ Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> Shar
|
||||
std::vector<Vertex::EdgeLink> out_edges;
|
||||
|
||||
{
|
||||
if (!PrepareForWrite(transaction_, vertex_ptr)) return Error::SERIALIZATION_ERROR;
|
||||
if (!PrepareForWrite(transaction_, vertex_ptr)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
if (vertex_ptr->deleted) return std::optional<ReturnType>{};
|
||||
|
||||
@ -443,7 +444,7 @@ Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> Shar
|
||||
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() == Error::SERIALIZATION_ERROR, "Invalid database state!");
|
||||
MG_ASSERT(ret.GetError() == common::ErrorCode::SERIALIZATION_ERROR, "Invalid database state!");
|
||||
return ret.GetError();
|
||||
}
|
||||
|
||||
@ -456,7 +457,7 @@ Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> Shar
|
||||
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() == Error::SERIALIZATION_ERROR, "Invalid database state!");
|
||||
MG_ASSERT(ret.GetError() == common::ErrorCode::SERIALIZATION_ERROR, "Invalid database state!");
|
||||
return ret.GetError();
|
||||
}
|
||||
|
||||
@ -469,7 +470,7 @@ Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> Shar
|
||||
// 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 Error::SERIALIZATION_ERROR;
|
||||
if (!PrepareForWrite(transaction_, vertex_ptr)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
MG_ASSERT(!vertex_ptr->deleted, "Invalid database state!");
|
||||
|
||||
@ -481,8 +482,8 @@ Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> Shar
|
||||
std::move(deleted_edges));
|
||||
}
|
||||
|
||||
Result<EdgeAccessor> Shard::Accessor::CreateEdge(VertexId from_vertex_id, VertexId to_vertex_id,
|
||||
const EdgeTypeId edge_type, const Gid gid) {
|
||||
ShardResult<EdgeAccessor> Shard::Accessor::CreateEdge(VertexId from_vertex_id, VertexId to_vertex_id,
|
||||
const EdgeTypeId edge_type, const Gid gid) {
|
||||
OOMExceptionEnabler oom_exception;
|
||||
Vertex *from_vertex{nullptr};
|
||||
Vertex *to_vertex{nullptr};
|
||||
@ -506,12 +507,12 @@ Result<EdgeAccessor> Shard::Accessor::CreateEdge(VertexId from_vertex_id, Vertex
|
||||
}
|
||||
|
||||
if (from_is_local) {
|
||||
if (!PrepareForWrite(transaction_, from_vertex)) return Error::SERIALIZATION_ERROR;
|
||||
if (from_vertex->deleted) return Error::DELETED_OBJECT;
|
||||
if (!PrepareForWrite(transaction_, from_vertex)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
if (from_vertex->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
}
|
||||
if (to_is_local && to_vertex != from_vertex) {
|
||||
if (!PrepareForWrite(transaction_, to_vertex)) return Error::SERIALIZATION_ERROR;
|
||||
if (to_vertex->deleted) return Error::DELETED_OBJECT;
|
||||
if (!PrepareForWrite(transaction_, to_vertex)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
if (to_vertex->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
}
|
||||
|
||||
EdgeRef edge(gid);
|
||||
@ -540,8 +541,8 @@ Result<EdgeAccessor> Shard::Accessor::CreateEdge(VertexId from_vertex_id, Vertex
|
||||
&shard_->indices_, config_);
|
||||
}
|
||||
|
||||
Result<std::optional<EdgeAccessor>> Shard::Accessor::DeleteEdge(VertexId from_vertex_id, VertexId to_vertex_id,
|
||||
const Gid edge_id) {
|
||||
ShardResult<std::optional<EdgeAccessor>> Shard::Accessor::DeleteEdge(VertexId from_vertex_id, VertexId to_vertex_id,
|
||||
const Gid edge_id) {
|
||||
Vertex *from_vertex{nullptr};
|
||||
Vertex *to_vertex{nullptr};
|
||||
|
||||
@ -566,13 +567,13 @@ Result<std::optional<EdgeAccessor>> Shard::Accessor::DeleteEdge(VertexId from_ve
|
||||
|
||||
if (from_is_local) {
|
||||
if (!PrepareForWrite(transaction_, from_vertex)) {
|
||||
return Error::SERIALIZATION_ERROR;
|
||||
return SHARD_ERROR(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 Error::SERIALIZATION_ERROR;
|
||||
return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
}
|
||||
MG_ASSERT(!to_vertex->deleted, "Invalid database state!");
|
||||
}
|
||||
|
@ -38,7 +38,6 @@
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/schema_validator.hpp"
|
||||
#include "storage/v3/schemas.hpp"
|
||||
#include "storage/v3/shard_operation_result.hpp"
|
||||
#include "storage/v3/transaction.hpp"
|
||||
#include "storage/v3/vertex.hpp"
|
||||
#include "storage/v3/vertex_accessor.hpp"
|
||||
@ -207,7 +206,7 @@ class Shard final {
|
||||
|
||||
public:
|
||||
/// @throw std::bad_alloc
|
||||
ShardOperationResult<VertexAccessor> CreateVertexAndValidate(
|
||||
ShardResult<VertexAccessor> CreateVertexAndValidate(
|
||||
const std::vector<LabelId> &labels, const std::vector<PropertyValue> &primary_properties,
|
||||
const std::vector<std::pair<PropertyId, PropertyValue>> &properties);
|
||||
|
||||
@ -262,19 +261,19 @@ class Shard final {
|
||||
|
||||
/// @return Accessor to the deleted vertex if a deletion took place, std::nullopt otherwise
|
||||
/// @throw std::bad_alloc
|
||||
Result<std::optional<VertexAccessor>> DeleteVertex(VertexAccessor *vertex);
|
||||
ShardResult<std::optional<VertexAccessor>> DeleteVertex(VertexAccessor *vertex);
|
||||
|
||||
/// @return Accessor to the deleted vertex and deleted edges if a deletion took place, std::nullopt otherwise
|
||||
/// @throw std::bad_alloc
|
||||
Result<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> DetachDeleteVertex(
|
||||
ShardResult<std::optional<std::pair<VertexAccessor, std::vector<EdgeAccessor>>>> DetachDeleteVertex(
|
||||
VertexAccessor *vertex);
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
Result<EdgeAccessor> CreateEdge(VertexId from_vertex_id, VertexId to_vertex_id, EdgeTypeId edge_type, Gid gid);
|
||||
ShardResult<EdgeAccessor> CreateEdge(VertexId from_vertex_id, VertexId to_vertex_id, EdgeTypeId edge_type, Gid gid);
|
||||
|
||||
/// Accessor to the deleted edge if a deletion took place, std::nullopt otherwise
|
||||
/// @throw std::bad_alloc
|
||||
Result<std::optional<EdgeAccessor>> DeleteEdge(VertexId from_vertex_id, VertexId to_vertex_id, Gid edge_id);
|
||||
ShardResult<std::optional<EdgeAccessor>> DeleteEdge(VertexId from_vertex_id, VertexId to_vertex_id, Gid edge_id);
|
||||
|
||||
LabelId NameToLabel(std::string_view name) const;
|
||||
|
||||
|
@ -1,26 +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 <variant>
|
||||
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/schema_validator.hpp"
|
||||
|
||||
namespace memgraph::storage::v3 {
|
||||
|
||||
using ResultErrorType = std::variant<SchemaViolation, Error>;
|
||||
|
||||
template <typename TValue>
|
||||
using ShardOperationResult = utils::BasicResult<ResultErrorType, TValue>;
|
||||
|
||||
} // namespace memgraph::storage::v3
|
@ -34,6 +34,7 @@
|
||||
#include "storage/v3/key_store.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/request_helper.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/schemas.hpp"
|
||||
#include "storage/v3/shard.hpp"
|
||||
#include "storage/v3/shard_rsm.hpp"
|
||||
@ -56,10 +57,17 @@ using conversions::FromPropertyValueToValue;
|
||||
using conversions::ToMsgsVertexId;
|
||||
using conversions::ToPropertyValue;
|
||||
|
||||
auto CreateErrorResponse(const ShardError &shard_error, const auto transaction_id, const std::string_view action) {
|
||||
msgs::ShardError message_shard_error{shard_error.code, shard_error.message};
|
||||
spdlog::debug("{} In transaction {} {} failed: {}: {}", shard_error.source, transaction_id.logical_id, action,
|
||||
ErrorCodeToString(shard_error.code), shard_error.message);
|
||||
return message_shard_error;
|
||||
}
|
||||
|
||||
msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateVerticesRequest &&req) {
|
||||
auto acc = shard_->Access(req.transaction_id);
|
||||
|
||||
bool action_successful = true;
|
||||
std::optional<msgs::ShardError> shard_error;
|
||||
|
||||
for (auto &new_vertex : req.new_vertices) {
|
||||
/// TODO(gvolfing) Consider other methods than converting. Change either
|
||||
@ -77,48 +85,39 @@ 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 (auto result_schema = acc.CreateVertexAndValidate(converted_label_ids, transformed_pk, converted_property_map);
|
||||
result_schema.HasError()) {
|
||||
LogResultError(result_schema.GetError(), "Creating Vertex");
|
||||
|
||||
action_successful = false;
|
||||
if (result_schema.HasError()) {
|
||||
shard_error.emplace(CreateErrorResponse(result_schema.GetError(), req.transaction_id, "creating vertices"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return msgs::CreateVerticesResponse{.success = action_successful};
|
||||
return msgs::CreateVerticesResponse{std::move(shard_error)};
|
||||
}
|
||||
|
||||
msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateVerticesRequest &&req) {
|
||||
auto acc = shard_->Access(req.transaction_id);
|
||||
|
||||
bool action_successful = true;
|
||||
|
||||
std::optional<msgs::ShardError> shard_error;
|
||||
for (auto &vertex : req.update_vertices) {
|
||||
if (!action_successful) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto vertex_to_update = acc.FindVertex(ConvertPropertyVector(std::move(vertex.primary_key)), View::OLD);
|
||||
if (!vertex_to_update) {
|
||||
action_successful = false;
|
||||
spdlog::debug("Vertex could not be found while trying to update its properties. Transaction id: {}",
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
||||
for (const auto label : vertex.add_labels) {
|
||||
if (const auto maybe_error = vertex_to_update->AddLabelAndValidate(label); maybe_error.HasError()) {
|
||||
LogResultError(maybe_error.GetError(), "Add vertex labels");
|
||||
action_successful = false;
|
||||
shard_error.emplace(CreateErrorResponse(maybe_error.GetError(), req.transaction_id, "adding label"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
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;
|
||||
shard_error.emplace(CreateErrorResponse(maybe_error.GetError(), req.transaction_id, "adding label"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -127,65 +126,58 @@ 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()) {
|
||||
action_successful = false;
|
||||
LogResultError(result_schema.GetError(), "Update vertex properties");
|
||||
shard_error.emplace(CreateErrorResponse(result_schema.GetError(), req.transaction_id, "adding label"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return msgs::UpdateVerticesResponse{.success = action_successful};
|
||||
return msgs::UpdateVerticesResponse{std::move(shard_error)};
|
||||
}
|
||||
|
||||
msgs::WriteResponses ShardRsm::ApplyWrite(msgs::DeleteVerticesRequest &&req) {
|
||||
bool action_successful = true;
|
||||
std::optional<msgs::ShardError> shard_error;
|
||||
auto acc = shard_->Access(req.transaction_id);
|
||||
|
||||
for (auto &propval : req.primary_keys) {
|
||||
if (!action_successful) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto vertex_acc = acc.FindVertex(ConvertPropertyVector(std::move(propval)), View::OLD);
|
||||
|
||||
if (!vertex_acc) {
|
||||
spdlog::debug("Error while trying to delete vertex. Vertex to delete does not exist. Transaction id: {}",
|
||||
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);
|
||||
action_successful = false;
|
||||
} else {
|
||||
// TODO(gvolfing)
|
||||
// Since we will not have different kinds of deletion types in one transaction,
|
||||
// we dont have to enter the switch statement on every iteration. Optimize this.
|
||||
switch (req.deletion_type) {
|
||||
case msgs::DeleteVerticesRequest::DeletionType::DELETE: {
|
||||
auto result = acc.DeleteVertex(&vertex_acc.value());
|
||||
if (result.HasError() || !(result.GetValue().has_value())) {
|
||||
action_successful = false;
|
||||
spdlog::debug("Error while trying to delete vertex. Transaction id: {}", req.transaction_id.logical_id);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case msgs::DeleteVerticesRequest::DeletionType::DETACH_DELETE: {
|
||||
auto result = acc.DetachDeleteVertex(&vertex_acc.value());
|
||||
if (result.HasError() || !(result.GetValue().has_value())) {
|
||||
action_successful = false;
|
||||
spdlog::debug("Error while trying to detach and delete vertex. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
}
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
// TODO(gvolfing)
|
||||
// Since we will not have different kinds of deletion types in one transaction,
|
||||
// we dont have to enter the switch statement on every iteration. Optimize this.
|
||||
switch (req.deletion_type) {
|
||||
case msgs::DeleteVerticesRequest::DeletionType::DELETE: {
|
||||
auto result = acc.DeleteVertex(&vertex_acc.value());
|
||||
if (result.HasError() || !(result.GetValue().has_value())) {
|
||||
shard_error.emplace(CreateErrorResponse(result.GetError(), req.transaction_id, "deleting vertices"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case msgs::DeleteVerticesRequest::DeletionType::DETACH_DELETE: {
|
||||
auto result = acc.DetachDeleteVertex(&vertex_acc.value());
|
||||
if (result.HasError() || !(result.GetValue().has_value())) {
|
||||
shard_error.emplace(CreateErrorResponse(result.GetError(), req.transaction_id, "deleting vertices"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (shard_error) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return msgs::DeleteVerticesResponse{.success = action_successful};
|
||||
return msgs::DeleteVerticesResponse{std::move(shard_error)};
|
||||
}
|
||||
|
||||
msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateExpandRequest &&req) {
|
||||
auto acc = shard_->Access(req.transaction_id);
|
||||
bool action_successful = true;
|
||||
std::optional<msgs::ShardError> shard_error;
|
||||
|
||||
for (auto &new_expand : req.new_expands) {
|
||||
const auto from_vertex_id =
|
||||
@ -195,7 +187,8 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateExpandRequest &&req) {
|
||||
VertexId{new_expand.dest_vertex.first.id, ConvertPropertyVector(std::move(new_expand.dest_vertex.second))};
|
||||
|
||||
if (!(shard_->IsVertexBelongToShard(from_vertex_id) || shard_->IsVertexBelongToShard(to_vertex_id))) {
|
||||
action_successful = false;
|
||||
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);
|
||||
break;
|
||||
@ -207,18 +200,18 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateExpandRequest &&req) {
|
||||
if (!new_expand.properties.empty()) {
|
||||
for (const auto &[property, value] : new_expand.properties) {
|
||||
if (const auto maybe_error = edge.SetProperty(property, ToPropertyValue(value)); maybe_error.HasError()) {
|
||||
action_successful = false;
|
||||
spdlog::debug("Setting edge property was not successful. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
break;
|
||||
}
|
||||
if (!action_successful) {
|
||||
shard_error.emplace(
|
||||
CreateErrorResponse(maybe_error.GetError(), req.transaction_id, "setting edge property"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (shard_error) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
action_successful = false;
|
||||
// TODO Code for this
|
||||
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND};
|
||||
spdlog::debug("Creating edge was not successful. Transaction id: {}", req.transaction_id.logical_id);
|
||||
break;
|
||||
}
|
||||
@ -228,24 +221,22 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CreateExpandRequest &&req) {
|
||||
for (auto &[edge_prop_key, edge_prop_val] : new_expand.properties) {
|
||||
auto set_result = edge_acc->SetProperty(edge_prop_key, ToPropertyValue(std::move(edge_prop_val)));
|
||||
if (set_result.HasError()) {
|
||||
action_successful = false;
|
||||
spdlog::debug("Adding property to edge was not successful. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
shard_error.emplace(CreateErrorResponse(set_result.GetError(), req.transaction_id, "adding edge property"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return msgs::CreateExpandResponse{.success = action_successful};
|
||||
return msgs::CreateExpandResponse{std::move(shard_error)};
|
||||
}
|
||||
|
||||
msgs::WriteResponses ShardRsm::ApplyWrite(msgs::DeleteEdgesRequest &&req) {
|
||||
bool action_successful = true;
|
||||
std::optional<msgs::ShardError> shard_error;
|
||||
auto acc = shard_->Access(req.transaction_id);
|
||||
|
||||
for (auto &edge : req.edges) {
|
||||
if (!action_successful) {
|
||||
if (shard_error) {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -253,41 +244,38 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::DeleteEdgesRequest &&req) {
|
||||
VertexId(edge.dst.first.id, ConvertPropertyVector(std::move(edge.dst.second))),
|
||||
Gid::FromUint(edge.id.gid));
|
||||
if (edge_acc.HasError() || !edge_acc.HasValue()) {
|
||||
spdlog::debug("Error while trying to delete edge. Transaction id: {}", req.transaction_id.logical_id);
|
||||
action_successful = false;
|
||||
shard_error.emplace(CreateErrorResponse(edge_acc.GetError(), req.transaction_id, "delete edge"));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return msgs::DeleteEdgesResponse{.success = action_successful};
|
||||
return msgs::DeleteEdgesResponse{std::move(shard_error)};
|
||||
}
|
||||
|
||||
msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateEdgesRequest &&req) {
|
||||
// TODO(antaljanosbenjamin): handle when the vertex is the destination vertex
|
||||
auto acc = shard_->Access(req.transaction_id);
|
||||
|
||||
bool action_successful = true;
|
||||
std::optional<msgs::ShardError> shard_error;
|
||||
|
||||
for (auto &edge : req.new_properties) {
|
||||
if (!action_successful) {
|
||||
if (shard_error) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto vertex_acc = acc.FindVertex(ConvertPropertyVector(std::move(edge.src.second)), View::OLD);
|
||||
if (!vertex_acc) {
|
||||
action_successful = false;
|
||||
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;
|
||||
}
|
||||
|
||||
// Since we are using the source vertex of the edge we are only intrested
|
||||
// Since we are using the source vertex of the edge we are only interested
|
||||
// in the vertex's out-going edges
|
||||
auto edges_res = vertex_acc->OutEdges(View::OLD);
|
||||
if (edges_res.HasError()) {
|
||||
action_successful = false;
|
||||
spdlog::debug("Encountered an error while trying to acquire EdgeAccessor with transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
shard_error.emplace(CreateErrorResponse(edges_res.GetError(), req.transaction_id, "update edge"));
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -303,27 +291,28 @@ msgs::WriteResponses ShardRsm::ApplyWrite(msgs::UpdateEdgesRequest &&req) {
|
||||
// Check if the property was set if SetProperty does not do that itself.
|
||||
auto res = edge_accessor.SetProperty(key, ToPropertyValue(std::move(value)));
|
||||
if (res.HasError()) {
|
||||
spdlog::debug("Encountered an error while trying to set the property of an Edge with transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
// TODO(jbajic) why not set action unsuccessful here?
|
||||
shard_error.emplace(CreateErrorResponse(edges_res.GetError(), req.transaction_id, "update edge"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!edge_accessor_did_match) {
|
||||
action_successful = false;
|
||||
// TODO(jbajic) Do we need this
|
||||
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND, "Edge was not found"};
|
||||
spdlog::debug("Could not find the Edge with the specified Gid. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return msgs::UpdateEdgesResponse{.success = action_successful};
|
||||
return msgs::UpdateEdgesResponse{std::move(shard_error)};
|
||||
}
|
||||
|
||||
msgs::ReadResponses ShardRsm::HandleRead(msgs::ScanVerticesRequest &&req) {
|
||||
auto acc = shard_->Access(req.transaction_id);
|
||||
bool action_successful = true;
|
||||
std::optional<msgs::ShardError> shard_error;
|
||||
|
||||
std::vector<msgs::ScanResultRow> results;
|
||||
if (req.batch_limit) {
|
||||
@ -348,25 +337,24 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ScanVerticesRequest &&req) {
|
||||
EvaluateVertexExpressions(dba, vertex, req.vertex_expressions, expr::identifier_node_symbol));
|
||||
}
|
||||
|
||||
std::optional<std::map<PropertyId, Value>> found_props;
|
||||
|
||||
if (req.props_to_return) {
|
||||
found_props = CollectSpecificPropertiesFromAccessor(vertex, req.props_to_return.value(), view);
|
||||
} else {
|
||||
auto found_props = std::invoke([&]() {
|
||||
if (req.props_to_return) {
|
||||
return CollectSpecificPropertiesFromAccessor(vertex, req.props_to_return.value(), view);
|
||||
}
|
||||
const auto *schema = shard_->GetSchema(shard_->PrimaryLabel());
|
||||
MG_ASSERT(schema);
|
||||
found_props = CollectAllPropertiesFromAccessor(vertex, view, *schema);
|
||||
}
|
||||
return CollectAllPropertiesFromAccessor(vertex, view, *schema);
|
||||
});
|
||||
|
||||
// TODO(gvolfing) -VERIFY-
|
||||
// Vertex is separated from the properties in the response.
|
||||
// Is it useful to return just a vertex without the properties?
|
||||
if (!found_props) {
|
||||
action_successful = false;
|
||||
if (found_props.HasError()) {
|
||||
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND, "Requested properties were not found!"};
|
||||
}
|
||||
|
||||
results.emplace_back(msgs::ScanResultRow{.vertex = ConstructValueVertex(vertex, view).vertex_v,
|
||||
.props = FromMap(found_props.value()),
|
||||
.props = FromMap(found_props.GetValue()),
|
||||
.evaluated_vertex_expressions = std::move(expression_results)});
|
||||
};
|
||||
|
||||
@ -410,10 +398,8 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ScanVerticesRequest &&req) {
|
||||
}
|
||||
}
|
||||
|
||||
msgs::ScanVerticesResponse resp{};
|
||||
resp.success = action_successful;
|
||||
|
||||
if (action_successful) {
|
||||
msgs::ScanVerticesResponse resp{.error = std::move(shard_error)};
|
||||
if (!resp.error) {
|
||||
resp.next_start_id = next_start_id;
|
||||
resp.results = std::move(results);
|
||||
}
|
||||
@ -423,13 +409,13 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ScanVerticesRequest &&req) {
|
||||
|
||||
msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) {
|
||||
auto acc = shard_->Access(req.transaction_id);
|
||||
bool action_successful = true;
|
||||
std::optional<msgs::ShardError> shard_error;
|
||||
|
||||
std::vector<msgs::ExpandOneResultRow> results;
|
||||
const auto batch_limit = req.limit;
|
||||
auto dba = DbAccessor{&acc};
|
||||
|
||||
auto maybe_filter_based_on_edge_uniquness = InitializeEdgeUniqunessFunction(req.only_unique_neighbor_rows);
|
||||
auto maybe_filter_based_on_edge_uniqueness = InitializeEdgeUniquenessFunction(req.only_unique_neighbor_rows);
|
||||
auto edge_filler = InitializeEdgeFillerFunction(req);
|
||||
|
||||
std::vector<VertexAccessor> vertex_accessors;
|
||||
@ -438,7 +424,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) {
|
||||
action_successful = false;
|
||||
shard_error = msgs::ShardError{common::ErrorCode::OBJECT_NOT_FOUND, "Source vertex was not found."};
|
||||
spdlog::debug("Encountered an error while trying to obtain VertexAccessor. Transaction id: {}",
|
||||
req.transaction_id.logical_id);
|
||||
break;
|
||||
@ -466,27 +452,23 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) {
|
||||
for (const auto &src_vertex_acc : vertex_accessors) {
|
||||
auto label_id = src_vertex_acc.PrimaryLabel(View::NEW);
|
||||
if (label_id.HasError()) {
|
||||
action_successful = false;
|
||||
break;
|
||||
shard_error.emplace(CreateErrorResponse(label_id.GetError(), req.transaction_id, "getting label"));
|
||||
}
|
||||
|
||||
auto primary_key = src_vertex_acc.PrimaryKey(View::NEW);
|
||||
if (primary_key.HasError()) {
|
||||
action_successful = false;
|
||||
shard_error.emplace(CreateErrorResponse(primary_key.GetError(), req.transaction_id, "getting primary key"));
|
||||
break;
|
||||
}
|
||||
|
||||
msgs::VertexId src_vertex(msgs::Label{.id = *label_id}, conversions::ConvertValueVector(*primary_key));
|
||||
|
||||
std::optional<msgs::ExpandOneResultRow> maybe_result;
|
||||
|
||||
if (req.order_by_edges.empty()) {
|
||||
const auto *schema = shard_->GetSchema(shard_->PrimaryLabel());
|
||||
MG_ASSERT(schema);
|
||||
maybe_result =
|
||||
GetExpandOneResult(acc, src_vertex, req, maybe_filter_based_on_edge_uniquness, edge_filler, *schema);
|
||||
|
||||
} else {
|
||||
auto maybe_result = std::invoke([&]() {
|
||||
if (req.order_by_edges.empty()) {
|
||||
const auto *schema = shard_->GetSchema(shard_->PrimaryLabel());
|
||||
MG_ASSERT(schema);
|
||||
return GetExpandOneResult(acc, src_vertex, req, maybe_filter_based_on_edge_uniqueness, edge_filler, *schema);
|
||||
}
|
||||
auto [in_edge_accessors, out_edge_accessors] = GetEdgesFromVertex(src_vertex_acc, req.direction);
|
||||
const auto in_ordered_edges = OrderByEdges(dba, in_edge_accessors, req.order_by_edges, src_vertex_acc);
|
||||
const auto out_ordered_edges = OrderByEdges(dba, out_edge_accessors, req.order_by_edges, src_vertex_acc);
|
||||
@ -500,25 +482,23 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) {
|
||||
[](const auto &edge_element) { return edge_element.object_acc; });
|
||||
const auto *schema = shard_->GetSchema(shard_->PrimaryLabel());
|
||||
MG_ASSERT(schema);
|
||||
maybe_result =
|
||||
GetExpandOneResult(src_vertex_acc, src_vertex, req, in_edge_ordered_accessors, out_edge_ordered_accessors,
|
||||
maybe_filter_based_on_edge_uniquness, edge_filler, *schema);
|
||||
}
|
||||
return GetExpandOneResult(src_vertex_acc, src_vertex, req, in_edge_ordered_accessors, out_edge_ordered_accessors,
|
||||
maybe_filter_based_on_edge_uniqueness, edge_filler, *schema);
|
||||
});
|
||||
|
||||
if (!maybe_result) {
|
||||
action_successful = false;
|
||||
if (maybe_result.HasError()) {
|
||||
shard_error.emplace(CreateErrorResponse(primary_key.GetError(), req.transaction_id, "getting primary key"));
|
||||
break;
|
||||
}
|
||||
|
||||
results.emplace_back(std::move(maybe_result.value()));
|
||||
results.emplace_back(std::move(maybe_result.GetValue()));
|
||||
if (batch_limit.has_value() && results.size() >= batch_limit.value()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
msgs::ExpandOneResponse resp{};
|
||||
resp.success = action_successful;
|
||||
if (action_successful) {
|
||||
msgs::ExpandOneResponse resp{.error = std::move(shard_error)};
|
||||
if (!resp.error) {
|
||||
resp.result = std::move(results);
|
||||
}
|
||||
|
||||
@ -527,7 +507,7 @@ msgs::ReadResponses ShardRsm::HandleRead(msgs::ExpandOneRequest &&req) {
|
||||
|
||||
msgs::WriteResponses ShardRsm::ApplyWrite(msgs::CommitRequest &&req) {
|
||||
shard_->Access(req.transaction_id).Commit(req.commit_timestamp);
|
||||
return msgs::CommitResponse{true};
|
||||
return msgs::CommitResponse{};
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
|
||||
|
@ -21,8 +21,8 @@
|
||||
#include "storage/v3/key_store.hpp"
|
||||
#include "storage/v3/mvcc.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/shard.hpp"
|
||||
#include "storage/v3/shard_operation_result.hpp"
|
||||
#include "storage/v3/vertex.hpp"
|
||||
#include "utils/logging.hpp"
|
||||
#include "utils/memory_tracker.hpp"
|
||||
@ -80,12 +80,12 @@ bool VertexAccessor::IsVisible(View view) const {
|
||||
return exists && (for_deleted_ || !deleted);
|
||||
}
|
||||
|
||||
Result<bool> VertexAccessor::AddLabel(LabelId label) {
|
||||
ShardResult<bool> VertexAccessor::AddLabel(LabelId label) {
|
||||
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return Error::SERIALIZATION_ERROR;
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
if (vertex_->deleted) return Error::DELETED_OBJECT;
|
||||
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
|
||||
if (std::find(vertex_->labels.begin(), vertex_->labels.end(), label) != vertex_->labels.end()) return false;
|
||||
|
||||
@ -98,15 +98,15 @@ Result<bool> VertexAccessor::AddLabel(LabelId label) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ShardOperationResult<bool> VertexAccessor::AddLabelAndValidate(LabelId label) {
|
||||
if (const auto maybe_violation_error = vertex_validator_->ValidateAddLabel(label); maybe_violation_error) {
|
||||
return {*maybe_violation_error};
|
||||
ShardResult<bool> VertexAccessor::AddLabelAndValidate(LabelId label) {
|
||||
if (const auto maybe_violation_error = vertex_validator_->ValidateAddLabel(label); maybe_violation_error.HasError()) {
|
||||
return {maybe_violation_error.GetError()};
|
||||
}
|
||||
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return {Error::SERIALIZATION_ERROR};
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
if (vertex_->deleted) return {Error::DELETED_OBJECT};
|
||||
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
|
||||
if (std::find(vertex_->labels.begin(), vertex_->labels.end(), label) != vertex_->labels.end()) return false;
|
||||
|
||||
@ -119,10 +119,10 @@ ShardOperationResult<bool> VertexAccessor::AddLabelAndValidate(LabelId label) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Result<bool> VertexAccessor::RemoveLabel(LabelId label) {
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return Error::SERIALIZATION_ERROR;
|
||||
ShardResult<bool> VertexAccessor::RemoveLabel(LabelId label) {
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
if (vertex_->deleted) return Error::DELETED_OBJECT;
|
||||
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
|
||||
auto it = std::find(vertex_->labels.begin(), vertex_->labels.end(), label);
|
||||
if (it == vertex_->labels.end()) return false;
|
||||
@ -134,14 +134,15 @@ Result<bool> VertexAccessor::RemoveLabel(LabelId label) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ShardOperationResult<bool> VertexAccessor::RemoveLabelAndValidate(LabelId label) {
|
||||
if (const auto maybe_violation_error = vertex_validator_->ValidateRemoveLabel(label); maybe_violation_error) {
|
||||
return {*maybe_violation_error};
|
||||
ShardResult<bool> VertexAccessor::RemoveLabelAndValidate(LabelId label) {
|
||||
if (const auto maybe_violation_error = vertex_validator_->ValidateRemoveLabel(label);
|
||||
maybe_violation_error.HasError()) {
|
||||
return {maybe_violation_error.GetError()};
|
||||
}
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return {Error::SERIALIZATION_ERROR};
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
if (vertex_->deleted) return {Error::DELETED_OBJECT};
|
||||
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
|
||||
auto it = std::find(vertex_->labels.begin(), vertex_->labels.end(), label);
|
||||
if (it == vertex_->labels.end()) return false;
|
||||
@ -153,9 +154,9 @@ ShardOperationResult<bool> VertexAccessor::RemoveLabelAndValidate(LabelId label)
|
||||
return true;
|
||||
}
|
||||
|
||||
Result<bool> VertexAccessor::HasLabel(View view, LabelId label) const { return HasLabel(label, view); }
|
||||
ShardResult<bool> VertexAccessor::HasLabel(View view, LabelId label) const { return HasLabel(label, view); }
|
||||
|
||||
Result<bool> VertexAccessor::HasLabel(LabelId label, View view) const {
|
||||
ShardResult<bool> VertexAccessor::HasLabel(LabelId label, View view) const {
|
||||
bool exists = true;
|
||||
bool deleted = false;
|
||||
bool has_label = false;
|
||||
@ -197,12 +198,12 @@ Result<bool> VertexAccessor::HasLabel(LabelId label, View view) const {
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!exists) return Error::NONEXISTENT_OBJECT;
|
||||
if (!for_deleted_ && deleted) return Error::DELETED_OBJECT;
|
||||
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
return has_label;
|
||||
}
|
||||
|
||||
Result<LabelId> VertexAccessor::PrimaryLabel(const View view) const {
|
||||
ShardResult<LabelId> VertexAccessor::PrimaryLabel(const View view) const {
|
||||
if (const auto result = CheckVertexExistence(view); result.HasError()) {
|
||||
return result.GetError();
|
||||
}
|
||||
@ -210,21 +211,21 @@ Result<LabelId> VertexAccessor::PrimaryLabel(const View view) const {
|
||||
return vertex_validator_->primary_label_;
|
||||
}
|
||||
|
||||
Result<PrimaryKey> VertexAccessor::PrimaryKey(const View view) const {
|
||||
ShardResult<PrimaryKey> VertexAccessor::PrimaryKey(const View view) const {
|
||||
if (const auto result = CheckVertexExistence(view); result.HasError()) {
|
||||
return result.GetError();
|
||||
}
|
||||
return vertex_->keys.Keys();
|
||||
}
|
||||
|
||||
Result<VertexId> VertexAccessor::Id(View view) const {
|
||||
ShardResult<VertexId> VertexAccessor::Id(View view) const {
|
||||
if (const auto result = CheckVertexExistence(view); result.HasError()) {
|
||||
return result.GetError();
|
||||
}
|
||||
return VertexId{vertex_validator_->primary_label_, vertex_->keys.Keys()};
|
||||
};
|
||||
|
||||
Result<std::vector<LabelId>> VertexAccessor::Labels(View view) const {
|
||||
ShardResult<std::vector<LabelId>> VertexAccessor::Labels(View view) const {
|
||||
bool exists = true;
|
||||
bool deleted = false;
|
||||
std::vector<LabelId> labels;
|
||||
@ -267,17 +268,17 @@ Result<std::vector<LabelId>> VertexAccessor::Labels(View view) const {
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!exists) return Error::NONEXISTENT_OBJECT;
|
||||
if (!for_deleted_ && deleted) return Error::DELETED_OBJECT;
|
||||
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
return std::move(labels);
|
||||
}
|
||||
|
||||
Result<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const PropertyValue &value) {
|
||||
ShardResult<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const PropertyValue &value) {
|
||||
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return Error::SERIALIZATION_ERROR;
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
if (vertex_->deleted) return Error::DELETED_OBJECT;
|
||||
if (vertex_->deleted) return SHARD_ERROR(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
|
||||
@ -294,7 +295,7 @@ Result<PropertyValue> VertexAccessor::SetProperty(PropertyId property, const Pro
|
||||
return std::move(current_value);
|
||||
}
|
||||
|
||||
Result<void> VertexAccessor::CheckVertexExistence(View view) const {
|
||||
ShardResult<void> VertexAccessor::CheckVertexExistence(View view) const {
|
||||
bool exists = true;
|
||||
bool deleted = false;
|
||||
Delta *delta = nullptr;
|
||||
@ -323,27 +324,27 @@ Result<void> VertexAccessor::CheckVertexExistence(View view) const {
|
||||
}
|
||||
});
|
||||
if (!exists) {
|
||||
return Error::NONEXISTENT_OBJECT;
|
||||
return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
}
|
||||
if (!for_deleted_ && deleted) {
|
||||
return Error::DELETED_OBJECT;
|
||||
return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
ShardOperationResult<PropertyValue> VertexAccessor::SetPropertyAndValidate(PropertyId property,
|
||||
const PropertyValue &value) {
|
||||
if (auto maybe_violation_error = vertex_validator_->ValidatePropertyUpdate(property); maybe_violation_error) {
|
||||
return {*maybe_violation_error};
|
||||
ShardResult<PropertyValue> VertexAccessor::SetPropertyAndValidate(PropertyId property, const PropertyValue &value) {
|
||||
if (auto maybe_violation_error = vertex_validator_->ValidatePropertyUpdate(property);
|
||||
maybe_violation_error.HasError()) {
|
||||
return {maybe_violation_error.GetError()};
|
||||
}
|
||||
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
|
||||
|
||||
if (!PrepareForWrite(transaction_, vertex_)) {
|
||||
return {Error::SERIALIZATION_ERROR};
|
||||
return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
}
|
||||
|
||||
if (vertex_->deleted) {
|
||||
return {Error::DELETED_OBJECT};
|
||||
return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
}
|
||||
|
||||
auto current_value = vertex_->properties.GetProperty(property);
|
||||
@ -361,10 +362,10 @@ ShardOperationResult<PropertyValue> VertexAccessor::SetPropertyAndValidate(Prope
|
||||
return std::move(current_value);
|
||||
}
|
||||
|
||||
Result<std::map<PropertyId, PropertyValue>> VertexAccessor::ClearProperties() {
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return Error::SERIALIZATION_ERROR;
|
||||
ShardResult<std::map<PropertyId, PropertyValue>> VertexAccessor::ClearProperties() {
|
||||
if (!PrepareForWrite(transaction_, vertex_)) return SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR);
|
||||
|
||||
if (vertex_->deleted) return Error::DELETED_OBJECT;
|
||||
if (vertex_->deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
|
||||
auto properties = vertex_->properties.Properties();
|
||||
for (const auto &property : properties) {
|
||||
@ -377,7 +378,7 @@ Result<std::map<PropertyId, PropertyValue>> VertexAccessor::ClearProperties() {
|
||||
return std::move(properties);
|
||||
}
|
||||
|
||||
Result<PropertyValue> VertexAccessor::GetProperty(View view, PropertyId property) const {
|
||||
ShardResult<PropertyValue> VertexAccessor::GetProperty(View view, PropertyId property) const {
|
||||
return GetProperty(property, view).GetValue();
|
||||
}
|
||||
|
||||
@ -407,7 +408,7 @@ PropertyValue VertexAccessor::GetPropertyValue(PropertyId property, View view) c
|
||||
return value;
|
||||
}
|
||||
|
||||
Result<PropertyValue> VertexAccessor::GetProperty(PropertyId property, View view) const {
|
||||
ShardResult<PropertyValue> VertexAccessor::GetProperty(PropertyId property, View view) const {
|
||||
bool exists = true;
|
||||
bool deleted = false;
|
||||
PropertyValue value;
|
||||
@ -442,12 +443,12 @@ Result<PropertyValue> VertexAccessor::GetProperty(PropertyId property, View view
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!exists) return Error::NONEXISTENT_OBJECT;
|
||||
if (!for_deleted_ && deleted) return Error::DELETED_OBJECT;
|
||||
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
return std::move(value);
|
||||
}
|
||||
|
||||
Result<std::map<PropertyId, PropertyValue>> VertexAccessor::Properties(View view) const {
|
||||
ShardResult<std::map<PropertyId, PropertyValue>> VertexAccessor::Properties(View view) const {
|
||||
bool exists = true;
|
||||
bool deleted = false;
|
||||
std::map<PropertyId, PropertyValue> properties;
|
||||
@ -492,13 +493,13 @@ Result<std::map<PropertyId, PropertyValue>> VertexAccessor::Properties(View view
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!exists) return Error::NONEXISTENT_OBJECT;
|
||||
if (!for_deleted_ && deleted) return Error::DELETED_OBJECT;
|
||||
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
return std::move(properties);
|
||||
}
|
||||
|
||||
Result<std::vector<EdgeAccessor>> VertexAccessor::InEdges(View view, const std::vector<EdgeTypeId> &edge_types,
|
||||
const VertexId *destination_id) const {
|
||||
ShardResult<std::vector<EdgeAccessor>> VertexAccessor::InEdges(View view, const std::vector<EdgeTypeId> &edge_types,
|
||||
const VertexId *destination_id) const {
|
||||
bool exists = true;
|
||||
bool deleted = false;
|
||||
std::vector<Vertex::EdgeLink> in_edges;
|
||||
@ -564,8 +565,8 @@ Result<std::vector<EdgeAccessor>> VertexAccessor::InEdges(View view, const std::
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!exists) return Error::NONEXISTENT_OBJECT;
|
||||
if (deleted) return Error::DELETED_OBJECT;
|
||||
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
if (deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
std::vector<EdgeAccessor> ret;
|
||||
if (in_edges.empty()) {
|
||||
return ret;
|
||||
@ -579,8 +580,8 @@ Result<std::vector<EdgeAccessor>> VertexAccessor::InEdges(View view, const std::
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result<std::vector<EdgeAccessor>> VertexAccessor::OutEdges(View view, const std::vector<EdgeTypeId> &edge_types,
|
||||
const VertexId *destination_id) const {
|
||||
ShardResult<std::vector<EdgeAccessor>> VertexAccessor::OutEdges(View view, const std::vector<EdgeTypeId> &edge_types,
|
||||
const VertexId *destination_id) const {
|
||||
bool exists = true;
|
||||
bool deleted = false;
|
||||
std::vector<Vertex::EdgeLink> out_edges;
|
||||
@ -644,8 +645,8 @@ Result<std::vector<EdgeAccessor>> VertexAccessor::OutEdges(View view, const std:
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!exists) return Error::NONEXISTENT_OBJECT;
|
||||
if (deleted) return Error::DELETED_OBJECT;
|
||||
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
if (deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
std::vector<EdgeAccessor> ret;
|
||||
if (out_edges.empty()) {
|
||||
return ret;
|
||||
@ -659,7 +660,7 @@ Result<std::vector<EdgeAccessor>> VertexAccessor::OutEdges(View view, const std:
|
||||
return ret;
|
||||
}
|
||||
|
||||
Result<size_t> VertexAccessor::InDegree(View view) const {
|
||||
ShardResult<size_t> VertexAccessor::InDegree(View view) const {
|
||||
bool exists = true;
|
||||
bool deleted = false;
|
||||
size_t degree = 0;
|
||||
@ -691,12 +692,12 @@ Result<size_t> VertexAccessor::InDegree(View view) const {
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!exists) return Error::NONEXISTENT_OBJECT;
|
||||
if (!for_deleted_ && deleted) return Error::DELETED_OBJECT;
|
||||
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
return degree;
|
||||
}
|
||||
|
||||
Result<size_t> VertexAccessor::OutDegree(View view) const {
|
||||
ShardResult<size_t> VertexAccessor::OutDegree(View view) const {
|
||||
bool exists = true;
|
||||
bool deleted = false;
|
||||
size_t degree = 0;
|
||||
@ -728,8 +729,8 @@ Result<size_t> VertexAccessor::OutDegree(View view) const {
|
||||
break;
|
||||
}
|
||||
});
|
||||
if (!exists) return Error::NONEXISTENT_OBJECT;
|
||||
if (!for_deleted_ && deleted) return Error::DELETED_OBJECT;
|
||||
if (!exists) return SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT);
|
||||
if (!for_deleted_ && deleted) return SHARD_ERROR(ErrorCode::DELETED_OBJECT);
|
||||
return degree;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "storage/v3/id_types.hpp"
|
||||
#include "storage/v3/key_store.hpp"
|
||||
#include "storage/v3/result.hpp"
|
||||
#include "storage/v3/shard_operation_result.hpp"
|
||||
#include "storage/v3/schema_validator.hpp"
|
||||
#include "storage/v3/transaction.hpp"
|
||||
#include "storage/v3/vertex.hpp"
|
||||
#include "storage/v3/vertex_id.hpp"
|
||||
@ -55,61 +55,61 @@ class VertexAccessor final {
|
||||
/// `false` is returned if the label already existed, or SchemaViolation
|
||||
/// if adding the label has violated one of the schema constraints.
|
||||
/// @throw std::bad_alloc
|
||||
ShardOperationResult<bool> AddLabelAndValidate(LabelId label);
|
||||
ShardResult<bool> AddLabelAndValidate(LabelId label);
|
||||
|
||||
/// Remove a label and return `true` if deletion took place.
|
||||
/// `false` is returned if the vertex did not have a label already. or SchemaViolation
|
||||
/// if adding the label has violated one of the schema constraints.
|
||||
/// @throw std::bad_alloc
|
||||
ShardOperationResult<bool> RemoveLabelAndValidate(LabelId label);
|
||||
ShardResult<bool> RemoveLabelAndValidate(LabelId label);
|
||||
|
||||
Result<bool> HasLabel(View view, LabelId label) const;
|
||||
ShardResult<bool> HasLabel(View view, LabelId label) const;
|
||||
|
||||
Result<bool> HasLabel(LabelId label, View view) const;
|
||||
ShardResult<bool> HasLabel(LabelId label, View view) const;
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
/// @throw std::length_error if the resulting vector exceeds
|
||||
/// std::vector::max_size().
|
||||
Result<std::vector<LabelId>> Labels(View view) const;
|
||||
ShardResult<std::vector<LabelId>> Labels(View view) const;
|
||||
|
||||
Result<LabelId> PrimaryLabel(View view) const;
|
||||
ShardResult<LabelId> PrimaryLabel(View view) const;
|
||||
|
||||
Result<PrimaryKey> PrimaryKey(View view) const;
|
||||
ShardResult<PrimaryKey> PrimaryKey(View view) const;
|
||||
|
||||
Result<VertexId> Id(View view) const;
|
||||
ShardResult<VertexId> Id(View view) const;
|
||||
|
||||
/// Set a property value and return the old value or error.
|
||||
/// @throw std::bad_alloc
|
||||
ShardOperationResult<PropertyValue> SetPropertyAndValidate(PropertyId property, const PropertyValue &value);
|
||||
ShardResult<PropertyValue> SetPropertyAndValidate(PropertyId property, const PropertyValue &value);
|
||||
|
||||
/// Remove all properties and return the values of the removed properties.
|
||||
/// @throw std::bad_alloc
|
||||
Result<std::map<PropertyId, PropertyValue>> ClearProperties();
|
||||
ShardResult<std::map<PropertyId, PropertyValue>> ClearProperties();
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
Result<PropertyValue> GetProperty(PropertyId property, View view) const;
|
||||
ShardResult<PropertyValue> GetProperty(PropertyId property, View view) const;
|
||||
|
||||
// TODO Remove this
|
||||
Result<PropertyValue> GetProperty(View view, PropertyId property) const;
|
||||
ShardResult<PropertyValue> GetProperty(View view, PropertyId property) const;
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
Result<std::map<PropertyId, PropertyValue>> Properties(View view) const;
|
||||
ShardResult<std::map<PropertyId, PropertyValue>> Properties(View view) const;
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
/// @throw std::length_error if the resulting vector exceeds
|
||||
/// std::vector::max_size().
|
||||
Result<std::vector<EdgeAccessor>> InEdges(View view, const std::vector<EdgeTypeId> &edge_types = {},
|
||||
const VertexId *destination_id = nullptr) const;
|
||||
ShardResult<std::vector<EdgeAccessor>> InEdges(View view, const std::vector<EdgeTypeId> &edge_types = {},
|
||||
const VertexId *destination_id = nullptr) const;
|
||||
|
||||
/// @throw std::bad_alloc
|
||||
/// @throw std::length_error if the resulting vector exceeds
|
||||
/// std::vector::max_size().
|
||||
Result<std::vector<EdgeAccessor>> OutEdges(View view, const std::vector<EdgeTypeId> &edge_types = {},
|
||||
const VertexId *destination_id = nullptr) const;
|
||||
ShardResult<std::vector<EdgeAccessor>> OutEdges(View view, const std::vector<EdgeTypeId> &edge_types = {},
|
||||
const VertexId *destination_id = nullptr) const;
|
||||
|
||||
Result<size_t> InDegree(View view) const;
|
||||
ShardResult<size_t> InDegree(View view) const;
|
||||
|
||||
Result<size_t> OutDegree(View view) const;
|
||||
ShardResult<size_t> OutDegree(View view) const;
|
||||
|
||||
const SchemaValidator *GetSchemaValidator() const;
|
||||
|
||||
@ -122,20 +122,20 @@ class VertexAccessor final {
|
||||
/// Add a label and return `true` if insertion took place.
|
||||
/// `false` is returned if the label already existed.
|
||||
/// @throw std::bad_alloc
|
||||
Result<bool> AddLabel(LabelId label);
|
||||
ShardResult<bool> AddLabel(LabelId label);
|
||||
|
||||
/// Remove a label and return `true` if deletion took place.
|
||||
/// `false` is returned if the vertex did not have a label already.
|
||||
/// @throw std::bad_alloc
|
||||
Result<bool> RemoveLabel(LabelId label);
|
||||
ShardResult<bool> RemoveLabel(LabelId label);
|
||||
|
||||
/// Set a property value and return the old value.
|
||||
/// @throw std::bad_alloc
|
||||
Result<PropertyValue> SetProperty(PropertyId property, const PropertyValue &value);
|
||||
ShardResult<PropertyValue> SetProperty(PropertyId property, const PropertyValue &value);
|
||||
|
||||
PropertyValue GetPropertyValue(PropertyId property, View view) const;
|
||||
|
||||
Result<void> CheckVertexExistence(View view) const;
|
||||
ShardResult<void> CheckVertexExistence(View view) const;
|
||||
|
||||
Vertex *vertex_;
|
||||
Transaction *transaction_;
|
||||
|
@ -137,7 +137,7 @@ void Commit(ShardClient &client, const coordinator::Hlc &transaction_timestamp)
|
||||
|
||||
auto write_response_result = write_res.GetValue();
|
||||
auto write_response = std::get<msgs::CommitResponse>(write_response_result);
|
||||
MG_ASSERT(write_response.success, "Commit expected to be successful, but it is failed");
|
||||
MG_ASSERT(!write_response.error.has_value(), "Commit expected to be successful, but it is failed");
|
||||
|
||||
break;
|
||||
}
|
||||
@ -156,7 +156,7 @@ bool AttemptToCreateVertex(ShardClient &client, int64_t value) {
|
||||
create_req.transaction_id.logical_id = GetTransactionId();
|
||||
|
||||
auto write_res = client.SendWriteRequest(create_req);
|
||||
MG_ASSERT(write_res.HasValue() && std::get<msgs::CreateVerticesResponse>(write_res.GetValue()).success,
|
||||
MG_ASSERT(write_res.HasValue() && !std::get<msgs::CreateVerticesResponse>(write_res.GetValue()).error.has_value(),
|
||||
"Unexpected failure");
|
||||
|
||||
Commit(client, create_req.transaction_id);
|
||||
@ -179,7 +179,7 @@ bool AttemptToDeleteVertex(ShardClient &client, int64_t value) {
|
||||
auto write_response = std::get<msgs::DeleteVerticesResponse>(write_response_result);
|
||||
|
||||
Commit(client, delete_req.transaction_id);
|
||||
return write_response.success;
|
||||
return !write_response.error.has_value();
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ bool AttemptToUpdateVertex(ShardClient &client, int64_t vertex_primary_key, std:
|
||||
auto write_response = std::get<msgs::UpdateVerticesResponse>(write_response_result);
|
||||
|
||||
Commit(client, update_req.transaction_id);
|
||||
return write_response.success;
|
||||
return !write_response.error.has_value();
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,7 +241,7 @@ bool AttemptToRemoveVertexProperty(ShardClient &client, int64_t primary_key, std
|
||||
auto write_response = std::get<msgs::UpdateVerticesResponse>(write_response_result);
|
||||
|
||||
Commit(client, update_req.transaction_id);
|
||||
return write_response.success;
|
||||
return !write_response.error.has_value();
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,7 +278,7 @@ bool AttemptToAddEdge(ShardClient &client, int64_t value_of_vertex_1, int64_t va
|
||||
|
||||
Commit(client, create_req.transaction_id);
|
||||
|
||||
return write_response.success;
|
||||
return !write_response.error.has_value();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -310,7 +310,7 @@ bool AttemptToAddEdgeWithProperties(ShardClient &client, int64_t value_of_vertex
|
||||
create_req.transaction_id.logical_id = GetTransactionId();
|
||||
|
||||
auto write_res = client.SendWriteRequest(create_req);
|
||||
MG_ASSERT(write_res.HasValue() && std::get<msgs::CreateExpandResponse>(write_res.GetValue()).success,
|
||||
MG_ASSERT(write_res.HasValue() && !std::get<msgs::CreateExpandResponse>(write_res.GetValue()).error.has_value(),
|
||||
"Unexpected failure");
|
||||
|
||||
Commit(client, create_req.transaction_id);
|
||||
@ -350,7 +350,7 @@ bool AttemptToDeleteEdge(ShardClient &client, int64_t value_of_vertex_1, int64_t
|
||||
auto write_response = std::get<msgs::DeleteEdgesResponse>(write_response_result);
|
||||
|
||||
Commit(client, delete_req.transaction_id);
|
||||
return write_response.success;
|
||||
return !write_response.error.has_value();
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,7 +390,7 @@ bool AttemptToUpdateEdge(ShardClient &client, int64_t value_of_vertex_1, int64_t
|
||||
auto write_response = std::get<msgs::UpdateEdgesResponse>(write_response_result);
|
||||
|
||||
Commit(client, update_req.transaction_id);
|
||||
return write_response.success;
|
||||
return !write_response.error.has_value();
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,7 +413,7 @@ std::tuple<size_t, std::optional<msgs::VertexId>> AttemptToScanAllWithoutBatchLi
|
||||
auto write_response_result = read_res.GetValue();
|
||||
auto write_response = std::get<msgs::ScanVerticesResponse>(write_response_result);
|
||||
|
||||
MG_ASSERT(write_response.success);
|
||||
MG_ASSERT(write_response.error == std::nullopt);
|
||||
|
||||
return {write_response.results.size(), write_response.next_start_id};
|
||||
}
|
||||
@ -439,7 +439,7 @@ std::tuple<size_t, std::optional<msgs::VertexId>> AttemptToScanAllWithBatchLimit
|
||||
auto write_response_result = read_res.GetValue();
|
||||
auto write_response = std::get<msgs::ScanVerticesResponse>(write_response_result);
|
||||
|
||||
MG_ASSERT(write_response.success);
|
||||
MG_ASSERT(!write_response.error.has_value());
|
||||
|
||||
return {write_response.results.size(), write_response.next_start_id};
|
||||
}
|
||||
@ -473,7 +473,7 @@ std::tuple<size_t, std::optional<msgs::VertexId>> AttemptToScanAllWithExpression
|
||||
auto write_response_result = read_res.GetValue();
|
||||
auto write_response = std::get<msgs::ScanVerticesResponse>(write_response_result);
|
||||
|
||||
MG_ASSERT(write_response.success);
|
||||
MG_ASSERT(!write_response.error.has_value());
|
||||
MG_ASSERT(!write_response.results.empty(), "There are no results!");
|
||||
MG_ASSERT(write_response.results[0].evaluated_vertex_expressions[0].int_v == 4);
|
||||
return {write_response.results.size(), write_response.next_start_id};
|
||||
@ -498,7 +498,7 @@ void AttemptToScanAllWithOrderByOnPrimaryProperty(ShardClient &client, msgs::Ver
|
||||
auto write_response_result = read_res.GetValue();
|
||||
auto write_response = std::get<msgs::ScanVerticesResponse>(write_response_result);
|
||||
|
||||
MG_ASSERT(write_response.success);
|
||||
MG_ASSERT(!write_response.error.has_value());
|
||||
MG_ASSERT(write_response.results.size() == 5, "Expecting 5 results!");
|
||||
for (int64_t i{0}; i < 5; ++i) {
|
||||
const auto expected_primary_key = std::vector{msgs::Value(1023 - i)};
|
||||
@ -528,7 +528,7 @@ void AttemptToScanAllWithOrderByOnSecondaryProperty(ShardClient &client, msgs::V
|
||||
auto write_response_result = read_res.GetValue();
|
||||
auto write_response = std::get<msgs::ScanVerticesResponse>(write_response_result);
|
||||
|
||||
MG_ASSERT(write_response.success);
|
||||
MG_ASSERT(!write_response.error.has_value());
|
||||
MG_ASSERT(write_response.results.size() == 5, "Expecting 5 results!");
|
||||
for (int64_t i{0}; i < 5; ++i) {
|
||||
const auto expected_prop4 = std::vector{msgs::Value(1023 - i)};
|
||||
|
@ -177,7 +177,7 @@ void ExecuteOp(msgs::ShardRequestManager<SimulatorTransport> &shard_request_mana
|
||||
auto result = shard_request_manager.Request(state, std::move(new_vertices));
|
||||
|
||||
RC_ASSERT(result.size() == 1);
|
||||
RC_ASSERT(result[0].success);
|
||||
RC_ASSERT(!result[0].error.has_value());
|
||||
|
||||
correctness_model.emplace(std::make_pair(create_vertex.first, create_vertex.second));
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ void ExecuteOp(msgs::ShardRequestManager<LocalTransport> &shard_request_manager,
|
||||
auto result = shard_request_manager.Request(state, std::move(new_vertices));
|
||||
|
||||
MG_ASSERT(result.size() == 1);
|
||||
MG_ASSERT(result[0].success);
|
||||
MG_ASSERT(!result[0].error.has_value());
|
||||
|
||||
correctness_model.emplace(std::make_pair(create_vertex.first, create_vertex.second));
|
||||
}
|
||||
|
@ -131,6 +131,7 @@ void TestCreateVertices(msgs::ShardRequestManagerInterface &shard_request_manage
|
||||
|
||||
auto result = shard_request_manager.Request(state, std::move(new_vertices));
|
||||
EXPECT_EQ(result.size(), 1);
|
||||
EXPECT_FALSE(result[0].error.has_value()) << result[0].error->message;
|
||||
}
|
||||
|
||||
void TestCreateExpand(msgs::ShardRequestManagerInterface &shard_request_manager) {
|
||||
@ -151,7 +152,7 @@ void TestCreateExpand(msgs::ShardRequestManagerInterface &shard_request_manager)
|
||||
|
||||
auto responses = shard_request_manager.Request(state, std::move(new_expands));
|
||||
MG_ASSERT(responses.size() == 1);
|
||||
MG_ASSERT(responses[0].success);
|
||||
MG_ASSERT(!responses[0].error.has_value());
|
||||
}
|
||||
|
||||
void TestExpandOne(msgs::ShardRequestManagerInterface &shard_request_manager) {
|
||||
|
@ -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(), Error::SERIALIZATION_ERROR);
|
||||
ASSERT_EQ(res.GetError(), SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR));
|
||||
EXPECT_EQ(CountVertices(acc2, View::OLD), 1U);
|
||||
EXPECT_EQ(CountVertices(acc2, View::NEW), 1U);
|
||||
acc2.AdvanceCommand();
|
||||
@ -660,12 +661,11 @@ TEST_P(StorageV3, VertexDeleteSpecialCases) {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TError, typename TResultHolder>
|
||||
void AssertErrorInVariant(TResultHolder &holder, TError error_type) {
|
||||
ASSERT_TRUE(holder.HasError());
|
||||
const auto error = holder.GetError();
|
||||
ASSERT_TRUE(std::holds_alternative<TError>(error));
|
||||
ASSERT_EQ(std::get<TError>(error), error_type);
|
||||
template <typename T>
|
||||
void AssertShardErrorEqual(const ShardResult<T> &lhs, const ShardError &rhs) {
|
||||
ASSERT_TRUE(lhs.HasError());
|
||||
const auto error = lhs.GetError();
|
||||
ASSERT_EQ(error, rhs);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(hicpp-special-member-functions)
|
||||
@ -711,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(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex->Labels(View::OLD)->size(), 0);
|
||||
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
|
||||
// Try to add the label
|
||||
{
|
||||
auto ret = vertex->AddLabelAndValidate(label5);
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
// Try to remove the label
|
||||
{
|
||||
auto ret = vertex->RemoveLabelAndValidate(label5);
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
acc.Abort();
|
||||
@ -779,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(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), SHARD_ERROR(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(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
|
||||
// Advance command
|
||||
acc.AdvanceCommand();
|
||||
|
||||
// Check whether label 5 exists
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::OLD).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->HasLabel(label5, View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Labels(View::OLD).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Labels(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
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));
|
||||
|
||||
// Try to add the label
|
||||
{
|
||||
auto ret = vertex->AddLabelAndValidate(label5);
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
// Try to remove the label
|
||||
{
|
||||
auto ret = vertex->RemoveLabelAndValidate(label5);
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
acc.Abort();
|
||||
@ -855,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(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
ASSERT_EQ(vertex->Properties(View::OLD)->size(), 0);
|
||||
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
|
||||
// Try to set the property5
|
||||
{
|
||||
auto ret = vertex->SetPropertyAndValidate(property5, PropertyValue("haihai"));
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
acc.Abort();
|
||||
@ -918,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(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), SHARD_ERROR(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(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
|
||||
// Advance command
|
||||
acc.AdvanceCommand();
|
||||
|
||||
// Check whether property 5 exists
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::OLD).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->GetProperty(property5, View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Properties(View::OLD).GetError(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex->Properties(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
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));
|
||||
|
||||
// Try to set the property
|
||||
{
|
||||
auto ret = vertex->SetPropertyAndValidate(property5, PropertyValue("haihai"));
|
||||
AssertErrorInVariant(ret, Error::DELETED_OBJECT);
|
||||
AssertShardErrorEqual(ret, SHARD_ERROR(ErrorCode::DELETED_OBJECT));
|
||||
}
|
||||
|
||||
acc.Abort();
|
||||
@ -1371,7 +1371,7 @@ TEST_P(StorageV3, VertexLabelSerializationError) {
|
||||
|
||||
{
|
||||
auto res = vertex->AddLabelAndValidate(label1);
|
||||
AssertErrorInVariant(res, Error::SERIALIZATION_ERROR);
|
||||
AssertShardErrorEqual(res, SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1865,7 +1865,7 @@ TEST_P(StorageV3, VertexPropertySerializationError) {
|
||||
|
||||
{
|
||||
auto res = vertex->SetPropertyAndValidate(property2, PropertyValue("nandare"));
|
||||
AssertErrorInVariant(res, Error::SERIALIZATION_ERROR);
|
||||
AssertShardErrorEqual(res, SHARD_ERROR(ErrorCode::SERIALIZATION_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2255,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(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.HasLabel(label1, View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.Properties(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.GetProperty(property1, View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.InEdges(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.OutEdges(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.InDegree(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.OutDegree(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
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));
|
||||
|
||||
// Check state before (NEW view).
|
||||
ASSERT_EQ(vertex.Labels(View::NEW)->size(), 0);
|
||||
@ -2282,14 +2282,14 @@ TEST_P(StorageV3, VertexNonexistentLabelPropertyEdgeAPI) {
|
||||
.HasValue());
|
||||
|
||||
// Check state after (OLD view).
|
||||
ASSERT_EQ(vertex.Labels(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.HasLabel(label1, View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.Properties(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.GetProperty(property1, View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.InEdges(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.OutEdges(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.InDegree(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
ASSERT_EQ(vertex.OutDegree(View::OLD).GetError(), Error::NONEXISTENT_OBJECT);
|
||||
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));
|
||||
|
||||
// Check state after (NEW view).
|
||||
ASSERT_EQ(vertex.Labels(View::NEW)->size(), 1);
|
||||
@ -2657,42 +2657,31 @@ TEST_P(StorageV3, TestCreateVertexAndValidate) {
|
||||
|
||||
ASSERT_TRUE(vertex2.HasError());
|
||||
auto error = vertex2.GetError();
|
||||
auto error_ptr = std::get_if<memgraph::storage::v3::Error>(&error);
|
||||
ASSERT_TRUE(error_ptr);
|
||||
ASSERT_TRUE(*error_ptr == storage::v3::Error::VERTEX_ALREADY_INSERTED);
|
||||
ASSERT_TRUE(error == common::ErrorCode::VERTEX_ALREADY_INSERTED);
|
||||
}
|
||||
{
|
||||
auto acc = store.Access(GetNextHlc());
|
||||
auto vertex = acc.CreateVertexAndValidate({primary_label}, {PropertyValue{0}}, {});
|
||||
ASSERT_TRUE(vertex.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(vertex.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(vertex.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, primary_label));
|
||||
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
|
||||
}
|
||||
{
|
||||
auto acc = store.Access(GetNextHlc());
|
||||
auto vertex = acc.CreateVertexAndValidate({primary_label}, {PropertyValue{0}}, {});
|
||||
ASSERT_TRUE(vertex.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(vertex.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(vertex.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, primary_label));
|
||||
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
|
||||
}
|
||||
{
|
||||
auto acc = store.Access(GetNextHlc());
|
||||
auto vertex = acc.CreateVertexAndValidate({}, {}, {});
|
||||
ASSERT_TRUE(vertex.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(vertex.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(vertex.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PRIMARY_PROPERTIES_UNDEFINED, primary_label));
|
||||
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PRIMARY_PROPERTIES_UNDEFINED));
|
||||
}
|
||||
{
|
||||
auto acc = store.Access(GetNextHlc());
|
||||
auto vertex = acc.CreateVertexAndValidate({}, {PropertyValue{"test"}}, {});
|
||||
ASSERT_TRUE(vertex.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(vertex.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(vertex.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PROPERTY_WRONG_TYPE, primary_label,
|
||||
{primary_property, common::SchemaType::INT}, PropertyValue("test")));
|
||||
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
|
||||
}
|
||||
}
|
||||
} // namespace memgraph::storage::v3::tests
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "storage/v3/name_id_mapper.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/shard.hpp"
|
||||
#include "storage/v3/shard_operation_result.hpp"
|
||||
|
||||
namespace memgraph::storage::v3::tests {
|
||||
using testing::UnorderedElementsAre;
|
||||
@ -39,7 +38,7 @@ class StorageEdgeTest : public ::testing::TestWithParam<bool> {
|
||||
return store.NameToEdgeType(edge_type_name);
|
||||
}
|
||||
|
||||
static ShardOperationResult<VertexAccessor> CreateVertex(Shard::Accessor &acc, const PropertyValue &key) {
|
||||
static ShardResult<VertexAccessor> CreateVertex(Shard::Accessor &acc, const PropertyValue &key) {
|
||||
return acc.CreateVertexAndValidate({}, {key}, {});
|
||||
}
|
||||
|
||||
@ -3243,7 +3242,7 @@ TEST_P(StorageEdgeTest, VertexDetachDeleteSingleCommit) {
|
||||
{
|
||||
auto ret = acc.DeleteVertex(&vertex_from.value());
|
||||
ASSERT_TRUE(ret.HasError());
|
||||
ASSERT_EQ(ret.GetError(), Error::VERTEX_HAS_EDGES);
|
||||
ASSERT_EQ(ret.GetError(), SHARD_ERROR(ErrorCode::VERTEX_HAS_EDGES));
|
||||
}
|
||||
|
||||
// Detach delete vertex
|
||||
@ -3256,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(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex_from->InDegree(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
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));
|
||||
{
|
||||
auto ret = vertex_from->OutEdges(View::OLD);
|
||||
ASSERT_TRUE(ret.HasValue());
|
||||
@ -3270,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(), Error::DELETED_OBJECT);
|
||||
ASSERT_EQ(vertex_from->OutDegree(View::NEW).GetError(), Error::DELETED_OBJECT);
|
||||
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));
|
||||
{
|
||||
auto ret = vertex_to->InEdges(View::OLD);
|
||||
ASSERT_TRUE(ret.HasValue());
|
||||
|
@ -14,10 +14,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "common/errors.hpp"
|
||||
#include "common/types.hpp"
|
||||
#include "storage/v3/id_types.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
@ -150,7 +150,15 @@ TEST_F(SchemaTest, TestSchemaDrop) {
|
||||
|
||||
class SchemaValidatorTest : public testing::Test {
|
||||
private:
|
||||
NameIdMapper id_mapper_{{{1, "label1"}, {2, "label2"}, {3, "prop1"}, {4, "prop2"}, {5, "prop3"}}};
|
||||
NameIdMapper id_mapper_{{{1, "label1"},
|
||||
{2, "label2"},
|
||||
{3, "prop1"},
|
||||
{4, "prop2"},
|
||||
{5, "prop3"},
|
||||
{6, "label4"},
|
||||
{7, "label5"},
|
||||
{8, "label6"},
|
||||
{9, "test"}}};
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
@ -162,9 +170,8 @@ class SchemaValidatorTest : public testing::Test {
|
||||
|
||||
PropertyId NameToProperty(const std::string &name) { return PropertyId::FromUint(id_mapper_.NameToId(name)); }
|
||||
|
||||
protected:
|
||||
Schemas schemas;
|
||||
SchemaValidator schema_validator{schemas};
|
||||
SchemaValidator schema_validator{schemas, id_mapper_};
|
||||
PropertyId prop_string{NameToProperty("prop1")};
|
||||
PropertyId prop_int{NameToProperty("prop2")};
|
||||
PropertyId prop_duration{NameToProperty("prop3")};
|
||||
@ -179,100 +186,92 @@ TEST_F(SchemaValidatorTest, TestSchemaValidateVertexCreate) {
|
||||
// Validate against secondary label
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidateVertexCreate(NameToLabel("test"), {}, {PropertyValue(1)});
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::NO_SCHEMA_DEFINED_FOR_LABEL, NameToLabel("test")));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(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,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PRIMARY_PROPERTIES_UNDEFINED, label2));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(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,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, label1));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(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,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, label2));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(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, SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PROPERTY_WRONG_TYPE, label1,
|
||||
schema_prop_string, PropertyValue(1)));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(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, SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PROPERTY_WRONG_TYPE, label2,
|
||||
schema_prop_duration, PropertyValue(1)));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(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, SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_PROPERTY_WRONG_TYPE, label2,
|
||||
schema_prop_duration, wrong_prop));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_PROPERTY_WRONG_TYPE));
|
||||
}
|
||||
// Passing validations
|
||||
EXPECT_EQ(schema_validator.ValidateVertexCreate(label1, {}, {PropertyValue("test")}), std::nullopt);
|
||||
EXPECT_EQ(schema_validator.ValidateVertexCreate(label1, {NameToLabel("label3"), NameToLabel("label4")},
|
||||
{PropertyValue("test")}),
|
||||
std::nullopt);
|
||||
EXPECT_EQ(schema_validator.ValidateVertexCreate(
|
||||
label2, {},
|
||||
{PropertyValue("test"), PropertyValue(122), PropertyValue(TemporalData(TemporalType::Duration, 1234))}),
|
||||
std::nullopt);
|
||||
EXPECT_EQ(schema_validator.ValidateVertexCreate(label2, {NameToLabel("label5"), NameToLabel("label6")},
|
||||
{PropertyValue("test123"), PropertyValue(122221),
|
||||
PropertyValue(TemporalData(TemporalType::Duration, 12344321))}),
|
||||
std::nullopt);
|
||||
EXPECT_FALSE(schema_validator.ValidateVertexCreate(label1, {}, {PropertyValue("test")}).HasError());
|
||||
EXPECT_FALSE(
|
||||
schema_validator
|
||||
.ValidateVertexCreate(label1, {NameToLabel("label3"), NameToLabel("label4")}, {PropertyValue("test")})
|
||||
.HasError());
|
||||
EXPECT_FALSE(schema_validator
|
||||
.ValidateVertexCreate(label2, {},
|
||||
{PropertyValue("test"), PropertyValue(122),
|
||||
PropertyValue(TemporalData(TemporalType::Duration, 1234))})
|
||||
.HasError());
|
||||
EXPECT_FALSE(schema_validator
|
||||
.ValidateVertexCreate(label2, {NameToLabel("label5"), NameToLabel("label6")},
|
||||
{PropertyValue("test123"), PropertyValue(122221),
|
||||
PropertyValue(TemporalData(TemporalType::Duration, 12344321))})
|
||||
.HasError());
|
||||
}
|
||||
|
||||
TEST_F(SchemaValidatorTest, TestSchemaValidatePropertyUpdate) {
|
||||
// Validate updating of primary key
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidatePropertyUpdate(label1, prop_string);
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation, SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_KEY, label1,
|
||||
schema_prop_string));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(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, SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_KEY, label2,
|
||||
schema_prop_duration));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(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);
|
||||
EXPECT_EQ(schema_validator.ValidatePropertyUpdate(label2, NameToProperty("test")), std::nullopt);
|
||||
EXPECT_FALSE(schema_validator.ValidatePropertyUpdate(label1, prop_int).HasError());
|
||||
EXPECT_FALSE(schema_validator.ValidatePropertyUpdate(label1, prop_duration).HasError());
|
||||
EXPECT_FALSE(schema_validator.ValidatePropertyUpdate(label2, NameToProperty("test")).HasError());
|
||||
}
|
||||
|
||||
TEST_F(SchemaValidatorTest, TestSchemaValidatePropertyUpdateLabel) {
|
||||
// Validate adding primary label
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidateLabelUpdate(label1);
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_LABEL, label1));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
|
||||
}
|
||||
{
|
||||
const auto schema_violation = schema_validator.ValidateLabelUpdate(label2);
|
||||
ASSERT_NE(schema_violation, std::nullopt);
|
||||
EXPECT_EQ(*schema_violation,
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_LABEL, label2));
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
|
||||
}
|
||||
EXPECT_EQ(schema_validator.ValidateLabelUpdate(NameToLabel("test")), std::nullopt);
|
||||
EXPECT_FALSE(schema_validator.ValidateLabelUpdate(NameToLabel("test")).HasError());
|
||||
}
|
||||
} // namespace memgraph::storage::v3::tests
|
||||
|
@ -94,7 +94,7 @@ class ShardRSMTest : public testing::Test {
|
||||
|
||||
auto commit_res = Commit(create_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::CommitResponse>(commit_res));
|
||||
ASSERT_TRUE(std::get<msgs::CommitResponse>(commit_res).success);
|
||||
ASSERT_FALSE(std::get<msgs::CommitResponse>(commit_res).error.has_value());
|
||||
}
|
||||
|
||||
void AssertVertexExists(const msgs::PrimaryKey &primary_key, const std::vector<msgs::Label> &labels,
|
||||
@ -109,7 +109,7 @@ class ShardRSMTest : public testing::Test {
|
||||
auto maybe_read_res = shard_rsm->Read(scan_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::ScanVerticesResponse>(maybe_read_res));
|
||||
const auto read_res = std::get<msgs::ScanVerticesResponse>(maybe_read_res);
|
||||
EXPECT_TRUE(read_res.success);
|
||||
EXPECT_FALSE(read_res.error.has_value());
|
||||
EXPECT_EQ(read_res.results.size(), 1);
|
||||
|
||||
// Read results
|
||||
@ -148,11 +148,11 @@ TEST_F(ShardRSMTest, TestUpdateVertexSecondaryProperty) {
|
||||
|
||||
const auto write_res = shard_rsm->Apply(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::UpdateVerticesResponse>(write_res));
|
||||
EXPECT_TRUE(std::get<msgs::UpdateVerticesResponse>(write_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::UpdateVerticesResponse>(write_res).error.has_value());
|
||||
|
||||
const auto commit_res = Commit(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::CommitResponse>(commit_res));
|
||||
EXPECT_TRUE(std::get<msgs::CommitResponse>(commit_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::CommitResponse>(commit_res).error.has_value());
|
||||
}
|
||||
AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}, {prop, msgs::Value(updated_vertex_id)}});
|
||||
|
||||
@ -167,11 +167,11 @@ TEST_F(ShardRSMTest, TestUpdateVertexSecondaryProperty) {
|
||||
|
||||
const auto write_res = shard_rsm->Apply(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::UpdateVerticesResponse>(write_res));
|
||||
ASSERT_TRUE(std::get<msgs::UpdateVerticesResponse>(write_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::UpdateVerticesResponse>(write_res).error.has_value());
|
||||
|
||||
const auto commit_res = Commit(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::CommitResponse>(commit_res));
|
||||
EXPECT_TRUE(std::get<msgs::CommitResponse>(commit_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::CommitResponse>(commit_res).error.has_value());
|
||||
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)}});
|
||||
@ -186,11 +186,11 @@ TEST_F(ShardRSMTest, TestUpdateVertexSecondaryProperty) {
|
||||
|
||||
const auto write_res = shard_rsm->Apply(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::UpdateVerticesResponse>(write_res));
|
||||
EXPECT_TRUE(std::get<msgs::UpdateVerticesResponse>(write_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::UpdateVerticesResponse>(write_res).error.has_value());
|
||||
|
||||
const auto commit_res = Commit(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::CommitResponse>(commit_res));
|
||||
EXPECT_TRUE(std::get<msgs::CommitResponse>(commit_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::CommitResponse>(commit_res).error.has_value());
|
||||
}
|
||||
AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}});
|
||||
}
|
||||
@ -213,7 +213,7 @@ TEST_F(ShardRSMTest, TestUpdateVertexPrimaryProperty) {
|
||||
|
||||
const auto write_res = shard_rsm->Apply(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::UpdateVerticesResponse>(write_res));
|
||||
EXPECT_FALSE(std::get<msgs::UpdateVerticesResponse>(write_res).success);
|
||||
EXPECT_TRUE(std::get<msgs::UpdateVerticesResponse>(write_res).error.has_value());
|
||||
}
|
||||
AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}});
|
||||
// Try to update primary property of another schema
|
||||
@ -226,11 +226,11 @@ TEST_F(ShardRSMTest, TestUpdateVertexPrimaryProperty) {
|
||||
|
||||
const auto write_res = shard_rsm->Apply(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::UpdateVerticesResponse>(write_res));
|
||||
EXPECT_TRUE(std::get<msgs::UpdateVerticesResponse>(write_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::UpdateVerticesResponse>(write_res).error.has_value());
|
||||
|
||||
const auto commit_res = Commit(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::CommitResponse>(commit_res));
|
||||
EXPECT_TRUE(std::get<msgs::CommitResponse>(commit_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::CommitResponse>(commit_res).error.has_value());
|
||||
}
|
||||
AssertVertexExists(pk, {},
|
||||
{{primary_property1, primary_key_val}, {primary_property2, msgs::Value(updated_vertex_id)}});
|
||||
@ -253,11 +253,11 @@ TEST_F(ShardRSMTest, TestUpdateSecondaryLabel) {
|
||||
|
||||
const auto write_res = shard_rsm->Apply(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::UpdateVerticesResponse>(write_res));
|
||||
ASSERT_TRUE(std::get<msgs::UpdateVerticesResponse>(write_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::UpdateVerticesResponse>(write_res).error.has_value());
|
||||
|
||||
const auto commit_res = Commit(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::CommitResponse>(commit_res));
|
||||
EXPECT_TRUE(std::get<msgs::CommitResponse>(commit_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::CommitResponse>(commit_res).error.has_value());
|
||||
}
|
||||
AssertVertexExists(pk, {secondary_label}, {{primary_property1, primary_key_val}});
|
||||
|
||||
@ -270,11 +270,11 @@ TEST_F(ShardRSMTest, TestUpdateSecondaryLabel) {
|
||||
|
||||
const auto write_res = shard_rsm->Apply(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::UpdateVerticesResponse>(write_res));
|
||||
EXPECT_TRUE(std::get<msgs::UpdateVerticesResponse>(write_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::UpdateVerticesResponse>(write_res).error.has_value());
|
||||
|
||||
const auto commit_res = Commit(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::CommitResponse>(commit_res));
|
||||
EXPECT_TRUE(std::get<msgs::CommitResponse>(commit_res).success);
|
||||
EXPECT_FALSE(std::get<msgs::CommitResponse>(commit_res).error.has_value());
|
||||
}
|
||||
AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}});
|
||||
}
|
||||
@ -295,7 +295,7 @@ TEST_F(ShardRSMTest, TestUpdatePrimaryLabel) {
|
||||
|
||||
const auto write_res = shard_rsm->Apply(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::UpdateVerticesResponse>(write_res));
|
||||
EXPECT_FALSE(std::get<msgs::UpdateVerticesResponse>(write_res).success);
|
||||
EXPECT_TRUE(std::get<msgs::UpdateVerticesResponse>(write_res).error.has_value());
|
||||
}
|
||||
AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}});
|
||||
|
||||
@ -308,7 +308,7 @@ TEST_F(ShardRSMTest, TestUpdatePrimaryLabel) {
|
||||
|
||||
const auto write_res = shard_rsm->Apply(update_req);
|
||||
ASSERT_TRUE(std::holds_alternative<msgs::UpdateVerticesResponse>(write_res));
|
||||
EXPECT_FALSE(std::get<msgs::UpdateVerticesResponse>(write_res).success);
|
||||
EXPECT_TRUE(std::get<msgs::UpdateVerticesResponse>(write_res).error.has_value());
|
||||
}
|
||||
AssertVertexExists(pk, {}, {{primary_property1, primary_key_val}});
|
||||
}
|
||||
|
@ -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, Error::NONEXISTENT_OBJECT);
|
||||
EXPECT_EQ(error_primary_label, SHARD_ERROR(ErrorCode::NONEXISTENT_OBJECT));
|
||||
}
|
||||
{
|
||||
auto acc = storage.Access(GetNextHlc());
|
||||
@ -127,9 +128,7 @@ TEST_F(StorageV3Accessor, TestAddLabels) {
|
||||
const auto label1 = NameToLabelId("label");
|
||||
auto vertex = acc.CreateVertexAndValidate({label1}, {PropertyValue{2}}, {});
|
||||
ASSERT_TRUE(vertex.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(vertex.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(vertex.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_SECONDARY_LABEL_IS_PRIMARY, label1));
|
||||
EXPECT_EQ(vertex.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_SECONDARY_LABEL_IS_PRIMARY));
|
||||
}
|
||||
{
|
||||
auto acc = storage.Access(GetNextHlc());
|
||||
@ -138,9 +137,7 @@ TEST_F(StorageV3Accessor, TestAddLabels) {
|
||||
ASSERT_TRUE(vertex.HasValue());
|
||||
const auto schema_violation = vertex->AddLabelAndValidate(label1);
|
||||
ASSERT_TRUE(schema_violation.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(schema_violation.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(schema_violation.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_LABEL, label1));
|
||||
EXPECT_EQ(schema_violation.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,9 +181,7 @@ TEST_F(StorageV3Accessor, TestRemoveLabels) {
|
||||
auto vertex = CreateVertexAndValidate(acc, {}, PropertyValue{2});
|
||||
const auto res1 = vertex.RemoveLabelAndValidate(primary_label);
|
||||
ASSERT_TRUE(res1.HasError());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(res1.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(res1.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_LABEL, primary_label));
|
||||
EXPECT_EQ(res1.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_LABEL));
|
||||
}
|
||||
}
|
||||
|
||||
@ -205,20 +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());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(res.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(res.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_KEY, primary_label,
|
||||
SchemaProperty{primary_property, common::SchemaType::INT}));
|
||||
EXPECT_EQ(res.GetError(), SHARD_ERROR(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());
|
||||
ASSERT_TRUE(std::holds_alternative<SchemaViolation>(res.GetError()));
|
||||
EXPECT_EQ(std::get<SchemaViolation>(res.GetError()),
|
||||
SchemaViolation(SchemaViolation::ValidationStatus::VERTEX_UPDATE_PRIMARY_KEY, primary_label,
|
||||
SchemaProperty{primary_property, common::SchemaType::INT}));
|
||||
EXPECT_EQ(res.GetError(), SHARD_ERROR(ErrorCode::SCHEMA_VERTEX_UPDATE_PRIMARY_KEY));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user