From 5b7947cc182c0b12404a352fd9414a8ecb69b941 Mon Sep 17 00:00:00 2001 From: Dominik Gleich <dominik.gleich@memgraph.io> Date: Wed, 30 May 2018 13:41:58 +0200 Subject: [PATCH] Revert "Remote vertex with gid creation" Summary: This reverts commit 7d161319f0ac1e689fa3ad870f887481d42b5b18. Reviewers: teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1410 --- src/database/graph_db_accessor.cpp | 9 +++------ src/database/graph_db_accessor.hpp | 9 +++------ src/distributed/updates_rpc_clients.cpp | 11 ++++++----- src/distributed/updates_rpc_clients.hpp | 21 ++++++++++----------- src/distributed/updates_rpc_messages.hpp | 3 --- src/distributed/updates_rpc_server.cpp | 9 ++++----- src/distributed/updates_rpc_server.hpp | 9 ++++----- tests/unit/distributed_updates.cpp | 11 ----------- 8 files changed, 30 insertions(+), 52 deletions(-) diff --git a/src/database/graph_db_accessor.cpp b/src/database/graph_db_accessor.cpp index abfb97329..ffd9d1337 100644 --- a/src/database/graph_db_accessor.cpp +++ b/src/database/graph_db_accessor.cpp @@ -94,16 +94,13 @@ VertexAccessor GraphDbAccessor::InsertVertex( VertexAccessor GraphDbAccessor::InsertVertexIntoRemote( int worker_id, const std::vector<storage::Label> &labels, - const std::unordered_map<storage::Property, query::TypedValue> &properties, - std::experimental::optional<gid::Gid> requested_gid) { + const std::unordered_map<storage::Property, query::TypedValue> + &properties) { CHECK(worker_id != db().WorkerId()) << "Not allowed to call InsertVertexIntoRemote for local worker"; gid::Gid gid = db().updates_clients().CreateVertex( - worker_id, transaction_id(), labels, properties, requested_gid); - - CHECK(!requested_gid || *requested_gid == gid) - << "Unable to assign requested vertex gid"; + worker_id, transaction_id(), labels, properties); auto vertex = std::make_unique<Vertex>(); vertex->labels_ = labels; diff --git a/src/database/graph_db_accessor.hpp b/src/database/graph_db_accessor.hpp index 2a3985c4e..bacb710d0 100644 --- a/src/database/graph_db_accessor.hpp +++ b/src/database/graph_db_accessor.hpp @@ -78,15 +78,12 @@ class GraphDbAccessor { VertexAccessor InsertVertex(std::experimental::optional<gid::Gid> requested_gid = std::experimental::nullopt); - /** Creates a new Vertex on the given worker with the `requested_gid` if - * specified. It is NOT allowed to call this function with this worker's id. - */ + /** Creates a new Vertex on the given worker. It is NOT allowed to call this + * function with this worker's id. */ VertexAccessor InsertVertexIntoRemote( int worker_id, const std::vector<storage::Label> &labels, const std::unordered_map<storage::Property, query::TypedValue> - &properties, - std::experimental::optional<gid::Gid> requested_gid = - std::experimental::nullopt); + &properties); /** * Removes the vertex of the given accessor. If the vertex has any outgoing or diff --git a/src/distributed/updates_rpc_clients.cpp b/src/distributed/updates_rpc_clients.cpp index 791ce8d59..0d29c5203 100644 --- a/src/distributed/updates_rpc_clients.cpp +++ b/src/distributed/updates_rpc_clients.cpp @@ -23,7 +23,7 @@ void RaiseIfRemoteError(UpdateResult result) { break; } } -} // namespace +} UpdateResult UpdatesRpcClients::Update(int worker_id, const database::StateDelta &delta) { @@ -35,10 +35,10 @@ UpdateResult UpdatesRpcClients::Update(int worker_id, gid::Gid UpdatesRpcClients::CreateVertex( int worker_id, tx::TransactionId tx_id, const std::vector<storage::Label> &labels, - const std::unordered_map<storage::Property, query::TypedValue> &properties, - std::experimental::optional<gid::Gid> requested_gid) { + const std::unordered_map<storage::Property, query::TypedValue> + &properties) { auto res = worker_clients_.GetClientPool(worker_id).Call<CreateVertexRpc>( - CreateVertexReqData{tx_id, labels, properties, requested_gid}); + CreateVertexReqData{tx_id, labels, properties}); CHECK(res) << "CreateVertexRpc failed on worker: " << worker_id; CHECK(res->member.result == UpdateResult::DONE) << "Remote Vertex creation result not UpdateResult::DONE"; @@ -59,7 +59,8 @@ storage::EdgeAddress UpdatesRpcClients::CreateEdge( return {res->member.gid, from_worker}; } -void UpdatesRpcClients::AddInEdge(tx::TransactionId tx_id, VertexAccessor &from, +void UpdatesRpcClients::AddInEdge(tx::TransactionId tx_id, + VertexAccessor &from, storage::EdgeAddress edge_address, VertexAccessor &to, storage::EdgeType edge_type) { diff --git a/src/distributed/updates_rpc_clients.hpp b/src/distributed/updates_rpc_clients.hpp index 66c2c3708..a5baf55f7 100644 --- a/src/distributed/updates_rpc_clients.hpp +++ b/src/distributed/updates_rpc_clients.hpp @@ -26,21 +26,20 @@ class UpdatesRpcClients { /// Sends an update delta to the given worker. UpdateResult Update(int worker_id, const database::StateDelta &delta); - /// Creates a vertex on the given worker and returns it's id (tries to create - /// vertex with requested_gid first). - gid::Gid CreateVertex(int worker_id, tx::TransactionId tx_id, - const std::vector<storage::Label> &labels, - const std::unordered_map<storage::Property, - query::TypedValue> &properties, - std::experimental::optional<gid::Gid> requested_gid); + /// Creates a vertex on the given worker and returns it's id. + gid::Gid CreateVertex( + int worker_id, tx::TransactionId tx_id, + const std::vector<storage::Label> &labels, + const std::unordered_map<storage::Property, query::TypedValue> + &properties); /// Creates an edge on the given worker and returns it's address. If the `to` /// vertex is on the same worker as `from`, then all remote CRUD will be /// handled by a call to this function. Otherwise a separate call to /// `AddInEdge` might be necessary. Throws all the exceptions that can /// occur remotely as a result of updating a vertex. - storage::EdgeAddress CreateEdge(tx::TransactionId tx_id, VertexAccessor &from, - VertexAccessor &to, + storage::EdgeAddress CreateEdge(tx::TransactionId tx_id, + VertexAccessor &from, VertexAccessor &to, storage::EdgeType edge_type); /// Adds the edge with the given address to the `to` vertex as an incoming @@ -62,8 +61,8 @@ class UpdatesRpcClients { gid::Gid vertex_from_id, storage::VertexAddress vertex_to_addr); - void RemoveInEdge(tx::TransactionId tx_id, int worker_id, gid::Gid vertex_id, - storage::EdgeAddress edge_address); + void RemoveInEdge(tx::TransactionId tx_id, int worker_id, + gid::Gid vertex_id, storage::EdgeAddress edge_address); /// Calls for all the workers (except the given one) to apply their updates /// and returns the future results. diff --git a/src/distributed/updates_rpc_messages.hpp b/src/distributed/updates_rpc_messages.hpp index e257361e2..098a13696 100644 --- a/src/distributed/updates_rpc_messages.hpp +++ b/src/distributed/updates_rpc_messages.hpp @@ -50,7 +50,6 @@ struct CreateVertexReqData { tx::TransactionId tx_id; std::vector<storage::Label> labels; std::unordered_map<storage::Property, query::TypedValue> properties; - std::experimental::optional<gid::Gid> requested_gid; private: friend class boost::serialization::access; @@ -64,7 +63,6 @@ struct CreateVertexReqData { ar << kv.first; utils::SaveTypedValue(ar, kv.second); } - ar << requested_gid; } template <class TArchive> @@ -80,7 +78,6 @@ struct CreateVertexReqData { utils::LoadTypedValue(ar, tv); properties.emplace(p, std::move(tv)); } - ar >> requested_gid; } BOOST_SERIALIZATION_SPLIT_MEMBER() }; diff --git a/src/distributed/updates_rpc_server.cpp b/src/distributed/updates_rpc_server.cpp index a02d4cc73..09e25a569 100644 --- a/src/distributed/updates_rpc_server.cpp +++ b/src/distributed/updates_rpc_server.cpp @@ -61,9 +61,9 @@ UpdateResult UpdatesRpcServer::TransactionUpdates<TRecordAccessor>::Emplace( template <typename TRecordAccessor> gid::Gid UpdatesRpcServer::TransactionUpdates<TRecordAccessor>::CreateVertex( const std::vector<storage::Label> &labels, - const std::unordered_map<storage::Property, query::TypedValue> &properties, - std::experimental::optional<gid::Gid> requested_gid) { - auto result = db_accessor_.InsertVertex(requested_gid); + const std::unordered_map<storage::Property, query::TypedValue> + &properties) { + auto result = db_accessor_.InsertVertex(); for (auto &label : labels) result.add_label(label); for (auto &kv : properties) result.PropsSet(kv.first, kv.second); std::lock_guard<SpinLock> guard{lock_}; @@ -201,8 +201,7 @@ UpdatesRpcServer::UpdatesRpcServer(database::GraphDb &db, server.Register<CreateVertexRpc>([this](const CreateVertexReq &req) { gid::Gid gid = GetUpdates(vertex_updates_, req.member.tx_id) - .CreateVertex(req.member.labels, req.member.properties, - req.member.requested_gid); + .CreateVertex(req.member.labels, req.member.properties); return std::make_unique<CreateVertexRes>( CreateResult{UpdateResult::DONE, gid}); }); diff --git a/src/distributed/updates_rpc_server.hpp b/src/distributed/updates_rpc_server.hpp index 62ce8ace0..de3bef334 100644 --- a/src/distributed/updates_rpc_server.hpp +++ b/src/distributed/updates_rpc_server.hpp @@ -40,13 +40,11 @@ class UpdatesRpcServer { /// fail-fast on serialization and update-after-delete errors. UpdateResult Emplace(const database::StateDelta &delta); - /// Creates a new vertex with requested_gid if possible and returns it's - /// gid. + /// Creates a new vertex and returns it's gid. gid::Gid CreateVertex( const std::vector<storage::Label> &labels, const std::unordered_map<storage::Property, query::TypedValue> - &properties, - std::experimental::optional<gid::Gid> requested_gid); + &properties); /// Creates a new edge and returns it's gid. Does not update vertices at the /// end of the edge. @@ -86,7 +84,8 @@ class UpdatesRpcServer { database::GraphDb &db_; template <typename TAccessor> - using MapT = ConcurrentMap<tx::TransactionId, TransactionUpdates<TAccessor>>; + using MapT = + ConcurrentMap<tx::TransactionId, TransactionUpdates<TAccessor>>; MapT<VertexAccessor> vertex_updates_; MapT<EdgeAccessor> edge_updates_; diff --git a/tests/unit/distributed_updates.cpp b/tests/unit/distributed_updates.cpp index ff37b66cb..24ec0f9aa 100644 --- a/tests/unit/distributed_updates.cpp +++ b/tests/unit/distributed_updates.cpp @@ -133,17 +133,6 @@ TEST_F(DistributedGraphDbTest, CreateVertexWithData) { } } -// Checks if it's possible to request a specific gid for vertex creation -TEST_F(DistributedGraphDbTest, CreateVertexWithGid) { - std::experimental::optional<gid::Gid> gid(1337); - { - database::GraphDbAccessor dba{worker(1)}; - auto v = dba.InsertVertexIntoRemote(2, {}, {}, gid); - EXPECT_EQ(v.gid(), *gid); - dba.Commit(); - } -} - // Checks if expiring a local record for a local update before applying a remote // update delta causes a problem TEST_F(DistributedGraphDbTest, UpdateVertexRemoteAndLocal) {