Summary: In a bunch of places `TypedValue` was used where `PropertyValue` should be. A lot of times it was only because `TypedValue` serialization code could be reused for `PropertyValue`, only without providing callbacks for `VERTEX`, `EDGE` and `PATH`. So first I wrote separate serialization code for `PropertyValue` and put it into storage folder. Then I fixed all the places where `TypedValue` was incorrectly used instead of `PropertyValue`. I also disabled implicit `TypedValue` to `PropertyValue` conversion in hopes of preventing misuse in the future. After that, I wrote code for `VertexAccessor` and `EdgeAccessor` serialization and put it into `storage` folder because it was almost duplicated in distributed BFS and pull produce RPC messages. On the sender side, some subset of records (old or new or both) is serialized, and on the reciever side, records are deserialized and immediately put into transaction cache. Then I rewrote the `TypedValue` serialization functions (`SaveCapnpTypedValue` and `LoadCapnpTypedValue`) to not take callbacks for `VERTEX`, `EDGE` and `PATH`, but use accessor serialization functions instead. That means that any code that wants to use `TypedValue` serialization must hold a reference to `GraphDbAccessor` and `DataManager`, so that should make clients reconsider if they really want to use `TypedValue` instead of `PropertyValue`. Reviewers: teon.banek, msantl Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1598
140 lines
4.6 KiB
C++
140 lines
4.6 KiB
C++
/// @file
|
|
|
|
#pragma once
|
|
|
|
#include "database/graph_db.hpp"
|
|
#include "durability/recovery.hpp"
|
|
|
|
namespace distributed {
|
|
class BfsRpcServer;
|
|
class BfsRpcClients;
|
|
class DataRpcServer;
|
|
class DataRpcClients;
|
|
class PlanDispatcher;
|
|
class PlanConsumer;
|
|
class PullRpcClients;
|
|
class ProduceRpcServer;
|
|
class UpdatesRpcServer;
|
|
class UpdatesRpcClients;
|
|
class DataManager;
|
|
class IndexRpcClients;
|
|
} // namespace distributed
|
|
|
|
namespace database {
|
|
|
|
namespace impl {
|
|
class Master;
|
|
class Worker;
|
|
} // namespace impl
|
|
|
|
/// Abstract base class for concrete distributed versions of GraphDb
|
|
class DistributedGraphDb : public GraphDb {
|
|
public:
|
|
virtual int WorkerId() const = 0;
|
|
virtual std::vector<int> GetWorkerIds() const = 0;
|
|
|
|
virtual distributed::BfsRpcClients &bfs_subcursor_clients() = 0;
|
|
virtual distributed::DataRpcClients &data_clients() = 0;
|
|
virtual distributed::UpdatesRpcServer &updates_server() = 0;
|
|
virtual distributed::UpdatesRpcClients &updates_clients() = 0;
|
|
virtual distributed::DataManager &data_manager() = 0;
|
|
};
|
|
|
|
class Master final : public DistributedGraphDb {
|
|
public:
|
|
explicit Master(Config config = Config());
|
|
~Master();
|
|
|
|
std::unique_ptr<GraphDbAccessor> Access() override;
|
|
std::unique_ptr<GraphDbAccessor> Access(tx::TransactionId) override;
|
|
|
|
Storage &storage() override;
|
|
durability::WriteAheadLog &wal() override;
|
|
tx::Engine &tx_engine() override;
|
|
storage::ConcurrentIdMapper<storage::Label> &label_mapper() override;
|
|
storage::ConcurrentIdMapper<storage::EdgeType> &edge_type_mapper() override;
|
|
storage::ConcurrentIdMapper<storage::Property> &property_mapper() override;
|
|
database::Counters &counters() override;
|
|
void CollectGarbage() override;
|
|
int WorkerId() const override;
|
|
std::vector<int> GetWorkerIds() const override;
|
|
bool MakeSnapshot(GraphDbAccessor &accessor) override;
|
|
void ReinitializeStorage() override;
|
|
|
|
/** Gets this master's endpoint. */
|
|
io::network::Endpoint endpoint() const;
|
|
/** Gets the endpoint of the worker with the given id. */
|
|
// TODO make const once Coordination::GetEndpoint is const.
|
|
io::network::Endpoint GetEndpoint(int worker_id);
|
|
|
|
distributed::BfsRpcClients &bfs_subcursor_clients() override;
|
|
distributed::DataRpcClients &data_clients() override;
|
|
distributed::UpdatesRpcServer &updates_server() override;
|
|
distributed::UpdatesRpcClients &updates_clients() override;
|
|
distributed::DataManager &data_manager() override;
|
|
|
|
distributed::PullRpcClients &pull_clients();
|
|
distributed::PlanDispatcher &plan_dispatcher();
|
|
distributed::IndexRpcClients &index_rpc_clients();
|
|
|
|
private:
|
|
std::unique_ptr<impl::Master> impl_;
|
|
|
|
utils::Scheduler transaction_killer_;
|
|
std::unique_ptr<utils::Scheduler> snapshot_creator_;
|
|
};
|
|
|
|
class Worker final : public DistributedGraphDb {
|
|
public:
|
|
explicit Worker(Config config = Config());
|
|
~Worker();
|
|
|
|
std::unique_ptr<GraphDbAccessor> Access() override;
|
|
std::unique_ptr<GraphDbAccessor> Access(tx::TransactionId) override;
|
|
|
|
Storage &storage() override;
|
|
durability::WriteAheadLog &wal() override;
|
|
tx::Engine &tx_engine() override;
|
|
storage::ConcurrentIdMapper<storage::Label> &label_mapper() override;
|
|
storage::ConcurrentIdMapper<storage::EdgeType> &edge_type_mapper() override;
|
|
storage::ConcurrentIdMapper<storage::Property> &property_mapper() override;
|
|
database::Counters &counters() override;
|
|
void CollectGarbage() override;
|
|
int WorkerId() const override;
|
|
std::vector<int> GetWorkerIds() const override;
|
|
bool MakeSnapshot(GraphDbAccessor &accessor) override;
|
|
void ReinitializeStorage() override;
|
|
void RecoverWalAndIndexes(durability::RecoveryData *recovery_data);
|
|
|
|
/** Gets this worker's endpoint. */
|
|
io::network::Endpoint endpoint() const;
|
|
/** Gets the endpoint of the worker with the given id. */
|
|
// TODO make const once Coordination::GetEndpoint is const.
|
|
io::network::Endpoint GetEndpoint(int worker_id);
|
|
void WaitForShutdown();
|
|
|
|
distributed::BfsRpcClients &bfs_subcursor_clients() override;
|
|
distributed::DataRpcClients &data_clients() override;
|
|
distributed::UpdatesRpcServer &updates_server() override;
|
|
distributed::UpdatesRpcClients &updates_clients() override;
|
|
distributed::DataManager &data_manager() override;
|
|
|
|
distributed::PlanConsumer &plan_consumer();
|
|
|
|
private:
|
|
std::unique_ptr<impl::Worker> impl_;
|
|
|
|
utils::Scheduler transaction_killer_;
|
|
};
|
|
|
|
/// Creates a new Vertex on the given worker.
|
|
/// It is NOT allowed to call this function with this worker's id.
|
|
VertexAccessor InsertVertexIntoRemote(
|
|
GraphDbAccessor *dba, int worker_id,
|
|
const std::vector<storage::Label> &labels,
|
|
const std::unordered_map<storage::Property, PropertyValue>
|
|
&properties,
|
|
std::experimental::optional<int64_t> cypher_id);
|
|
|
|
} // namespace database
|