Summary: Converts the RPC stack to use Cap'n Proto for serialization instead of boost. There are still some traces of boost in other places in the code, but most of it is removed. A future diff should cleanup boost for good. The RPC API is now changed to be more flexible with regards to how serialize data. This makes the simplest cases a bit more verbose, but allows complex serialization code to be correctly written instead of relying on hacks. (For reference, look for the old serialization of `PullRpc` which had a nasty pointer hacks to inject accessors in `TypedValue`.) Since RPC messages were uselessly modeled via inheritance of Message base class, that class is now removed. Furthermore, that approach doesn't really work with Cap'n Proto. Instead, each message type is required to have some type information. This can be automated, so `define-rpc` has been added to LCP, which hopefully simplifies defining new RPC request and response messages. Specify Cap'n Proto schema ID in cmake This preserves Cap'n Proto generated typeIds across multiple generations of capnp schemas through LCP. It is imperative that typeId stays the same to ensure that different compilations of Memgraph may communicate via RPC in a distributed cluster. Use CLOS for meta information on C++ types in LCP Since some structure slots and functions have started to repeat themselves, it makes sense to model C++ meta information via Common Lisp Object System. Depends on D1391 Reviewers: buda, dgleich, mferencevic, mtomic, mculinovic, msantl Reviewed By: msantl Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1407
66 lines
1.8 KiB
C++
66 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
#include "communication/rpc/client_pool.hpp"
|
|
#include "communication/rpc/server.hpp"
|
|
#include "data_structures/concurrent/concurrent_map.hpp"
|
|
|
|
namespace database {
|
|
|
|
/** A set of counter that are guaranteed to produce unique, consecutive values
|
|
* on each call. */
|
|
class Counters {
|
|
public:
|
|
virtual ~Counters() {}
|
|
|
|
/**
|
|
* Returns the current value of the counter with the given name, and
|
|
* increments that counter. If the counter with the given name does not exist,
|
|
* a new counter is created and this function returns 0.
|
|
*/
|
|
virtual int64_t Get(const std::string &name) = 0;
|
|
|
|
/**
|
|
* Sets the counter with the given name to the given value. Returns nothing.
|
|
* If the counter with the given name does not exist, a new counter is created
|
|
* and set to the given value.
|
|
*/
|
|
virtual void Set(const std::string &name, int64_t values) = 0;
|
|
};
|
|
|
|
/** Implementation for the single-node memgraph */
|
|
class SingleNodeCounters : public Counters {
|
|
public:
|
|
int64_t Get(const std::string &name) override;
|
|
void Set(const std::string &name, int64_t value) override;
|
|
|
|
private:
|
|
ConcurrentMap<std::string, std::atomic<int64_t>> counters_;
|
|
};
|
|
|
|
/** Implementation for distributed master. */
|
|
class MasterCounters : public SingleNodeCounters {
|
|
public:
|
|
explicit MasterCounters(communication::rpc::Server &server);
|
|
|
|
private:
|
|
communication::rpc::Server &rpc_server_;
|
|
};
|
|
|
|
/** Implementation for distributed worker. */
|
|
class WorkerCounters : public Counters {
|
|
public:
|
|
explicit WorkerCounters(communication::rpc::ClientPool &master_client_pool);
|
|
|
|
int64_t Get(const std::string &name) override;
|
|
void Set(const std::string &name, int64_t value) override;
|
|
|
|
private:
|
|
communication::rpc::ClientPool &master_client_pool_;
|
|
};
|
|
|
|
} // namespace database
|