Apply feedback from cpplint
This commit is contained in:
parent
9ae1671e4f
commit
1ef11a36f4
@ -20,7 +20,7 @@
|
||||
|
||||
#include "utils/logging.hpp"
|
||||
|
||||
#include "errors.hpp"
|
||||
#include "io/v3/errors.hpp"
|
||||
|
||||
template <typename T>
|
||||
class MgPromise;
|
||||
@ -130,7 +130,7 @@ class Shared {
|
||||
}
|
||||
|
||||
public:
|
||||
Shared(std::function<bool()> simulator_notifier) : simulator_notifier_(simulator_notifier) {}
|
||||
explicit Shared(std::function<bool()> simulator_notifier) : simulator_notifier_(simulator_notifier) {}
|
||||
Shared() = default;
|
||||
Shared(Shared &&) = delete;
|
||||
Shared &operator=(Shared &&) = delete;
|
||||
@ -141,7 +141,7 @@ class Shared {
|
||||
|
||||
template <typename T>
|
||||
class MgFuture {
|
||||
MgFuture(std::shared_ptr<Shared<T>> shared) : shared_(shared) {}
|
||||
explicit MgFuture(std::shared_ptr<Shared<T>> shared) : shared_(shared) {}
|
||||
|
||||
bool consumed_or_moved_ = false;
|
||||
std::shared_ptr<Shared<T>> shared_;
|
||||
@ -210,7 +210,7 @@ class MgPromise {
|
||||
friend std::pair<MgFuture<T>, MgPromise<T>> FuturePromisePairWithNotifier<T>(std::function<bool()>);
|
||||
|
||||
public:
|
||||
MgPromise(std::shared_ptr<Shared<T>> shared) : shared_(shared) {}
|
||||
explicit MgPromise(std::shared_ptr<Shared<T>> shared) : shared_(shared) {}
|
||||
|
||||
MgPromise(MgPromise &&old) {
|
||||
shared_ = std::move(old.shared_);
|
||||
|
@ -11,14 +11,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
|
||||
#include "address.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "future.hpp"
|
||||
#include "simulator_config.hpp"
|
||||
#include "simulator_handle.hpp"
|
||||
#include "transport.hpp"
|
||||
#include "io/v3/address.hpp"
|
||||
#include "io/v3/errors.hpp"
|
||||
#include "io/v3/future.hpp"
|
||||
#include "io/v3/simulator_config.hpp"
|
||||
#include "io/v3/simulator_handle.hpp"
|
||||
#include "io/v3/transport.hpp"
|
||||
|
||||
class SimulatorTransport {
|
||||
std::shared_ptr<SimulatorHandle> simulator_handle_;
|
||||
@ -66,7 +68,7 @@ class Simulator {
|
||||
std::shared_ptr<SimulatorHandle> simulator_handle_;
|
||||
|
||||
public:
|
||||
Simulator(SimulatorConfig config)
|
||||
explicit Simulator(SimulatorConfig config)
|
||||
: rng_(std::mt19937{config.rng_seed}), simulator_handle_{std::make_shared<SimulatorHandle>(config)} {}
|
||||
|
||||
void ShutDown() { simulator_handle_->ShutDown(); }
|
||||
|
@ -11,23 +11,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <any>
|
||||
#include <compare>
|
||||
|
||||
#include <any>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "address.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "simulator_config.hpp"
|
||||
#include "simulator_stats.hpp"
|
||||
#include "transport.hpp"
|
||||
#include "io/v3/address.hpp"
|
||||
#include "io/v3/errors.hpp"
|
||||
#include "io/v3/simulator_config.hpp"
|
||||
#include "io/v3/simulator_stats.hpp"
|
||||
#include "io/v3/transport.hpp"
|
||||
|
||||
// TODO enforce this around std::any usage
|
||||
// TODO(tyler) enforce this around std::any usage
|
||||
template <typename T>
|
||||
concept SameAsDecayed = std::same_as<T, std::decay_t<T>>;
|
||||
|
||||
@ -150,9 +152,9 @@ class OpaquePromise {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
OpaquePromise(std::unique_ptr<ResponsePromise<T>> promise)
|
||||
explicit OpaquePromise(std::unique_ptr<ResponsePromise<T>> promise)
|
||||
: ti_(&typeid(T)),
|
||||
ptr_((void *)promise.release()),
|
||||
ptr_(static_cast<void *>(promise.release())),
|
||||
dtor_([](void *ptr) { static_cast<ResponsePromise<T> *>(ptr)->~ResponsePromise<T>(); }),
|
||||
is_awaited_([](void *ptr) { return static_cast<ResponsePromise<T> *>(ptr)->IsAwaited(); }),
|
||||
fill_([](void *this_ptr, OpaqueMessage opaque_message) {
|
||||
@ -222,7 +224,7 @@ class SimulatorHandle {
|
||||
SimulatorConfig config_;
|
||||
|
||||
public:
|
||||
SimulatorHandle(SimulatorConfig config)
|
||||
explicit SimulatorHandle(SimulatorConfig config)
|
||||
: cluster_wide_time_microseconds_(config.start_time), rng_(config.rng_seed), config_(config) {}
|
||||
|
||||
void IncrementServerCountAndWaitForQuiescentState(Address address) {
|
||||
@ -254,7 +256,7 @@ class SimulatorHandle {
|
||||
uint64_t now = cluster_wide_time_microseconds_;
|
||||
|
||||
for (auto &[promise_key, dop] : promises_) {
|
||||
// TODO queue this up and drop it after its deadline
|
||||
// TODO(tyler) queue this up and drop it after its deadline
|
||||
if (dop.deadline < now) {
|
||||
std::cout << "timing out request" << std::endl;
|
||||
DeadlineAndOpaquePromise dop = std::move(promises_.at(promise_key));
|
||||
@ -387,7 +389,7 @@ class SimulatorHandle {
|
||||
}
|
||||
|
||||
template <Message... Ms>
|
||||
requires(sizeof...(Ms) > 0) RequestResult<Ms...> Receive(Address &receiver, uint64_t timeout_microseconds) {
|
||||
requires(sizeof...(Ms) > 0) RequestResult<Ms...> Receive(const Address &receiver, uint64_t timeout_microseconds) {
|
||||
std::unique_lock<std::mutex> lock(mu_);
|
||||
|
||||
uint64_t deadline = cluster_wide_time_microseconds_ + timeout_microseconds;
|
||||
@ -399,7 +401,7 @@ class SimulatorHandle {
|
||||
OpaqueMessage message = std::move(can_rx.back());
|
||||
can_rx.pop_back();
|
||||
|
||||
// TODO search for item in can_receive_ that matches the desired types, rather
|
||||
// TODO(tyler) search for item in can_receive_ that matches the desired types, rather
|
||||
// than asserting that the last item in can_rx matches.
|
||||
auto m_opt = message.Take<Ms...>();
|
||||
return std::move(m_opt).value();
|
||||
|
@ -9,8 +9,6 @@
|
||||
// by the Apache License, Version 2.0, included in the file
|
||||
// licenses/APL.txt.
|
||||
|
||||
// TODO chrono::microseconds instead of std::time_t
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
@ -19,9 +17,9 @@
|
||||
|
||||
#include "utils/result.hpp"
|
||||
|
||||
#include "address.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "future.hpp"
|
||||
#include "io/v3/address.hpp"
|
||||
#include "io/v3/errors.hpp"
|
||||
#include "io/v3/future.hpp"
|
||||
|
||||
using memgraph::utils::BasicResult;
|
||||
|
||||
|
@ -118,15 +118,26 @@ struct Follower {
|
||||
|
||||
using Role = std::variant<Candidate, Leader, Follower>;
|
||||
|
||||
template <typename IoImpl>
|
||||
/*
|
||||
template <typename T>
|
||||
concept ReplicatedStateMachine = true;
|
||||
requires(T a, uint8_t *ptr, size_t len) {
|
||||
{ a.Serialize() } -> std::same_as<std::vector<uint8_t>>;
|
||||
{ T::Deserialize(ptr, len) } -> std::same_as<T>;
|
||||
};
|
||||
*/
|
||||
|
||||
template <typename IoImpl /*, typename ReplicatedState, ReplicatedStateMachine<ReplicatedState> Rsm*/>
|
||||
class Server {
|
||||
CommonState state_;
|
||||
Role role_ = Candidate{};
|
||||
Io<IoImpl> io_;
|
||||
std::vector<Address> peers_;
|
||||
// Rsm rsm_;
|
||||
|
||||
public:
|
||||
Server(Io<IoImpl> io, std::vector<Address> peers) : io_(io), peers_(peers) {}
|
||||
Server(Io<IoImpl> &&io, std::vector<Address> peers /*, Rsm &&rsm */)
|
||||
: io_(std::move(io)), peers_(peers) /*, rsm_(std::move(rsm)*/ {}
|
||||
|
||||
void Run() {
|
||||
Time last_cron = io_.Now();
|
||||
@ -622,7 +633,7 @@ void RunServer(Server<IoImpl> server) {
|
||||
}
|
||||
|
||||
void RunSimulation() {
|
||||
auto config = SimulatorConfig{
|
||||
SimulatorConfig config{
|
||||
.drop_percent = 5,
|
||||
.perform_timeouts = true,
|
||||
.scramble_messages = true,
|
||||
@ -647,9 +658,9 @@ void RunSimulation() {
|
||||
std::vector<Address> srv_2_peers = {srv_addr_1, srv_addr_3};
|
||||
std::vector<Address> srv_3_peers = {srv_addr_1, srv_addr_2};
|
||||
|
||||
Server srv_1{srv_io_1, srv_1_peers};
|
||||
Server srv_2{srv_io_2, srv_2_peers};
|
||||
Server srv_3{srv_io_3, srv_3_peers};
|
||||
Server srv_1{std::move(srv_io_1), srv_1_peers};
|
||||
Server srv_2{std::move(srv_io_2), srv_2_peers};
|
||||
Server srv_3{std::move(srv_io_3), srv_3_peers};
|
||||
|
||||
auto srv_thread_1 = std::jthread(RunServer<SimulatorTransport>, std::move(srv_1));
|
||||
simulator.IncrementServerCountAndWaitForQuiescentState(srv_addr_1);
|
||||
@ -662,7 +673,7 @@ void RunSimulation() {
|
||||
|
||||
std::cout << "beginning test after servers have become quiescent" << std::endl;
|
||||
|
||||
std::mt19937 cli_rng_{};
|
||||
std::mt19937 cli_rng_{0};
|
||||
Address server_addrs[]{srv_addr_1, srv_addr_2, srv_addr_3};
|
||||
bool success = false;
|
||||
Address leader = server_addrs[0];
|
||||
|
Loading…
Reference in New Issue
Block a user