From 6d978571027026c619ec6ccbbbc5f94de1a49e7a Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 24 Jan 2023 11:50:36 +0100 Subject: [PATCH 1/3] Upgrade code base to C++20 --- CMakeLists.txt | 4 ++-- examples/cxx/common.cpp | 2 +- src/common/logger/logger.hpp | 30 ++++++++++++++++-------------- src/common/net/server.cpp | 30 ++++++++++++------------------ src/lib/detail/impl.cpp | 1 + src/scord/rpc_handlers.cpp | 2 +- 6 files changed, 33 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b5c351fc..118c19e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,7 +84,7 @@ set(CMAKE_SHARED_LINKER_FLAGS_ASAN set_property(GLOBAL APPEND PROPERTY DEBUG_CONFIGURATIONS Debug) set_property(GLOBAL APPEND PROPERTY DEBUG_CONFIGURATIONS ASan) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) message(STATUS "[${PROJECT_NAME}] Project version: ${PROJECT_VERSION}") @@ -220,7 +220,7 @@ message(STATUS "[${PROJECT_NAME}] Downloading and building file_options") FetchContent_Declare( file_options GIT_REPOSITORY https://storage.bsc.es/gitlab/utils/file_options - GIT_TAG 50071ff78d0974b2f1178f27ce1a08d22e5e8fa2 # v0.1.0-pre + GIT_TAG bdb4f7f7f2dd731815241fc41afe6373df8f732a # v0.1.0-pre GIT_SHALLOW ON GIT_PROGRESS ON ) diff --git a/examples/cxx/common.cpp b/examples/cxx/common.cpp index be3585d9..31c57c67 100644 --- a/examples/cxx/common.cpp +++ b/examples/cxx/common.cpp @@ -16,7 +16,7 @@ prepare_datasets(const std::string& pattern, size_t n) { std::vector datasets; datasets.reserve(n); for(size_t i = 0; i < n; ++i) { - datasets.emplace_back(fmt::format(pattern, i)); + datasets.emplace_back(fmt::format(fmt::runtime(pattern), i)); } return datasets; diff --git a/src/common/logger/logger.hpp b/src/common/logger/logger.hpp index 7aa530cb..1dfa3d23 100644 --- a/src/common/logger/logger.hpp +++ b/src/common/logger/logger.hpp @@ -161,26 +161,26 @@ public: template inline void - info(const char* fmt, const Args&... args) { - m_internal_logger->info(fmt, args...); + info(fmt::format_string fmt, Args&&... args) { + m_internal_logger->info(fmt, std::forward(args)...); } template inline void - debug(const char* fmt, const Args&... args) { - m_internal_logger->debug(fmt, args...); + debug(fmt::format_string fmt, Args&&... args) { + m_internal_logger->debug(fmt, std::forward(args)...); } template inline void - warn(const char* fmt, const Args&... args) { - m_internal_logger->warn(fmt, args...); + warn(fmt::format_string fmt, Args&&... args) { + m_internal_logger->warn(fmt, std::forward(args)...); } template inline void - error(const char* fmt, const Args&... args) { - m_internal_logger->error(fmt, args...); + error(fmt::format_string fmt, Args&&... args) { + m_internal_logger->error(fmt, std::forward(args)...); } static inline std::string @@ -194,25 +194,27 @@ public: template inline void - error_errno(const char* fmt, const Args&... args) { + error_errno(fmt::format_string fmt, Args&&... args) { const int saved_errno = errno; constexpr const std::size_t MAX_ERROR_MSG = 128; - std::array errstr; + std::array errstr; // NOLINT - std::string str_fmt(fmt); + fmt::string_view sv{fmt}; + std::string str_fmt{sv.begin(), sv.end()}; str_fmt += ": {}"; char* msg = strerror_r(saved_errno, errstr.data(), MAX_ERROR_MSG); - m_internal_logger->error(str_fmt.c_str(), args..., msg); + m_internal_logger->error(fmt::runtime(str_fmt), + std::forward(args)..., msg); } template inline void - critical(const char* fmt, const Args&... args) { - m_internal_logger->critical(fmt, args...); + critical(fmt::format_string fmt, Args&&... args) { + m_internal_logger->critical(fmt, std::forward(args)...); } template diff --git a/src/common/net/server.cpp b/src/common/net/server.cpp index 22174f21..99293371 100644 --- a/src/common/net/server.cpp +++ b/src/common/net/server.cpp @@ -296,15 +296,12 @@ server::check_configuration() { void server::print_greeting() { - const char greeting[] = "Starting {} daemon (pid {})"; - const auto gsep = - std::string(sizeof(greeting) - 4 + m_settings->progname().size() + - std::to_string(getpid()).size(), - '='); - - LOGGER_INFO("{}", gsep); - LOGGER_INFO(greeting, m_settings->progname(), getpid()); - LOGGER_INFO("{}", gsep); + const auto greeting = fmt::format("Starting {} daemon (pid {})", + m_settings->progname(), getpid()); + + LOGGER_INFO("{:=>{}}", "", greeting.size()); + LOGGER_INFO(greeting); + LOGGER_INFO("{:=>{}}", "", greeting.size()); } void @@ -332,15 +329,12 @@ server::print_configuration() { void server::print_farewell() { - const char farewell[] = "Stopping {} daemon (pid {})"; - const auto fsep = - std::string(sizeof(farewell) - 4 + m_settings->progname().size() + - std::to_string(getpid()).size(), - '='); - - LOGGER_INFO("{}", fsep); - LOGGER_INFO(farewell, m_settings->progname(), getpid()); - LOGGER_INFO("{}", fsep); + const auto farewell = fmt::format("Stopping {} daemon (pid {})", + m_settings->progname(), getpid()); + + LOGGER_INFO("{:=>{}}", "", farewell.size()); + LOGGER_INFO(farewell); + LOGGER_INFO("{:=>{}}", "", farewell.size()); } int diff --git a/src/lib/detail/impl.cpp b/src/lib/detail/impl.cpp index 962f1f92..8282d7a9 100644 --- a/src/lib/detail/impl.cpp +++ b/src/lib/detail/impl.cpp @@ -386,6 +386,7 @@ deploy_adhoc_storage(const server& srv, const adhoc_storage& adhoc_storage) { LOGGER_INFO("rpc id: {} name: {} from: {} <= " "body: {{retval: {}}}] [op_id: {}]", rpc_id, std::quoted("ADM_"s + __FUNCTION__), + std::quoted(rpc_client.self_address()), admire::error_code::success, out.op_id); return admire::error_code::success; diff --git a/src/scord/rpc_handlers.cpp b/src/scord/rpc_handlers.cpp index 2c530742..cfffce87 100644 --- a/src/scord/rpc_handlers.cpp +++ b/src/scord/rpc_handlers.cpp @@ -1081,7 +1081,7 @@ ADM_adhoc_access(hg_handle_t h) { if(in.access == nullptr) { LOGGER_ERROR("ADM_adhoc_access(): invalid access (nullptr)"); } else { - LOGGER_INFO("ADM_adhoc_access({}, {})", in.access); + LOGGER_INFO("ADM_adhoc_access({})", in.access); if((acc == "write-only") || (acc == "read-only") || (acc == "read-write")) { -- GitLab From bf2fe14049941db4e27cddfb321f95b61cb49321 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 24 Jan 2023 12:06:24 +0100 Subject: [PATCH 2/3] Fix server returning invalid op_id in deploy_adhoc_storage() --- src/lib/detail/impl.cpp | 2 +- src/scord/rpc_handlers.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/detail/impl.cpp b/src/lib/detail/impl.cpp index 8282d7a9..6129e7f9 100644 --- a/src/lib/detail/impl.cpp +++ b/src/lib/detail/impl.cpp @@ -384,7 +384,7 @@ deploy_adhoc_storage(const server& srv, const adhoc_storage& adhoc_storage) { } LOGGER_INFO("rpc id: {} name: {} from: {} <= " - "body: {{retval: {}}}] [op_id: {}]", + "body: {{retval: {}}} [op_id: {}]", rpc_id, std::quoted("ADM_"s + __FUNCTION__), std::quoted(rpc_client.self_address()), admire::error_code::success, out.op_id); diff --git a/src/scord/rpc_handlers.cpp b/src/scord/rpc_handlers.cpp index cfffce87..190af867 100644 --- a/src/scord/rpc_handlers.cpp +++ b/src/scord/rpc_handlers.cpp @@ -528,6 +528,7 @@ ADM_deploy_adhoc_storage(hg_handle_t h) { std::quoted(get_address(h)), ec); } + out.op_id = rpc_id; out.retval = ec; LOGGER_INFO("rpc id: {} name: {} to: {} <= " -- GitLab From fe1abb5ed58b25a3cf453d1f1fbe06c558694959 Mon Sep 17 00:00:00 2001 From: Alberto Miranda Date: Tue, 24 Jan 2023 12:15:36 +0100 Subject: [PATCH 3/3] Fix inconsistent log output for `deploy_adhoc_storage` --- src/lib/detail/impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/detail/impl.cpp b/src/lib/detail/impl.cpp index 6129e7f9..bad2ab03 100644 --- a/src/lib/detail/impl.cpp +++ b/src/lib/detail/impl.cpp @@ -366,9 +366,9 @@ deploy_adhoc_storage(const server& srv, const adhoc_storage& adhoc_storage) { auto endp = rpc_client.lookup(srv.address()); LOGGER_INFO("rpc id: {} name: {} from: {} => " - "body: {{adhoc_storage: {}}}", + "body: {{adhoc_id: {}}}", rpc_id, std::quoted("ADM_"s + __FUNCTION__), - std::quoted(rpc_client.self_address()), adhoc_storage); + std::quoted(rpc_client.self_address()), adhoc_storage.id()); ADM_deploy_adhoc_storage_in_t in{adhoc_storage.id()}; ADM_deploy_adhoc_storage_out_t out; -- GitLab