diff --git a/src/interface/storage.thrift b/src/interface/storage.thrift index 6fba4b586..96c6224bc 100644 --- a/src/interface/storage.thrift +++ b/src/interface/storage.thrift @@ -260,9 +260,9 @@ struct CreateVerticesRequest { } struct NewEdge { - 1: VertexId src; - 2: VertexId dest; - 3: EdgeType type; + 1: required VertexId src; + 2: required VertexId dest; + 3: required EdgeType type; 4: map properties; } @@ -272,12 +272,26 @@ struct CreateEdgesRequest { 4: list new_edges; } +// We still use different request for removing properties and labels +struct UpdateProperty { + 1: required binary name; + 2: required Value value; +} + +struct UpdateVerticesRequest { + 1: required i64 transaction_id; + 2: required list vertices_id; + 3: list updated_props; + 4: list added_labels; +} + service Storage { i64 startTransaction() Result commitTransaction(1: i64 transaction_id) void abortTransaction(1: i64 transaction_id) Result createVertices(1: CreateVerticesRequest req) + Result updateVertices(1: UpdateVerticesRequest req) Result createEdges(1: CreateEdgesRequest req) ScanVerticesResponse scanVertices(1: ScanVerticesRequest req) GetPropertiesResponse getProperties(1: GetPropertiesRequest req) diff --git a/tests/manual/storage_client_demo.cpp b/tests/manual/storage_client_demo.cpp index 377d1dda9..16de3e4a8 100644 --- a/tests/manual/storage_client_demo.cpp +++ b/tests/manual/storage_client_demo.cpp @@ -232,6 +232,47 @@ void CreateEdge(const std::shared_ptr &client, uint64_t src, .get(); } +void UpdateVerticesProperties(const std::shared_ptr &client, std::vector vertices_id, + std::vector labels, std::vector property_names) { + interface::storage::UpdateVerticesRequest request {}; + request.added_labels_ref()->assign(labels.cbegin(), labels.cend()); + request.vertices_id_ref()->assign(vertices_id.cbegin(), vertices_id.cend()); + + int prop_count = 10; + for (const auto prop : property_names) { + interface::storage::UpdateProperty update_prop {}; + update_prop.name = prop; + update_prop.value.set_int_v(prop_count); + request.updated_props_ref()->emplace_back(update_prop); + prop_count++; + } + + client->future_startTransaction() + .then([client, request = std::move(request)](folly::Try &&result) mutable { + if (result.hasException()) { + LOG(INFO) << "FAILED1: " << result.exception().get_exception()->what() << std::endl; + return folly::makeFuture(std::runtime_error("failed to start transaction")); + } + const auto transaction_id = result.value(); + request.transaction_id_ref() = transaction_id; + LOG(INFO) << "Sending message..."; + + return client->future_updateVertices(request).then( + [transaction_id, client](folly::Try &&reply) { + LOG(INFO) << "Closing transaction"; + if (reply.hasException()) { + LOG(INFO) << "FAILED2: " << reply.exception().get_exception()->what() << std::endl; + return client->future_abortTransaction(transaction_id).then([](folly::Try &&reply) { + return folly::makeFuture(std::runtime_error("updating vertices failed")); + }); + } + LOG(INFO) << "SUCCESS\n"; + return client->future_commitTransaction(transaction_id); + }); + }) + .get(); +} + int main(int argc, char *argv[]) { FLAGS_logtostderr = true; folly::init(&argc, &argv); @@ -262,7 +303,10 @@ int main(int argc, char *argv[]) { CreateEdge(client, 1, 2, "type1", {"proop", "prooop2"}); CreateEdge(client, 2, 3, "type5", {}); // This should fail - CreateEdge(client, 12121212, 2121212121, "type5", {}); + // CreateEdge(client, 12121212, 2121212121, "type5", {}); + + UpdateVerticesProperties(client, {0, 1, 2}, {}, {"proop", "new_prop"}); + UpdateVerticesProperties(client, {0}, {"el_label"}, {"proop", "new_new_prop"}); const auto transaction_id = client->future_startTransaction().get(); std::vector props{"proop", "prooop2"}; diff --git a/tests/manual/storage_service.cpp b/tests/manual/storage_service.cpp index a1b199032..6e9b226c4 100644 --- a/tests/manual/storage_service.cpp +++ b/tests/manual/storage_service.cpp @@ -210,6 +210,32 @@ void StorageServiceHandler::createEdges(::interface::storage::Result &result, spdlog::info("Edges creation done!"); } +void StorageServiceHandler::updateVertices(::interface::storage::Result &result, + const ::interface::storage::UpdateVerticesRequest &req) { + spdlog::info("Updating vertices..."); + result.success_ref() = false; + auto accessor = active_transactions_.at(req.get_transaction_id()); + + for (const auto vertex_id : req.get_vertices_id()) { + auto vertex = accessor->FindVertex(memgraph::storage::Gid::FromInt(vertex_id), memgraph::storage::View::NEW); + if (!vertex) { + throw std::runtime_error("Vertex not found in storage"); + } + + for (auto &updated_prop : req.get_updated_props()) { + if (const auto result = vertex->SetProperty(accessor->NameToProperty(updated_prop.name), + ThriftValueToPropertyValue(updated_prop.value)); + result.HasError()) { + return; + } + + // TODO Add label + } + } + + spdlog::info("Updating vertices done!"); +} + static_assert(sizeof(apache::thrift::optional_field_ref) > 16); std::function(memgraph::storage::VertexAccessor)> CreateVertexProcessor( diff --git a/tests/manual/storage_service.hpp b/tests/manual/storage_service.hpp index 9a384678c..7e7c623a4 100644 --- a/tests/manual/storage_service.hpp +++ b/tests/manual/storage_service.hpp @@ -33,6 +33,9 @@ class StorageServiceHandler final : public interface::storage::StorageSvIf { void createVertices(::interface::storage::Result &result, const ::interface::storage::CreateVerticesRequest &req) override; + void updateVertices(::interface::storage::Result &result, + const ::interface::storage::UpdateVerticesRequest &req) override; + void createEdges(::interface::storage::Result &result, const ::interface::storage::CreateEdgesRequest &req) override; void scanVertices(::interface::storage::ScanVerticesResponse &resp,