diff --git a/src/io/address.hpp b/src/io/address.hpp index d649dd451..5ad76fb7e 100644 --- a/src/io/address.hpp +++ b/src/io/address.hpp @@ -47,12 +47,10 @@ struct Address { if (unique_id == other.unique_id) { if (last_known_ip == other.last_known_ip) { return last_known_port < other.last_known_port; - } else { - return last_known_ip < other.last_known_ip; } - } else { - return unique_id < other.unique_id; + return last_known_ip < other.last_known_ip; } + return unique_id < other.unique_id; } std::string ToString() const { diff --git a/src/io/future.hpp b/src/io/future.hpp index f694e22dc..bc4adb9f6 100644 --- a/src/io/future.hpp +++ b/src/io/future.hpp @@ -108,9 +108,9 @@ class Shared { if (item_) { return Take(lock); - } else { - return std::nullopt; } + + return std::nullopt; } void Fill(T item) { @@ -142,14 +142,14 @@ class Future { explicit Future(std::shared_ptr> shared) : shared_(shared) {} Future() = delete; - Future(Future &&old) { + Future(Future &&old) noexcept { MG_ASSERT(!old.consumed_or_moved_, "Future moved from after already being moved from or consumed."); shared_ = std::move(old.shared_); consumed_or_moved_ = old.consumed_or_moved_; old.consumed_or_moved_ = true; } - Future &operator=(Future &&old) { + Future &operator=(Future &&old) noexcept { MG_ASSERT(!old.consumed_or_moved_, "Future moved from after already being moved from or consumed."); shared_ = std::move(old.shared_); old.consumed_or_moved_ = true; @@ -205,13 +205,13 @@ class Promise { explicit Promise(std::shared_ptr> shared) : shared_(shared) {} Promise() = delete; - Promise(Promise &&old) { + Promise(Promise &&old) noexcept { MG_ASSERT(!old.filled_or_moved_, "Promise moved from after already being moved from or filled."); shared_ = std::move(old.shared_); old.filled_or_moved_ = true; } - Promise &operator=(Promise &&old) { + Promise &operator=(Promise &&old) noexcept { MG_ASSERT(!old.filled_or_moved_, "Promise moved from after already being moved from or filled."); shared_ = std::move(old.shared_); old.filled_or_moved_ = true; diff --git a/src/io/simulator/message_conversion.hpp b/src/io/simulator/message_conversion.hpp index 11a1322ea..ab57bd18c 100644 --- a/src/io/simulator/message_conversion.hpp +++ b/src/io/simulator/message_conversion.hpp @@ -67,9 +67,9 @@ struct OpaqueMessage { .request_id = request_id, .from_address = from_address, }; - } else { - return std::nullopt; } + + return std::nullopt; } }; @@ -82,17 +82,17 @@ class OpaquePromise { std::function time_out_; public: - OpaquePromise(OpaquePromise &&old) + OpaquePromise(OpaquePromise &&old) noexcept : ti_(old.ti_), ptr_(old.ptr_), - dtor_(old.dtor_), - is_awaited_(old.is_awaited_), - fill_(old.fill_), - time_out_(old.time_out_) { + dtor_(std::move(old.dtor_)), + is_awaited_(std::move(old.is_awaited_)), + fill_(std::move(old.fill_)), + time_out_(std::move(old.time_out_)) { old.ptr_ = nullptr; } - OpaquePromise &operator=(OpaquePromise &&old) { + OpaquePromise &operator=(OpaquePromise &&old) noexcept { MG_ASSERT(this != &old); ptr_ = old.ptr_; @@ -115,7 +115,7 @@ class OpaquePromise { MG_ASSERT(typeid(T) == *ti_); MG_ASSERT(ptr_ != nullptr); - ResponsePromise *ptr = static_cast *>(ptr_); + auto ptr = static_cast *>(ptr_); ptr_ = nullptr; @@ -133,12 +133,12 @@ class OpaquePromise { auto response_envelope = ResponseEnvelope{.message = std::move(message), .request_id = opaque_message.request_id, .from_address = opaque_message.from_address}; - ResponsePromise *promise = static_cast *>(this_ptr); + auto promise = static_cast *>(this_ptr); auto unique_promise = std::unique_ptr>(promise); unique_promise->Fill(std::move(response_envelope)); }), time_out_([](void *ptr) { - ResponsePromise *promise = static_cast *>(ptr); + auto promise = static_cast *>(ptr); auto unique_promise = std::unique_ptr>(promise); ResponseResult result = TimedOut{}; unique_promise->Fill(std::move(result)); diff --git a/src/io/simulator/simulator.hpp b/src/io/simulator/simulator.hpp index 8e3ad85c0..354aae6ac 100644 --- a/src/io/simulator/simulator.hpp +++ b/src/io/simulator/simulator.hpp @@ -33,7 +33,7 @@ class Simulator { Io Register(Address address) { std::uniform_int_distribution seed_distrib; uint64_t seed = seed_distrib(rng_); - return Io(SimulatorTransport(simulator_handle_, address, seed), address); + return Io{SimulatorTransport{simulator_handle_, address, seed}, address}; } void IncrementServerCountAndWaitForQuiescentState(Address address) { diff --git a/src/io/simulator/simulator_handle.hpp b/src/io/simulator/simulator_handle.hpp index 140fd9111..cd5d5565d 100644 --- a/src/io/simulator/simulator_handle.hpp +++ b/src/io/simulator/simulator_handle.hpp @@ -47,12 +47,10 @@ struct PromiseKey { if (requester_address == other.requester_address) { if (request_id == other.request_id) { return replier_address < other.replier_address; - } else { - return request_id < other.request_id; } - } else { - return requester_address < other.requester_address; + return request_id < other.request_id; } + return requester_address < other.requester_address; } }; @@ -120,9 +118,9 @@ class SimulatorHandle { const Time deadline = cluster_wide_time_microseconds_ + timeout; - std::any message(std::move(request)); + std::any message(std::forward(request)); OpaqueMessage om{.from_address = from_address, .request_id = request_id, .message = std::move(message)}; - in_flight_.emplace_back(std::make_pair(std::move(to_address), std::move(om))); + in_flight_.emplace_back(std::make_pair(to_address, std::move(om))); PromiseKey promise_key{.requester_address = from_address, .request_id = request_id, .replier_address = to_address}; OpaquePromise opaque_promise(std::move(promise).ToUnique()); @@ -133,8 +131,6 @@ class SimulatorHandle { stats_.total_requests++; cv_.notify_all(); - - return; } template diff --git a/src/io/simulator/simulator_stats.hpp b/src/io/simulator/simulator_stats.hpp index 1f016c2fb..7f529a456 100644 --- a/src/io/simulator/simulator_stats.hpp +++ b/src/io/simulator/simulator_stats.hpp @@ -11,6 +11,8 @@ #pragma once +#include + namespace memgraph::io::simulator { struct SimulatorStats { uint64_t total_messages = 0; diff --git a/src/io/transport.hpp b/src/io/transport.hpp index 36df67c66..a9e550434 100644 --- a/src/io/transport.hpp +++ b/src/io/transport.hpp @@ -22,9 +22,10 @@ #include "io/time.hpp" #include "utils/result.hpp" +namespace memgraph::io { + using memgraph::utils::BasicResult; -namespace memgraph::io { // TODO(tyler) ensure that Message continues to represent // reasonable constraints around message types over time, // as we adapt things to use Thrift-generated message types. diff --git a/tests/simulation/basic_request.cpp b/tests/simulation/basic_request.cpp index 6e87b8e41..ac3190ad7 100644 --- a/tests/simulation/basic_request.cpp +++ b/tests/simulation/basic_request.cpp @@ -30,7 +30,7 @@ struct CounterResponse { }; void run_server(Io io) { - uint64_t highest_seen; + uint64_t highest_seen = 0; while (!io.ShouldShutDown()) { std::cout << "[SERVER] Is receiving..." << std::endl;