From f8e503201106544b95af0f7b78760b07ae492495 Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Thu, 21 Jul 2022 12:10:23 +0000 Subject: [PATCH] Restructure files into namespaces and subdirectories --- src/CMakeLists.txt | 2 +- src/io/CMakeLists.txt | 5 ++++- src/io/{v3 => }/address.hpp | 2 ++ src/io/{v3 => }/errors.hpp | 2 ++ src/io/future.hpp | 2 +- src/io/simulator/CMakeLists.txt | 11 +++++++++++ src/io/{v3 => simulator}/simulator.hpp | 10 ++++++---- src/io/{v3 => simulator}/simulator_config.hpp | 2 ++ src/io/{v3 => simulator}/simulator_handle.hpp | 12 +++++++----- src/io/{v3 => simulator}/simulator_stats.hpp | 2 ++ src/io/{v3 => simulator}/simulator_transport.hpp | 6 ++++-- src/io/{v3 => }/transport.hpp | 9 ++++----- src/io/v3/CMakeLists.txt | 14 -------------- tests/simulation/CMakeLists.txt | 2 +- tests/simulation/basic_request.cpp | 10 +++++++++- tests/simulation/raft.cpp | 12 +++++++++++- 16 files changed, 67 insertions(+), 36 deletions(-) rename src/io/{v3 => }/address.hpp (96%) rename src/io/{v3 => }/errors.hpp (95%) create mode 100644 src/io/simulator/CMakeLists.txt rename src/io/{v3 => simulator}/simulator.hpp (84%) rename src/io/{v3 => simulator}/simulator_config.hpp (90%) rename src/io/{v3 => simulator}/simulator_handle.hpp (98%) rename src/io/{v3 => simulator}/simulator_stats.hpp (90%) rename src/io/{v3 => simulator}/simulator_transport.hpp (93%) rename src/io/{v3 => }/transport.hpp (97%) delete mode 100644 src/io/v3/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 073e5702c..71fbece72 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,7 +17,7 @@ add_subdirectory(query/v2) add_subdirectory(slk) add_subdirectory(rpc) add_subdirectory(auth) -add_subdirectory(io/v3) +add_subdirectory(io/simulator) if (MG_ENTERPRISE) add_subdirectory(audit) diff --git a/src/io/CMakeLists.txt b/src/io/CMakeLists.txt index b6eefc4b5..7ba068c8b 100644 --- a/src/io/CMakeLists.txt +++ b/src/io/CMakeLists.txt @@ -3,7 +3,10 @@ set(io_src_files network/endpoint.cpp network/socket.cpp network/utils.cpp - future.hpp) + future.hpp + address.hpp + errors.hpp + transport.hpp) find_package(fmt REQUIRED) find_package(Threads REQUIRED) diff --git a/src/io/v3/address.hpp b/src/io/address.hpp similarity index 96% rename from src/io/v3/address.hpp rename to src/io/address.hpp index 4e1a80c75..0d1d396ad 100644 --- a/src/io/v3/address.hpp +++ b/src/io/address.hpp @@ -16,6 +16,7 @@ #include #include +namespace memgraph::io { struct Address { // It's important for all participants to have a // unique identifier - IP and port alone are not @@ -46,3 +47,4 @@ struct Address { } } }; +}; // namespace memgraph::io diff --git a/src/io/v3/errors.hpp b/src/io/errors.hpp similarity index 95% rename from src/io/v3/errors.hpp rename to src/io/errors.hpp index 6c5e69fba..7df2171d9 100644 --- a/src/io/v3/errors.hpp +++ b/src/io/errors.hpp @@ -11,6 +11,7 @@ #pragma once +namespace memgraph::io { // Signifies that a retriable operation was unable to // complete after a configured number of retries. struct RetriesExhausted {}; @@ -22,3 +23,4 @@ struct RetriesExhausted {}; // It may be the case that the request was fully processed // but that the response was not received. struct TimedOut {}; +}; // namespace memgraph::io diff --git a/src/io/future.hpp b/src/io/future.hpp index 26ef55326..0f47bb05e 100644 --- a/src/io/future.hpp +++ b/src/io/future.hpp @@ -20,7 +20,7 @@ #include "utils/logging.hpp" -#include "io/v3/errors.hpp" +#include "io/errors.hpp" namespace memgraph::io { diff --git a/src/io/simulator/CMakeLists.txt b/src/io/simulator/CMakeLists.txt new file mode 100644 index 000000000..758659386 --- /dev/null +++ b/src/io/simulator/CMakeLists.txt @@ -0,0 +1,11 @@ +set(io_simulator_sources + simulator.hpp + simulator_handle.hpp + simulator_stats.hpp + simulator_config.hpp) + +find_package(fmt REQUIRED) +find_package(Threads REQUIRED) + +add_library(mg-io-simulator STATIC ${io_simulator_sources}) +target_link_libraries(mg-io-simulator stdc++fs Threads::Threads fmt::fmt mg-utils) diff --git a/src/io/v3/simulator.hpp b/src/io/simulator/simulator.hpp similarity index 84% rename from src/io/v3/simulator.hpp rename to src/io/simulator/simulator.hpp index 51d77e706..4f4bee1f9 100644 --- a/src/io/v3/simulator.hpp +++ b/src/io/simulator/simulator.hpp @@ -13,11 +13,12 @@ #include -#include "io/v3/address.hpp" -#include "io/v3/simulator_config.hpp" -#include "io/v3/simulator_handle.hpp" -#include "io/v3/simulator_transport.hpp" +#include "io/address.hpp" +#include "io/simulator/simulator_config.hpp" +#include "io/simulator/simulator_handle.hpp" +#include "io/simulator/simulator_transport.hpp" +namespace memgraph::io::simulator { class Simulator { std::mt19937 rng_{}; std::shared_ptr simulator_handle_; @@ -40,3 +41,4 @@ class Simulator { SimulatorStats Stats() { return simulator_handle_->Stats(); } }; +}; // namespace memgraph::io::simulator diff --git a/src/io/v3/simulator_config.hpp b/src/io/simulator/simulator_config.hpp similarity index 90% rename from src/io/v3/simulator_config.hpp rename to src/io/simulator/simulator_config.hpp index 49634fef7..2d5cf7342 100644 --- a/src/io/v3/simulator_config.hpp +++ b/src/io/simulator/simulator_config.hpp @@ -11,6 +11,7 @@ #pragma once +namespace memgraph::io::simulator { struct SimulatorConfig { int drop_percent = 0; bool perform_timeouts = false; @@ -19,3 +20,4 @@ struct SimulatorConfig { uint64_t start_time = 0; uint64_t abort_time = ULLONG_MAX; }; +}; // namespace memgraph::io::simulator diff --git a/src/io/v3/simulator_handle.hpp b/src/io/simulator/simulator_handle.hpp similarity index 98% rename from src/io/v3/simulator_handle.hpp rename to src/io/simulator/simulator_handle.hpp index 65603e3b1..b6f1899e2 100644 --- a/src/io/v3/simulator_handle.hpp +++ b/src/io/simulator/simulator_handle.hpp @@ -23,12 +23,13 @@ #include #include -#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" +#include "io/address.hpp" +#include "io/errors.hpp" +#include "io/simulator/simulator_config.hpp" +#include "io/simulator/simulator_stats.hpp" +#include "io/transport.hpp" +namespace memgraph::io::simulator { struct OpaqueMessage { Address from_address; uint64_t request_id; @@ -449,3 +450,4 @@ class SimulatorHandle { return stats_; } }; +}; // namespace memgraph::io::simulator diff --git a/src/io/v3/simulator_stats.hpp b/src/io/simulator/simulator_stats.hpp similarity index 90% rename from src/io/v3/simulator_stats.hpp rename to src/io/simulator/simulator_stats.hpp index cf8b068f0..1f016c2fb 100644 --- a/src/io/v3/simulator_stats.hpp +++ b/src/io/simulator/simulator_stats.hpp @@ -11,6 +11,7 @@ #pragma once +namespace memgraph::io::simulator { struct SimulatorStats { uint64_t total_messages = 0; uint64_t dropped_messages = 0; @@ -19,3 +20,4 @@ struct SimulatorStats { uint64_t total_responses = 0; uint64_t simulator_ticks = 0; }; +}; // namespace memgraph::io::simulator diff --git a/src/io/v3/simulator_transport.hpp b/src/io/simulator/simulator_transport.hpp similarity index 93% rename from src/io/v3/simulator_transport.hpp rename to src/io/simulator/simulator_transport.hpp index ac21ccaeb..38af6547b 100644 --- a/src/io/v3/simulator_transport.hpp +++ b/src/io/simulator/simulator_transport.hpp @@ -14,9 +14,10 @@ #include #include -#include "io/v3/address.hpp" -#include "io/v3/simulator_handle.hpp" +#include "io/address.hpp" +#include "io/simulator/simulator_handle.hpp" +namespace memgraph::io::simulator { class SimulatorTransport { std::shared_ptr simulator_handle_; Address address_; @@ -58,3 +59,4 @@ class SimulatorTransport { return distrib(rng_); } }; +}; // namespace memgraph::io::simulator diff --git a/src/io/v3/transport.hpp b/src/io/transport.hpp similarity index 97% rename from src/io/v3/transport.hpp rename to src/io/transport.hpp index 67d70d2f5..d3e045cb2 100644 --- a/src/io/v3/transport.hpp +++ b/src/io/transport.hpp @@ -17,15 +17,13 @@ #include "utils/result.hpp" +#include "io/address.hpp" +#include "io/errors.hpp" #include "io/future.hpp" -#include "io/v3/address.hpp" -#include "io/v3/errors.hpp" using memgraph::utils::BasicResult; -template -class Io; - +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. @@ -129,3 +127,4 @@ class Io { Address GetAddress() { return address_; } }; +}; // namespace memgraph::io diff --git a/src/io/v3/CMakeLists.txt b/src/io/v3/CMakeLists.txt deleted file mode 100644 index 9f24ef0e2..000000000 --- a/src/io/v3/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -set(io_v3_sources - address.hpp - errors.hpp - transport.hpp - simulator.hpp - simulator_handle.hpp - simulator_stats.hpp - simulator_config.hpp) - -find_package(fmt REQUIRED) -find_package(Threads REQUIRED) - -add_library(mg-io-v3 STATIC ${io_v3_sources}) -target_link_libraries(mg-io-v3 stdc++fs Threads::Threads fmt::fmt mg-utils) diff --git a/tests/simulation/CMakeLists.txt b/tests/simulation/CMakeLists.txt index 78abde792..1463d1a32 100644 --- a/tests/simulation/CMakeLists.txt +++ b/tests/simulation/CMakeLists.txt @@ -13,7 +13,7 @@ function(add_simulation_test test_cpp san) # used to help create two targets of the same name even though CMake # requires unique logical target names set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${exec_name}) - target_link_libraries(${target_name} gtest gmock gtest_main mg-utils mg-io-v3) + target_link_libraries(${target_name} gtest gmock gtest_main mg-utils mg-io mg-io-simulator) # sanitize target_compile_options(${target_name} PRIVATE -fsanitize=${san}) diff --git a/tests/simulation/basic_request.cpp b/tests/simulation/basic_request.cpp index 560fe126b..ecf8fbe1d 100644 --- a/tests/simulation/basic_request.cpp +++ b/tests/simulation/basic_request.cpp @@ -11,7 +11,15 @@ #include -#include "io/v3/simulator.hpp" +#include "io/simulator/simulator.hpp" + +using memgraph::io::Address; +using memgraph::io::Io; +using memgraph::io::ResponseFuture; +using memgraph::io::ResponseResult; +using memgraph::io::simulator::Simulator; +using memgraph::io::simulator::SimulatorConfig; +using memgraph::io::simulator::SimulatorTransport; struct CounterRequest { uint64_t proposal; diff --git a/tests/simulation/raft.cpp b/tests/simulation/raft.cpp index 438419b93..5733bc22f 100644 --- a/tests/simulation/raft.cpp +++ b/tests/simulation/raft.cpp @@ -23,7 +23,17 @@ #include #include -#include "io/v3/simulator.hpp" +#include "io/simulator/simulator.hpp" + +using memgraph::io::Address; +using memgraph::io::Io; +using memgraph::io::ResponseEnvelope; +using memgraph::io::ResponseFuture; +using memgraph::io::ResponseResult; +using memgraph::io::simulator::Simulator; +using memgraph::io::simulator::SimulatorConfig; +using memgraph::io::simulator::SimulatorStats; +using memgraph::io::simulator::SimulatorTransport; using Op = std::vector; using Term = uint64_t;