From 6bb40a7f49882e3364db4db1beb8b6188660042f Mon Sep 17 00:00:00 2001 From: Jure Bajic Date: Wed, 19 Oct 2022 13:55:46 +0200 Subject: [PATCH] Create ExpandOne request (#580) Refactor CreateEdge into CreateExpand --- src/coordinator/shard_map.hpp | 14 ++- src/glue/v2/communication.cpp | 40 ++++++- src/memgraph.cpp | 11 +- src/query/v2/accessors.cpp | 2 + src/query/v2/accessors.hpp | 2 + src/query/v2/context.hpp | 19 +++- src/query/v2/interpreter.cpp | 16 ++- src/query/v2/interpreter.hpp | 5 +- src/query/v2/plan/operator.cpp | 123 ++++++++++++++++++-- src/query/v2/plan/vertex_count_cache.hpp | 5 +- src/query/v2/requests.hpp | 29 +++-- src/query/v2/shard_request_manager.hpp | 126 ++++++++++++++++----- src/storage/v3/bindings/db_accessor.hpp | 2 +- src/storage/v3/shard_rsm.cpp | 44 ++++--- src/storage/v3/shard_rsm.hpp | 2 +- tests/simulation/shard_request_manager.cpp | 20 ++++ tests/simulation/shard_rsm.cpp | 34 +++--- 17 files changed, 401 insertions(+), 93 deletions(-) diff --git a/src/coordinator/shard_map.hpp b/src/coordinator/shard_map.hpp index f99bdbc25..93ddd78c6 100644 --- a/src/coordinator/shard_map.hpp +++ b/src/coordinator/shard_map.hpp @@ -54,6 +54,9 @@ struct AddressAndStatus { memgraph::io::Address address; Status status; friend bool operator<(const AddressAndStatus &lhs, const AddressAndStatus &rhs) { return lhs.address < rhs.address; } + friend bool operator==(const AddressAndStatus &lhs, const AddressAndStatus &rhs) { + return lhs.address == rhs.address; + } }; using PrimaryKey = std::vector; @@ -115,7 +118,12 @@ struct ShardMap { bool mutated = false; for (auto &[label_id, label_space] : label_spaces) { - for (auto &[low_key, shard] : label_space.shards) { + for (auto it = label_space.shards.begin(); it != label_space.shards.end(); it++) { + auto &[low_key, shard] = *it; + std::optional high_key; + if (const auto next_it = std::next(it); next_it != label_space.shards.end()) { + high_key = next_it->first; + } // TODO(tyler) avoid these triple-nested loops by having the heartbeat include better info bool machine_contains_shard = false; @@ -133,7 +141,7 @@ struct ShardMap { .uuid = aas.address.unique_id, .label_id = label_id, .min_key = low_key, - .max_key = std::nullopt, + .max_key = high_key, .schema = schemas[label_id], .config = Config{}, }); @@ -150,7 +158,7 @@ struct ShardMap { ret.push_back(ShardToInitialize{.uuid = address.unique_id, .label_id = label_id, .min_key = low_key, - .max_key = std::nullopt, + .max_key = high_key, .schema = schemas[label_id], .config = Config{}}); diff --git a/src/glue/v2/communication.cpp b/src/glue/v2/communication.cpp index 217f39545..6da68950a 100644 --- a/src/glue/v2/communication.cpp +++ b/src/glue/v2/communication.cpp @@ -204,9 +204,45 @@ Value ToBoltValue(msgs::Value value) { case msgs::Value::Type::Vertex: case msgs::Value::Type::Edge: case msgs::Value::Type::Path: { - throw utils::BasicException("Path, Vertex and Edge not supported!"); + throw utils::BasicException("Vertex, Edge and Path are not supported!"); + } + } +} + +Value ToBoltValue(msgs::Value value, const coordinator::ShardMap & /*shard_map*/, storage::v3::View /*view*/) { + switch (value.type) { + case msgs::Value::Type::Null: + return {}; + case msgs::Value::Type::Bool: + return {value.bool_v}; + case msgs::Value::Type::Int64: + return {value.int_v}; + case msgs::Value::Type::Double: + return {value.double_v}; + case msgs::Value::Type::String: + return {std::string(value.string_v)}; + case msgs::Value::Type::List: { + std::vector values; + values.reserve(value.list_v.size()); + for (const auto &v : value.list_v) { + auto maybe_value = ToBoltValue(v); + values.emplace_back(std::move(maybe_value)); + } + return Value{std::move(values)}; + } + case msgs::Value::Type::Map: { + std::map map; + for (const auto &kv : value.map_v) { + auto maybe_value = ToBoltValue(kv.second); + map.emplace(kv.first, std::move(maybe_value)); + } + return Value{std::move(map)}; + } + case msgs::Value::Type::Vertex: + case msgs::Value::Type::Edge: + case msgs::Value::Type::Path: { + throw utils::BasicException("Vertex, Edge and Path are not supported!"); } - // TODO Value to Date types not supported } } diff --git a/src/memgraph.cpp b/src/memgraph.cpp index 7d821b3e6..36a194fb4 100644 --- a/src/memgraph.cpp +++ b/src/memgraph.cpp @@ -639,12 +639,15 @@ int main(int argc, char **argv) { .listen_port = unique_local_addr_query.last_known_port, }; + const std::string property{"property"}; + const std::string label{"label"}; memgraph::coordinator::ShardMap sm; - auto prop_map = sm.AllocatePropertyIds(std::vector{"property"}); + auto prop_map = sm.AllocatePropertyIds(std::vector{property}); auto edge_type_map = sm.AllocateEdgeTypeIds(std::vector{"edge_type"}); - std::vector schema{ - {prop_map.at("property"), memgraph::common::SchemaType::INT}}; - sm.InitializeNewLabel("label", schema, 1, sm.shard_map_version); + std::vector schema{{prop_map.at(property), memgraph::common::SchemaType::INT}}; + sm.InitializeNewLabel(label, schema, 1, sm.shard_map_version); + sm.SplitShard(sm.GetHlc(), sm.GetLabelId(label), + std::vector{memgraph::storage::v3::PropertyValue{2}}); memgraph::coordinator::Coordinator coordinator{sm}; diff --git a/src/query/v2/accessors.cpp b/src/query/v2/accessors.cpp index 87fb74aa3..de64e80fb 100644 --- a/src/query/v2/accessors.cpp +++ b/src/query/v2/accessors.cpp @@ -43,6 +43,8 @@ VertexAccessor EdgeAccessor::From() const { return VertexAccessor(Vertex{edge.sr VertexAccessor::VertexAccessor(Vertex v, std::vector> props) : vertex(std::move(v)), properties(std::move(props)) {} +Label VertexAccessor::PrimaryLabel() const { return vertex.id.first; } + std::vector