2018-01-22 19:36:14 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2018-01-24 19:16:14 +08:00
|
|
|
#include "communication/rpc/server.hpp"
|
2018-01-22 19:36:14 +08:00
|
|
|
#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:
|
2018-02-23 17:56:56 +08:00
|
|
|
RemoteDataRpcServer(database::GraphDb &db, communication::rpc::Server &server)
|
|
|
|
: db_(db), rpc_server_(server) {
|
2018-01-22 19:36:14 +08:00
|
|
|
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_;
|
2018-02-23 17:56:56 +08:00
|
|
|
communication::rpc::Server &rpc_server_;
|
2018-01-22 19:36:14 +08:00
|
|
|
};
|
|
|
|
} // namespace distributed
|