c877c87bb4
Summary: Previously, the RPC stack used the network stack only to receive messages. The messages were then added to a separate queue that was processed by different thread pools. This design was inefficient because there was a lock when inserting and getting messages from the common queue. This diff removes the need for separate thread pools by utilising the new network stack design. This is possible because the new network stack allows full processing of the network request without blocking the whole queue. Reviewers: buda, florijan, teon.banek, dgleich, mislav.bradac Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1229
39 lines
1.3 KiB
C++
39 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include "communication/rpc/server.hpp"
|
|
#include "database/graph_db.hpp"
|
|
#include "database/graph_db_accessor.hpp"
|
|
#include "distributed/remote_data_rpc_messages.hpp"
|
|
#include "transactions/type.hpp"
|
|
|
|
namespace distributed {
|
|
|
|
/** Serves this worker's data to others. */
|
|
class RemoteDataRpcServer {
|
|
public:
|
|
RemoteDataRpcServer(database::GraphDb &db, communication::rpc::Server &server)
|
|
: db_(db), rpc_server_(server) {
|
|
rpc_server_.Register<RemoteVertexRpc>([this](const RemoteVertexReq &req) {
|
|
database::GraphDbAccessor dba(db_, req.member.tx_id);
|
|
auto vertex = dba.FindVertexChecked(req.member.gid, false);
|
|
CHECK(vertex.GetOld())
|
|
<< "Old record must exist when sending vertex by RPC";
|
|
return std::make_unique<RemoteVertexRes>(vertex.GetOld(), db_.WorkerId());
|
|
});
|
|
|
|
rpc_server_.Register<RemoteEdgeRpc>([this](const RemoteEdgeReq &req) {
|
|
database::GraphDbAccessor dba(db_, req.member.tx_id);
|
|
auto edge = dba.FindEdgeChecked(req.member.gid, false);
|
|
CHECK(edge.GetOld()) << "Old record must exist when sending edge by RPC";
|
|
return std::make_unique<RemoteEdgeRes>(edge.GetOld(), db_.WorkerId());
|
|
});
|
|
}
|
|
|
|
private:
|
|
database::GraphDb &db_;
|
|
communication::rpc::Server &rpc_server_;
|
|
};
|
|
} // namespace distributed
|