diff --git a/CMakeLists.txt b/CMakeLists.txt index 85e2b085c..028406447 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -189,7 +189,7 @@ add_custom_target(clean_all # is easier debugging of compilation and linker flags. set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) # c99-designator is disabled because of required mixture of designated and # non-designated initializers in Python Query Module code (`py_module.cpp`). @@ -211,8 +211,13 @@ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO # ** Static linking is allowed only for executables! ** set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") -# Use lld linker to speedup build -add_link_options(-fuse-ld=lld) # TODO: use mold linker +# Use lld linker to speedup build and use less memory. +add_link_options(-fuse-ld=lld) +# NOTE: Moving to latest Clang (probably starting from 15), lld stopped to work +# without explicit link_directories call. +string(REPLACE ":" " " LD_LIBS $ENV{LD_LIBRARY_PATH}) +separate_arguments(LD_LIBS) +link_directories(${LD_LIBS}) # release flags set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") diff --git a/include/_mgp.hpp b/include/_mgp.hpp index 4f6797739..8b67bc36a 100644 --- a/include/_mgp.hpp +++ b/include/_mgp.hpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -283,7 +283,7 @@ inline mgp_list *list_all_unique_constraints(mgp_graph *graph, mgp_memory *memor } // mgp_graph - + inline bool graph_is_transactional(mgp_graph *graph) { return MgInvoke(mgp_graph_is_transactional, graph); } inline bool graph_is_mutable(mgp_graph *graph) { return MgInvoke(mgp_graph_is_mutable, graph); } diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index fd6823ee5..7d568d548 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -16,7 +16,7 @@ set(GFLAGS_NOTHREADS OFF) # NOTE: config/generate.py depends on the gflags help XML format. find_package(gflags REQUIRED) -find_package(fmt 8.0.1) +find_package(fmt 8.0.1 REQUIRED) find_package(ZLIB 1.2.11 REQUIRED) set(LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/libs/librdtsc.patch b/libs/librdtsc.patch index 70a98c94a..c6022adac 100644 --- a/libs/librdtsc.patch +++ b/libs/librdtsc.patch @@ -5,7 +5,7 @@ index ee9b58c..31359a9 100644 @@ -48,7 +48,7 @@ option(LIBRDTSC_USE_PMU "Enables PMU usage on ARM platforms" OFF) # | Library Build and Install Properties | # +--------------------------------------------------------+ - + -add_library(rdtsc SHARED +add_library(rdtsc src/cycles.c @@ -14,7 +14,7 @@ index ee9b58c..31359a9 100644 @@ -72,15 +72,6 @@ target_include_directories(rdtsc PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ) - + -# Install directory changes depending on build mode -if (CMAKE_BUILD_TYPE MATCHES "^[Dd]ebug") - # During debug, the library will be installed into a local directory @@ -27,3 +27,15 @@ index ee9b58c..31359a9 100644 # Specifying what to export when installing (GNUInstallDirs required) install(TARGETS rdtsc EXPORT librstsc-config +diff --git a/include/librdtsc/common_timer.h b/include/librdtsc/common_timer.h +index a6922d8..080dc77 100644 +--- a/include/librdtsc/common_timer.h ++++ b/include/librdtsc/common_timer.h +@@ -2,6 +2,7 @@ + #define LIBRDTSC_COMMON_TIMER_H + + #include ++#include + + extern uint64_t rdtsc_get_tsc_freq_arch(); + extern uint64_t rdtsc_get_tsc_freq(); diff --git a/libs/rocksdb.patch b/libs/rocksdb.patch deleted file mode 100644 index 297e509fb..000000000 --- a/libs/rocksdb.patch +++ /dev/null @@ -1,21 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 6761929..6a369af 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -220,6 +220,7 @@ else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -momit-leaf-frame-pointer") - endif() - endif() -+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-copy -Wno-unused-but-set-variable") - endif() - - include(CheckCCompilerFlag) -@@ -997,7 +998,7 @@ if(NOT WIN32 OR ROCKSDB_INSTALL_ON_WINDOWS) - - if(ROCKSDB_BUILD_SHARED) - install( -- TARGETS ${ROCKSDB_SHARED_LIB} -+ TARGETS ${ROCKSDB_SHARED_LIB} OPTIONAL - EXPORT RocksDBTargets - COMPONENT runtime - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" diff --git a/libs/setup.sh b/libs/setup.sh index ebf20e830..9c2a38c47 100755 --- a/libs/setup.sh +++ b/libs/setup.sh @@ -168,12 +168,11 @@ pushd antlr4 git apply ../antlr4.10.1.patch popd -# cppitertools v2.0 2019-12-23 -cppitertools_ref="cb3635456bdb531121b82b4d2e3afc7ae1f56d47" +cppitertools_ref="v2.1" # 2021-01-15 repo_clone_try_double "${primary_urls[cppitertools]}" "${secondary_urls[cppitertools]}" "cppitertools" "$cppitertools_ref" # rapidcheck -rapidcheck_tag="7bc7d302191a4f3d0bf005692677126136e02f60" # (2020-05-04) +rapidcheck_tag="1c91f40e64d87869250cfb610376c629307bf77d" # (2023-08-15) repo_clone_try_double "${primary_urls[rapidcheck]}" "${secondary_urls[rapidcheck]}" "rapidcheck" "$rapidcheck_tag" # google benchmark @@ -221,7 +220,7 @@ repo_clone_try_double "${primary_urls[pymgclient]}" "${secondary_urls[pymgclient mgconsole_tag="v1.4.0" # (2023-05-21) repo_clone_try_double "${primary_urls[mgconsole]}" "${secondary_urls[mgconsole]}" "mgconsole" "$mgconsole_tag" true -spdlog_tag="v1.9.2" # (2021-08-12) +spdlog_tag="v1.12.0" # (2022-11-02) repo_clone_try_double "${primary_urls[spdlog]}" "${secondary_urls[spdlog]}" "spdlog" "$spdlog_tag" true # librdkafka diff --git a/src/auth/crypto.hpp b/src/auth/crypto.hpp index c5dfc1c05..a0458a067 100644 --- a/src/auth/crypto.hpp +++ b/src/auth/crypto.hpp @@ -8,10 +8,12 @@ #pragma once -#include +#include #include #include +#include + namespace memgraph::auth { /// Need to be stable, auth durability depends on this enum class PasswordHashAlgorithm : uint8_t { BCRYPT = 0, SHA256 = 1, SHA256_MULTIPLE = 2 }; diff --git a/src/communication/bolt/client.cpp b/src/communication/bolt/client.cpp index 39cd24730..29f7d237a 100644 --- a/src/communication/bolt/client.cpp +++ b/src/communication/bolt/client.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -15,6 +15,9 @@ #include "communication/bolt/v1/value.hpp" #include "utils/logging.hpp" +#include "communication/bolt/v1/fmt.hpp" +#include "io/network/fmt.hpp" + namespace { constexpr uint8_t kBoltV43Version[4] = {0x00, 0x00, 0x03, 0x04}; constexpr uint8_t kEmptyBoltVersion[4] = {0x00, 0x00, 0x00, 0x00}; diff --git a/src/communication/bolt/v1/fmt.hpp b/src/communication/bolt/v1/fmt.hpp new file mode 100644 index 000000000..0a6808643 --- /dev/null +++ b/src/communication/bolt/v1/fmt.hpp @@ -0,0 +1,27 @@ +// Copyright 2024 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#if FMT_VERSION > 90000 +#include + +#include "communication/bolt/v1/value.hpp" + +template <> +class fmt::formatter : public fmt::ostream_formatter {}; + +template <> +class fmt::formatter> : public fmt::ostream_formatter {}; + +template <> +class fmt::formatter> : public fmt::ostream_formatter {}; +#endif diff --git a/src/communication/fmt.hpp b/src/communication/fmt.hpp new file mode 100644 index 000000000..ab65066b2 --- /dev/null +++ b/src/communication/fmt.hpp @@ -0,0 +1,20 @@ +// Copyright 2024 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#if FMT_VERSION > 90000 +#include +#include + +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/src/communication/http/listener.hpp b/src/communication/http/listener.hpp index fac4cfaf3..aa3e7e2f5 100644 --- a/src/communication/http/listener.hpp +++ b/src/communication/http/listener.hpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -21,6 +21,7 @@ #include #include "communication/context.hpp" +#include "communication/fmt.hpp" #include "communication/http/session.hpp" #include "utils/spin_lock.hpp" #include "utils/synchronized.hpp" @@ -82,7 +83,7 @@ class Listener final : public std::enable_shared_from_this #include "communication/context.hpp" +#include "communication/fmt.hpp" #include "communication/init.hpp" #include "communication/v2/listener.hpp" #include "communication/v2/pool.hpp" @@ -129,7 +130,7 @@ bool Server::Start() { listener_->Start(); spdlog::info("{} server is fully armed and operational", service_name_); - spdlog::info("{} listening on {}", service_name_, endpoint_.address()); + spdlog::info("{} listening on {}", service_name_, endpoint_); context_thread_pool_.Run(); return true; diff --git a/src/communication/v2/session.hpp b/src/communication/v2/session.hpp index b54607729..0b23d9301 100644 --- a/src/communication/v2/session.hpp +++ b/src/communication/v2/session.hpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -47,6 +47,7 @@ #include "communication/buffer.hpp" #include "communication/context.hpp" #include "communication/exceptions.hpp" +#include "communication/fmt.hpp" #include "dbms/global.hpp" #include "utils/event_counter.hpp" #include "utils/logging.hpp" @@ -212,14 +213,11 @@ class WebsocketSession : public std::enable_shared_from_this 90000 +#include +#include + +#include +#include "utils/logging.hpp" + +inline std::string ToString(const nuraft::cmd_result_code &code) { + switch (code) { + case nuraft::cmd_result_code::OK: + return "OK"; + case nuraft::cmd_result_code::FAILED: + return "FAILED"; + case nuraft::cmd_result_code::RESULT_NOT_EXIST_YET: + return "RESULT_NOT_EXIST_YET"; + case nuraft::cmd_result_code::TERM_MISMATCH: + return "TERM_MISMATCH"; + case nuraft::cmd_result_code::SERVER_IS_LEAVING: + return "SERVER_IS_LEAVING"; + case nuraft::cmd_result_code::CANNOT_REMOVE_LEADER: + return "CANNOT_REMOVE_LEADER"; + case nuraft::cmd_result_code::SERVER_NOT_FOUND: + return "SERVER_NOT_FOUND"; + case nuraft::cmd_result_code::SERVER_IS_JOINING: + return "SERVER_IS_JOINING"; + case nuraft::cmd_result_code::CONFIG_CHANGING: + return "CONFIG_CHANGING"; + case nuraft::cmd_result_code::SERVER_ALREADY_EXISTS: + return "SERVER_ALREADY_EXISTS"; + case nuraft::cmd_result_code::BAD_REQUEST: + return "BAD_REQUEST"; + case nuraft::cmd_result_code::NOT_LEADER: + return "NOT_LEADER"; + case nuraft::cmd_result_code::TIMEOUT: + return "TIMEOUT"; + case nuraft::cmd_result_code::CANCELLED: + return "CANCELLED"; + } + LOG_FATAL("ToString of a nuraft::cmd_result_code -> check missing switch case"); +} +inline std::ostream &operator<<(std::ostream &os, const nuraft::cmd_result_code &code) { + os << ToString(code); + return os; +} +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/src/dbms/inmemory/replication_handlers.cpp b/src/dbms/inmemory/replication_handlers.cpp index b7b2146f4..3fc174d3c 100644 --- a/src/dbms/inmemory/replication_handlers.cpp +++ b/src/dbms/inmemory/replication_handlers.cpp @@ -19,6 +19,7 @@ #include "storage/v2/durability/durability.hpp" #include "storage/v2/durability/snapshot.hpp" #include "storage/v2/durability/version.hpp" +#include "storage/v2/fmt.hpp" #include "storage/v2/indices/label_index_stats.hpp" #include "storage/v2/inmemory/storage.hpp" #include "storage/v2/inmemory/unique_constraints.hpp" diff --git a/src/dbms/utils.hpp b/src/dbms/utils.hpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/distributed/include/distributed/lamport_clock.hpp b/src/distributed/include/distributed/lamport_clock.hpp index f3e91e47a..2bbc0b447 100644 --- a/src/distributed/include/distributed/lamport_clock.hpp +++ b/src/distributed/include/distributed/lamport_clock.hpp @@ -10,6 +10,7 @@ // licenses/APL.txt. #pragma once +#include #include #include #include diff --git a/src/integrations/kafka/consumer.cpp b/src/integrations/kafka/consumer.cpp index 9889fe46b..c5604e85a 100644 --- a/src/integrations/kafka/consumer.cpp +++ b/src/integrations/kafka/consumer.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -22,6 +22,7 @@ #include "integrations/constants.hpp" #include "integrations/kafka/exceptions.hpp" +#include "integrations/kafka/fmt.hpp" #include "utils/exceptions.hpp" #include "utils/logging.hpp" #include "utils/on_scope_exit.hpp" diff --git a/src/integrations/kafka/fmt.hpp b/src/integrations/kafka/fmt.hpp new file mode 100644 index 000000000..f85f74b49 --- /dev/null +++ b/src/integrations/kafka/fmt.hpp @@ -0,0 +1,25 @@ +// Copyright 2024 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#if FMT_VERSION > 90000 +#include + +#include + +inline std::ostream &operator<<(std::ostream &os, const RdKafka::ErrorCode &code) { + os << RdKafka::err2str(code); + return os; +} +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/src/integrations/pulsar/consumer.cpp b/src/integrations/pulsar/consumer.cpp index f004cf6dc..1cfd8159c 100644 --- a/src/integrations/pulsar/consumer.cpp +++ b/src/integrations/pulsar/consumer.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -15,12 +15,12 @@ #include #include -#include #include #include #include "integrations/constants.hpp" #include "integrations/pulsar/exceptions.hpp" +#include "integrations/pulsar/fmt.hpp" #include "utils/concepts.hpp" #include "utils/logging.hpp" #include "utils/on_scope_exit.hpp" diff --git a/src/integrations/pulsar/fmt.hpp b/src/integrations/pulsar/fmt.hpp new file mode 100644 index 000000000..7585d87c7 --- /dev/null +++ b/src/integrations/pulsar/fmt.hpp @@ -0,0 +1,21 @@ +// Copyright 2024 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#if FMT_VERSION > 90000 +#include + +#include "integrations/pulsar/consumer.hpp" + +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/src/io/network/fmt.hpp b/src/io/network/fmt.hpp new file mode 100644 index 000000000..014de5353 --- /dev/null +++ b/src/io/network/fmt.hpp @@ -0,0 +1,21 @@ +// Copyright 2024 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#if FMT_VERSION > 90000 +#include + +#include "io/network/endpoint.hpp" + +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/src/io/network/stream_buffer.hpp b/src/io/network/stream_buffer.hpp index 5ed7fc69e..5a9f01bf7 100644 --- a/src/io/network/stream_buffer.hpp +++ b/src/io/network/stream_buffer.hpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -11,6 +11,7 @@ #pragma once +#include #include namespace memgraph::io::network { diff --git a/src/kvstore/kvstore.hpp b/src/kvstore/kvstore.hpp index b9675d75b..84aa27009 100644 --- a/src/kvstore/kvstore.hpp +++ b/src/kvstore/kvstore.hpp @@ -160,13 +160,14 @@ class KVStore final { * and behaves as if all of those pairs are stored in a single iterable * collection of std::pair. */ - class iterator final : public std::iterator, // value_type - long, // difference_type - const std::pair *, // pointer - const std::pair & // reference - > { + class iterator final { public: + using iterator_concept [[maybe_unused]] = std::input_iterator_tag; + using value_type = std::pair; + using difference_type = long; + using pointer = const std::pair *; + using reference = const std::pair &; + explicit iterator(const KVStore *kvstore, const std::string &prefix = "", bool at_end = false); iterator(const iterator &other) = delete; diff --git a/src/mg_import_csv.cpp b/src/mg_import_csv.cpp index cbfb905aa..2d77c2db2 100644 --- a/src/mg_import_csv.cpp +++ b/src/mg_import_csv.cpp @@ -139,6 +139,11 @@ struct NodeId { std::string id_space; }; +#if FMT_VERSION > 90000 +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif + bool operator==(const NodeId &a, const NodeId &b) { return a.id == b.id && a.id_space == b.id_space; } std::ostream &operator<<(std::ostream &stream, const NodeId &node_id) { diff --git a/src/py/py.hpp b/src/py/py.hpp index 14d54d657..7b25b595e 100644 --- a/src/py/py.hpp +++ b/src/py/py.hpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -274,3 +274,8 @@ inline void RestoreError(ExceptionInfo exc_info) { } } // namespace memgraph::py + +#if FMT_VERSION > 90000 +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/src/query/common.hpp b/src/query/common.hpp index 054714164..36ba07791 100644 --- a/src/query/common.hpp +++ b/src/query/common.hpp @@ -19,6 +19,7 @@ #include "query/db_accessor.hpp" #include "query/exceptions.hpp" +#include "query/fmt.hpp" #include "query/frontend/ast/ast.hpp" #include "query/frontend/semantic/symbol.hpp" #include "query/typed_value.hpp" diff --git a/src/query/fmt.hpp b/src/query/fmt.hpp new file mode 100644 index 000000000..50a915715 --- /dev/null +++ b/src/query/fmt.hpp @@ -0,0 +1,23 @@ +// Copyright 2024 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#if FMT_VERSION > 90000 +#include + +#include "query/typed_value.hpp" + +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/src/query/plan/preprocess.cpp b/src/query/plan/preprocess.cpp index cf8ad9c97..c3bfdf462 100644 --- a/src/query/plan/preprocess.cpp +++ b/src/query/plan/preprocess.cpp @@ -313,7 +313,7 @@ void Filters::CollectPatternFilters(Pattern &pattern, SymbolTable &symbol_table, auto *property_lookup = storage.Create(atom->filter_lambda_.inner_edge, prop_pair.first); auto *prop_equal = storage.Create(property_lookup, prop_pair.second); // Currently, variable expand has no gains if we set PropertyFilter. - all_filters_.emplace_back(FilterInfo{FilterInfo::Type::Generic, prop_equal, collector.symbols_}); + all_filters_.emplace_back(FilterInfo::Type::Generic, prop_equal, collector.symbols_); } { collector.symbols_.clear(); @@ -328,9 +328,9 @@ void Filters::CollectPatternFilters(Pattern &pattern, SymbolTable &symbol_table, auto *prop_equal = storage.Create(property_lookup, prop_pair.second); // Currently, variable expand has no gains if we set PropertyFilter. all_filters_.emplace_back( - FilterInfo{FilterInfo::Type::Generic, - storage.Create(identifier, atom->identifier_, storage.Create(prop_equal)), - collector.symbols_}); + FilterInfo::Type::Generic, + storage.Create(identifier, atom->identifier_, storage.Create(prop_equal)), + collector.symbols_); } } return; @@ -639,6 +639,12 @@ void AddMatching(const Match &match, SymbolTable &symbol_table, AstStorage &stor } } +PatternFilterVisitor::PatternFilterVisitor(SymbolTable &symbol_table, AstStorage &storage) + : symbol_table_(symbol_table), storage_(storage) {} +PatternFilterVisitor::PatternFilterVisitor(const PatternFilterVisitor &) = default; +PatternFilterVisitor::PatternFilterVisitor(PatternFilterVisitor &&) noexcept = default; +PatternFilterVisitor::~PatternFilterVisitor() = default; + void PatternFilterVisitor::Visit(Exists &op) { std::vector patterns; patterns.push_back(op.pattern_); @@ -652,6 +658,8 @@ void PatternFilterVisitor::Visit(Exists &op) { matchings_.push_back(std::move(filter_matching)); } +std::vector PatternFilterVisitor::getMatchings() { return matchings_; } + static void ParseForeach(query::Foreach &foreach, SingleQueryPart &query_part, AstStorage &storage, SymbolTable &symbol_table) { for (auto *clause : foreach.clauses_) { @@ -723,4 +731,18 @@ QueryParts CollectQueryParts(SymbolTable &symbol_table, AstStorage &storage, Cyp return QueryParts{query_parts, distinct}; } +FilterInfo::FilterInfo(Type type, Expression *expression, std::unordered_set used_symbols, + std::optional property_filter, std::optional id_filter) + : type(type), + expression(expression), + used_symbols(std::move(used_symbols)), + property_filter(std::move(property_filter)), + id_filter(std::move(id_filter)), + matchings({}) {} +FilterInfo::FilterInfo(const FilterInfo &) = default; +FilterInfo &FilterInfo::operator=(const FilterInfo &) = default; +FilterInfo::FilterInfo(FilterInfo &&) noexcept = default; +FilterInfo &FilterInfo::operator=(FilterInfo &&) noexcept = default; +FilterInfo::~FilterInfo() = default; + } // namespace memgraph::query::plan diff --git a/src/query/plan/preprocess.hpp b/src/query/plan/preprocess.hpp index 2b53fb7b0..01b10ebaf 100644 --- a/src/query/plan/preprocess.hpp +++ b/src/query/plan/preprocess.hpp @@ -19,6 +19,7 @@ #include #include "query/frontend/ast/ast.hpp" +#include "query/frontend/ast/ast_visitor.hpp" #include "query/frontend/semantic/symbol_table.hpp" namespace memgraph::query::plan { @@ -159,8 +160,12 @@ enum class PatternFilterType { EXISTS }; /// Collects matchings from filters that include patterns class PatternFilterVisitor : public ExpressionVisitor { public: - explicit PatternFilterVisitor(SymbolTable &symbol_table, AstStorage &storage) - : symbol_table_(symbol_table), storage_(storage) {} + explicit PatternFilterVisitor(SymbolTable &symbol_table, AstStorage &storage); + PatternFilterVisitor(const PatternFilterVisitor &); + PatternFilterVisitor &operator=(const PatternFilterVisitor &) = delete; + PatternFilterVisitor(PatternFilterVisitor &&) noexcept; + PatternFilterVisitor &operator=(PatternFilterVisitor &&) noexcept = delete; + ~PatternFilterVisitor() override; using ExpressionVisitor::Visit; @@ -232,7 +237,7 @@ class PatternFilterVisitor : public ExpressionVisitor { void Visit(RegexMatch &op) override{}; void Visit(PatternComprehension &op) override{}; - std::vector getMatchings() { return matchings_; } + std::vector getMatchings(); SymbolTable &symbol_table_; AstStorage &storage_; @@ -298,9 +303,23 @@ struct FilterInfo { /// elements. enum class Type { Generic, Label, Property, Id, Pattern }; - Type type; + // FilterInfo is tricky because FilterMatching is not yet defined: + // * if no declared constructor -> FilterInfo is std::__is_complete_or_unbounded + // * if any user-declared constructor -> non-aggregate type -> no designated initializers are possible + // * IMPORTANT: Matchings will always be initialized to an empty container. + explicit FilterInfo(Type type = Type::Generic, Expression *expression = nullptr, + std::unordered_set used_symbols = {}, std::optional property_filter = {}, + std::optional id_filter = {}); + // All other constructors are also defined in the cpp file because this struct is incomplete here. + FilterInfo(const FilterInfo &); + FilterInfo &operator=(const FilterInfo &); + FilterInfo(FilterInfo &&) noexcept; + FilterInfo &operator=(FilterInfo &&) noexcept; + ~FilterInfo(); + + Type type{Type::Generic}; /// The original filter expression which must be satisfied. - Expression *expression; + Expression *expression{nullptr}; /// Set of used symbols by the filter @c expression. std::unordered_set used_symbols{}; /// Labels for Type::Label filtering. @@ -310,7 +329,8 @@ struct FilterInfo { /// Information for Type::Id filtering. std::optional id_filter{}; /// Matchings for filters that include patterns - std::vector matchings{}; + /// NOTE: The vector is not defined here because FilterMatching is forward declared above. + std::vector matchings; }; /// Stores information on filters used inside the @c Matching of a @c QueryPart. @@ -329,34 +349,15 @@ class Filters final { auto empty() const { return all_filters_.empty(); } - auto erase(iterator pos) { return all_filters_.erase(pos); } - auto erase(const_iterator pos) { return all_filters_.erase(pos); } - auto erase(iterator first, iterator last) { return all_filters_.erase(first, last); } - auto erase(const_iterator first, const_iterator last) { return all_filters_.erase(first, last); } + auto erase(iterator pos) -> iterator; + auto erase(const_iterator pos) -> iterator; + auto erase(iterator first, iterator last) -> iterator; + auto erase(const_iterator first, const_iterator last) -> iterator; void SetFilters(std::vector &&all_filters) { all_filters_ = std::move(all_filters); } - auto FilteredLabels(const Symbol &symbol) const { - std::unordered_set labels; - for (const auto &filter : all_filters_) { - if (filter.type == FilterInfo::Type::Label && utils::Contains(filter.used_symbols, symbol)) { - MG_ASSERT(filter.used_symbols.size() == 1U, "Expected a single used symbol for label filter"); - labels.insert(filter.labels.begin(), filter.labels.end()); - } - } - return labels; - } - - auto FilteredProperties(const Symbol &symbol) const -> std::unordered_set { - std::unordered_set properties; - - for (const auto &filter : all_filters_) { - if (filter.type == FilterInfo::Type::Property && filter.property_filter->symbol_ == symbol) { - properties.insert(filter.property_filter->property_); - } - } - return properties; - } + auto FilteredLabels(const Symbol &symbol) const -> std::unordered_set; + auto FilteredProperties(const Symbol &symbol) const -> std::unordered_set; /// Remove a filter; may invalidate iterators. /// Removal is done by comparing only the expression, so that multiple @@ -370,26 +371,10 @@ class Filters final { std::vector *removed_filters = nullptr); /// Returns a vector of FilterInfo for properties. - auto PropertyFilters(const Symbol &symbol) const { - std::vector filters; - for (const auto &filter : all_filters_) { - if (filter.type == FilterInfo::Type::Property && filter.property_filter->symbol_ == symbol) { - filters.push_back(filter); - } - } - return filters; - } + auto PropertyFilters(const Symbol &symbol) const -> std::vector; /// Return a vector of FilterInfo for ID equality filtering. - auto IdFilters(const Symbol &symbol) const { - std::vector filters; - for (const auto &filter : all_filters_) { - if (filter.type == FilterInfo::Type::Id && filter.id_filter->symbol_ == symbol) { - filters.push_back(filter); - } - } - return filters; - } + auto IdFilters(const Symbol &symbol) const -> std::vector; /// Collects filtering information from a pattern. /// @@ -459,6 +444,57 @@ struct FilterMatching : Matching { std::optional symbol; }; +inline auto Filters::erase(Filters::iterator pos) -> iterator { return all_filters_.erase(pos); } +inline auto Filters::erase(Filters::const_iterator pos) -> iterator { return all_filters_.erase(pos); } +inline auto Filters::erase(Filters::iterator first, Filters::iterator last) -> iterator { + return all_filters_.erase(first, last); +} +inline auto Filters::erase(Filters::const_iterator first, Filters::const_iterator last) -> iterator { + return all_filters_.erase(first, last); +} + +inline auto Filters::FilteredLabels(const Symbol &symbol) const -> std::unordered_set { + std::unordered_set labels; + for (const auto &filter : all_filters_) { + if (filter.type == FilterInfo::Type::Label && utils::Contains(filter.used_symbols, symbol)) { + MG_ASSERT(filter.used_symbols.size() == 1U, "Expected a single used symbol for label filter"); + labels.insert(filter.labels.begin(), filter.labels.end()); + } + } + return labels; +} + +inline auto Filters::FilteredProperties(const Symbol &symbol) const -> std::unordered_set { + std::unordered_set properties; + + for (const auto &filter : all_filters_) { + if (filter.type == FilterInfo::Type::Property && filter.property_filter->symbol_ == symbol) { + properties.insert(filter.property_filter->property_); + } + } + return properties; +} + +inline auto Filters::PropertyFilters(const Symbol &symbol) const -> std::vector { + std::vector filters; + for (const auto &filter : all_filters_) { + if (filter.type == FilterInfo::Type::Property && filter.property_filter->symbol_ == symbol) { + filters.push_back(filter); + } + } + return filters; +} + +inline auto Filters::IdFilters(const Symbol &symbol) const -> std::vector { + std::vector filters; + for (const auto &filter : all_filters_) { + if (filter.type == FilterInfo::Type::Id && filter.id_filter->symbol_ == symbol) { + filters.push_back(filter); + } + } + return filters; +} + /// @brief Represents a read (+ write) part of a query. Parts are split on /// `WITH` clauses. /// diff --git a/src/query/procedure/fmt.hpp b/src/query/procedure/fmt.hpp new file mode 100644 index 000000000..85775da46 --- /dev/null +++ b/src/query/procedure/fmt.hpp @@ -0,0 +1,82 @@ +// Copyright 2024 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#if FMT_VERSION > 90000 +#include +#include + +#include "mg_procedure.h" +#include "utils/logging.hpp" + +inline std::string ToString(const mgp_log_level &log_level) { + switch (log_level) { + case mgp_log_level::MGP_LOG_LEVEL_CRITICAL: + return "CRITICAL"; + case mgp_log_level::MGP_LOG_LEVEL_ERROR: + return "ERROR"; + case mgp_log_level::MGP_LOG_LEVEL_WARN: + return "WARN"; + case mgp_log_level::MGP_LOG_LEVEL_INFO: + return "INFO"; + case mgp_log_level::MGP_LOG_LEVEL_DEBUG: + return "DEBUG"; + case mgp_log_level::MGP_LOG_LEVEL_TRACE: + return "TRACE"; + } + LOG_FATAL("ToString of a wrong mgp_log_level -> check missing switch case"); +} +inline std::ostream &operator<<(std::ostream &os, const mgp_log_level &log_level) { + os << ToString(log_level); + return os; +} +template <> +class fmt::formatter : public fmt::ostream_formatter {}; + +inline std::string ToString(const mgp_error &error) { + switch (error) { + case mgp_error::MGP_ERROR_NO_ERROR: + return "NO ERROR"; + case mgp_error::MGP_ERROR_UNKNOWN_ERROR: + return "UNKNOWN ERROR"; + case mgp_error::MGP_ERROR_UNABLE_TO_ALLOCATE: + return "UNABLE TO ALLOCATE ERROR"; + case mgp_error::MGP_ERROR_INSUFFICIENT_BUFFER: + return "INSUFFICIENT BUFFER ERROR"; + case mgp_error::MGP_ERROR_OUT_OF_RANGE: + return "OUT OF RANGE ERROR"; + case mgp_error::MGP_ERROR_LOGIC_ERROR: + return "LOGIC ERROR"; + case mgp_error::MGP_ERROR_DELETED_OBJECT: + return "DELETED OBJECT ERROR"; + case mgp_error::MGP_ERROR_INVALID_ARGUMENT: + return "INVALID ARGUMENT ERROR"; + case mgp_error::MGP_ERROR_KEY_ALREADY_EXISTS: + return "KEY ALREADY EXISTS ERROR"; + case mgp_error::MGP_ERROR_IMMUTABLE_OBJECT: + return "IMMUTABLE OBJECT ERROR"; + case mgp_error::MGP_ERROR_VALUE_CONVERSION: + return "VALUE CONVERSION ERROR"; + case mgp_error::MGP_ERROR_SERIALIZATION_ERROR: + return "SERIALIZATION ERROR"; + case mgp_error::MGP_ERROR_AUTHORIZATION_ERROR: + return "AUTHORIZATION ERROR"; + } + LOG_FATAL("ToString of a wrong mgp_error -> check missing switch case"); +} +inline std::ostream &operator<<(std::ostream &os, const mgp_error &error) { + os << ToString(error); + return os; +} +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/src/query/procedure/mg_procedure_helpers.cpp b/src/query/procedure/mg_procedure_helpers.cpp index 6b206e7dc..a6590a287 100644 --- a/src/query/procedure/mg_procedure_helpers.cpp +++ b/src/query/procedure/mg_procedure_helpers.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -10,6 +10,7 @@ // licenses/APL.txt. #include "query/procedure/mg_procedure_helpers.hpp" +#include "query/procedure/fmt.hpp" namespace memgraph::query::procedure { MgpUniquePtr GetStringValueOrSetError(const char *string, mgp_memory *memory, mgp_result *result) { diff --git a/src/query/procedure/mg_procedure_helpers.hpp b/src/query/procedure/mg_procedure_helpers.hpp index cb8bd55db..d0032c521 100644 --- a/src/query/procedure/mg_procedure_helpers.hpp +++ b/src/query/procedure/mg_procedure_helpers.hpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -18,6 +18,7 @@ #include #include "mg_procedure.h" +#include "query/procedure/fmt.hpp" namespace memgraph::query::procedure { template diff --git a/src/query/procedure/mg_procedure_impl.cpp b/src/query/procedure/mg_procedure_impl.cpp index c7faf15f7..647f3e14d 100644 --- a/src/query/procedure/mg_procedure_impl.cpp +++ b/src/query/procedure/mg_procedure_impl.cpp @@ -29,6 +29,7 @@ #include "query/db_accessor.hpp" #include "query/frontend/ast/ast.hpp" #include "query/procedure/cypher_types.hpp" +#include "query/procedure/fmt.hpp" #include "query/procedure/mg_procedure_helpers.hpp" #include "query/stream/common.hpp" #include "storage/v2/property_value.hpp" diff --git a/src/query/typed_value.cpp b/src/query/typed_value.cpp index 4cb79508e..86d25f01b 100644 --- a/src/query/typed_value.cpp +++ b/src/query/typed_value.cpp @@ -19,6 +19,7 @@ #include #include +#include "query/fmt.hpp" #include "storage/v2/temporal.hpp" #include "utils/exceptions.hpp" #include "utils/fnv.hpp" @@ -326,13 +327,11 @@ TypedValue::operator storage::PropertyValue() const { throw TypedValueException("TypedValue is of type '{}', not '{}'", type_, Type::type_enum); \ return field; \ } \ - \ const type_param &TypedValue::Value##type_enum() const { \ if (type_ != Type::type_enum) [[unlikely]] \ throw TypedValueException("TypedValue is of type '{}', not '{}'", type_, Type::type_enum); \ return field; \ } \ - \ bool TypedValue::Is##type_enum() const { return type_ == Type::type_enum; } DEFINE_VALUE_AND_TYPE_GETTERS(bool, Bool, bool_v) @@ -783,10 +782,13 @@ TypedValue operator<(const TypedValue &a, const TypedValue &b) { return false; } }; - if (!is_legal(a.type()) || !is_legal(b.type())) + if (!is_legal(a.type()) || !is_legal(b.type())) { throw TypedValueException("Invalid 'less' operand types({} + {})", a.type(), b.type()); + } - if (a.IsNull() || b.IsNull()) return TypedValue(a.GetMemoryResource()); + if (a.IsNull() || b.IsNull()) { + return TypedValue(a.GetMemoryResource()); + } if (a.IsString() || b.IsString()) { if (a.type() != b.type()) { @@ -956,8 +958,9 @@ inline void EnsureArithmeticallyOk(const TypedValue &a, const TypedValue &b, boo // checked here because they are handled before this check is performed in // arithmetic op implementations. - if (!is_legal(a) || !is_legal(b)) + if (!is_legal(a) || !is_legal(b)) { throw TypedValueException("Invalid {} operand types {}, {}", op_name, a.type(), b.type()); + } } namespace { @@ -1107,8 +1110,9 @@ TypedValue operator%(const TypedValue &a, const TypedValue &b) { } inline void EnsureLogicallyOk(const TypedValue &a, const TypedValue &b, const std::string &op_name) { - if (!((a.IsBool() || a.IsNull()) && (b.IsBool() || b.IsNull()))) + if (!((a.IsBool() || a.IsNull()) && (b.IsBool() || b.IsNull()))) { throw TypedValueException("Invalid {} operand types({} && {})", op_name, a.type(), b.type()); + } } TypedValue operator&&(const TypedValue &a, const TypedValue &b) { diff --git a/src/replication/include/replication/messages.hpp b/src/replication/include/replication/messages.hpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/replication/messages.cpp b/src/replication/messages.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/replication/replication_client.cpp b/src/replication/replication_client.cpp index ed46ea471..262d698bf 100644 --- a/src/replication/replication_client.cpp +++ b/src/replication/replication_client.cpp @@ -10,6 +10,7 @@ // licenses/APL.txt. #include "replication/replication_client.hpp" +#include "io/network/fmt.hpp" namespace memgraph::replication { @@ -30,7 +31,7 @@ ReplicationClient::ReplicationClient(const memgraph::replication::ReplicationCli ReplicationClient::~ReplicationClient() { try { auto const &endpoint = rpc_client_.Endpoint(); - spdlog::trace("Closing replication client on {}:{}", endpoint.address, endpoint.port); + spdlog::trace("Closing replication client on {}", endpoint); } catch (...) { // Logging can throw. Not a big deal, just ignore. } diff --git a/src/rpc/client.hpp b/src/rpc/client.hpp index 3a2fefd57..d14746313 100644 --- a/src/rpc/client.hpp +++ b/src/rpc/client.hpp @@ -27,6 +27,8 @@ #include "utils/on_scope_exit.hpp" #include "utils/typeinfo.hpp" +#include "io/network/fmt.hpp" + namespace memgraph::rpc { /// Client is thread safe, but it is recommended to use thread_local clients. diff --git a/src/storage/v2/disk/storage.cpp b/src/storage/v2/disk/storage.cpp index adc0e92f4..fa9f93ccb 100644 --- a/src/storage/v2/disk/storage.cpp +++ b/src/storage/v2/disk/storage.cpp @@ -1278,7 +1278,7 @@ bool DiskStorage::DeleteEdgeFromConnectivityIndex(Transaction *transaction, cons /// std::map /// Here we also do flushing of too many things, we don't need to serialize edges in read-only txn, check that... [[nodiscard]] utils::BasicResult DiskStorage::FlushModifiedEdges( - Transaction *transaction, const auto &edge_acc) { + Transaction *transaction, const auto &edges_acc) { for (const auto &modified_edge : transaction->modified_edges_) { const std::string edge_gid = modified_edge.first.ToString(); const Delta::Action root_action = modified_edge.second.delta_action; @@ -1304,8 +1304,8 @@ bool DiskStorage::DeleteEdgeFromConnectivityIndex(Transaction *transaction, cons return StorageManipulationError{SerializationError{}}; } - const auto &edge = edge_acc.find(modified_edge.first); - MG_ASSERT(edge != edge_acc.end(), + const auto &edge = edges_acc.find(modified_edge.first); + MG_ASSERT(edge != edges_acc.end(), "Database in invalid state, commit not possible! Please restart your DB and start the import again."); /// TODO: (andi) I think this is not wrong but it would be better to use AtomicWrites across column families. @@ -1693,9 +1693,8 @@ utils::BasicResult DiskStorage::DiskAccessor::Co transaction_.commit_timestamp->store(*commit_timestamp_, std::memory_order_release); if (edge_import_mode_active) { - if (auto res = - disk_storage->FlushModifiedEdges(&transaction_, disk_storage->edge_import_mode_cache_->AccessToEdges()); - res.HasError()) { + auto edges_acc = disk_storage->edge_import_mode_cache_->AccessToEdges(); + if (auto res = disk_storage->FlushModifiedEdges(&transaction_, edges_acc); res.HasError()) { Abort(); return res; } @@ -1717,7 +1716,8 @@ utils::BasicResult DiskStorage::DiskAccessor::Co return del_vertices_res.GetError(); } - if (auto modified_edges_res = disk_storage->FlushModifiedEdges(&transaction_, transaction_.edges_->access()); + auto tx_edges_acc = transaction_.edges_->access(); + if (auto modified_edges_res = disk_storage->FlushModifiedEdges(&transaction_, tx_edges_acc); modified_edges_res.HasError()) { Abort(); return modified_edges_res.GetError(); diff --git a/src/storage/v2/disk/storage.hpp b/src/storage/v2/disk/storage.hpp index 293e102b1..20b1645be 100644 --- a/src/storage/v2/disk/storage.hpp +++ b/src/storage/v2/disk/storage.hpp @@ -195,7 +195,7 @@ class DiskStorage final : public Storage { [[nodiscard]] utils::BasicResult FlushDeletedVertices(Transaction *transaction); [[nodiscard]] utils::BasicResult FlushDeletedEdges(Transaction *transaction); [[nodiscard]] utils::BasicResult FlushModifiedEdges(Transaction *transaction, - const auto &edge_acc); + const auto &edges_acc); [[nodiscard]] utils::BasicResult ClearDanglingVertices(Transaction *transaction); /// Writing methods diff --git a/src/storage/v2/durability/snapshot.cpp b/src/storage/v2/durability/snapshot.cpp index 0d434fadf..eee099870 100644 --- a/src/storage/v2/durability/snapshot.cpp +++ b/src/storage/v2/durability/snapshot.cpp @@ -22,6 +22,7 @@ #include "storage/v2/edge.hpp" #include "storage/v2/edge_accessor.hpp" #include "storage/v2/edge_ref.hpp" +#include "storage/v2/fmt.hpp" #include "storage/v2/id_types.hpp" #include "storage/v2/indices/label_index_stats.hpp" #include "storage/v2/indices/label_property_index_stats.hpp" diff --git a/src/storage/v2/fmt.hpp b/src/storage/v2/fmt.hpp new file mode 100644 index 000000000..e200d7299 --- /dev/null +++ b/src/storage/v2/fmt.hpp @@ -0,0 +1,23 @@ +// Copyright 2024 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#if FMT_VERSION > 90000 +#include + +#include "storage/v2/property_value.hpp" + +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +template <> +class fmt::formatter : public fmt::ostream_formatter {}; +#endif diff --git a/src/storage/v2/replication/replication_client.cpp b/src/storage/v2/replication/replication_client.cpp index 16247de57..a581201c1 100644 --- a/src/storage/v2/replication/replication_client.cpp +++ b/src/storage/v2/replication/replication_client.cpp @@ -9,6 +9,8 @@ // by the Apache License, Version 2.0, included in the file // licenses/APL.txt. +#include + #include "replication/replication_client.hpp" #include "storage/v2/inmemory/storage.hpp" #include "storage/v2/storage.hpp" @@ -17,7 +19,7 @@ #include "utils/uuid.hpp" #include "utils/variant_helpers.hpp" -#include +#include "io/network/fmt.hpp" namespace { template diff --git a/src/storage/v2/replication/serialization.cpp b/src/storage/v2/replication/serialization.cpp index 6651b8999..d0ba2e8ac 100644 --- a/src/storage/v2/replication/serialization.cpp +++ b/src/storage/v2/replication/serialization.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source diff --git a/src/utils/async_timer.cpp b/src/utils/async_timer.cpp index dd5789172..b72be4d45 100644 --- a/src/utils/async_timer.cpp +++ b/src/utils/async_timer.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -56,12 +56,11 @@ void EraseFlag(uint64_t flag_id) { expiration_flags.access().remove(flag_id); } std::weak_ptr> GetFlag(uint64_t flag_id) { const auto flag_accessor = expiration_flags.access(); - const auto it = flag_accessor.find(flag_id); - if (it == flag_accessor.end()) { + const auto iter = flag_accessor.find(flag_id); + if (iter == flag_accessor.end()) { return {}; } - - return it->flag; + return iter->flag; } void MarkDone(const uint64_t flag_id) { diff --git a/src/utils/logging.hpp b/src/utils/logging.hpp index 02389beab..adc5db51a 100644 --- a/src/utils/logging.hpp +++ b/src/utils/logging.hpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -23,6 +23,11 @@ #include #include +// NOTE: fmt 9+ introduced fmt/std.h, it's important because of, e.g., std::path formatting. toolchain-v4 has fmt 8, +// the guard is here because of fmt 8 compatibility. +#if FMT_VERSION > 90000 +#include +#endif #include #include #include diff --git a/src/utils/message.hpp b/src/utils/message.hpp index c301b3878..009bea032 100644 --- a/src/utils/message.hpp +++ b/src/utils/message.hpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -17,8 +17,13 @@ namespace memgraph::utils { template std::string MessageWithLink(fmt::format_string fmt, Args &&...args) { +#if FMT_VERSION > 90000 + return fmt::format(fmt::runtime(fmt::format(fmt::runtime("{} For more details, visit {{}}."), fmt.get())), + std::forward(args)...); +#else return fmt::format(fmt::runtime(fmt::format(fmt::runtime("{} For more details, visit {{}}."), fmt)), std::forward(args)...); +#endif } } // namespace memgraph::utils diff --git a/src/utils/stat.hpp b/src/utils/stat.hpp index 4c2eec6d6..de806f853 100644 --- a/src/utils/stat.hpp +++ b/src/utils/stat.hpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -18,6 +18,7 @@ #include #include "utils/file.hpp" +#include "utils/logging.hpp" #include "utils/string.hpp" namespace memgraph::utils { @@ -39,19 +40,19 @@ inline uint64_t GetDirDiskUsage(const std::filesystem::path &path) { return 0; } uint64_t size = 0; - for (const auto &p : std::filesystem::directory_iterator(path)) { - if (IgnoreSymlink && std::filesystem::is_symlink(p)) continue; - if (std::filesystem::is_directory(p)) { - size += GetDirDiskUsage(p); - } else if (std::filesystem::is_regular_file(p)) { - if (!utils::HasReadAccess(p)) { + for (const auto &dir_entry : std::filesystem::directory_iterator(path)) { + if (IgnoreSymlink && std::filesystem::is_symlink(dir_entry)) continue; + if (std::filesystem::is_directory(dir_entry)) { + size += GetDirDiskUsage(dir_entry); + } else if (std::filesystem::is_regular_file(dir_entry)) { + if (!utils::HasReadAccess(dir_entry)) { spdlog::warn( "Skipping file path on collecting directory disk usage '{}' because it is not readable, check file " "ownership and read permissions!", - p); + dir_entry.path()); continue; } - size += std::filesystem::file_size(p); + size += std::filesystem::file_size(dir_entry); } } diff --git a/tests/e2e/replication/constraints.cpp b/tests/e2e/replication/constraints.cpp index 6f7e2991a..de090007f 100644 --- a/tests/e2e/replication/constraints.cpp +++ b/tests/e2e/replication/constraints.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -18,6 +18,7 @@ #include #include "common.hpp" +#include "io/network/fmt.hpp" #include "utils/logging.hpp" #include "utils/thread.hpp" #include "utils/timer.hpp" diff --git a/tests/e2e/replication/indices.cpp b/tests/e2e/replication/indices.cpp index c0eee23a7..d4b5397f1 100644 --- a/tests/e2e/replication/indices.cpp +++ b/tests/e2e/replication/indices.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -18,6 +18,7 @@ #include #include "common.hpp" +#include "io/network/fmt.hpp" #include "utils/logging.hpp" #include "utils/thread.hpp" #include "utils/timer.hpp" diff --git a/tests/e2e/replication/read_write_benchmark.cpp b/tests/e2e/replication/read_write_benchmark.cpp index 243aab2a8..b7719faf0 100644 --- a/tests/e2e/replication/read_write_benchmark.cpp +++ b/tests/e2e/replication/read_write_benchmark.cpp @@ -1,4 +1,4 @@ -// Copyright 2023 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -19,6 +19,7 @@ #include #include "common.hpp" +#include "io/network/fmt.hpp" #include "utils/logging.hpp" #include "utils/thread.hpp" #include "utils/timer.hpp" diff --git a/tests/e2e/triggers/privilige_check.cpp b/tests/e2e/triggers/privilige_check.cpp index f2cad40d4..2d7ac0f1c 100644 --- a/tests/e2e/triggers/privilige_check.cpp +++ b/tests/e2e/triggers/privilige_check.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -13,7 +13,6 @@ #include #include -#include #include #include "common.hpp" #include "utils/logging.hpp" diff --git a/tests/macro_benchmark/clients/pokec_client.cpp b/tests/macro_benchmark/clients/pokec_client.cpp index ba6f96941..40854707e 100644 --- a/tests/macro_benchmark/clients/pokec_client.cpp +++ b/tests/macro_benchmark/clients/pokec_client.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -24,11 +24,13 @@ #include #include +#include "communication/bolt/v1/value.hpp" #include "io/network/utils.hpp" +#include "long_running_common.hpp" #include "utils/algorithm.hpp" #include "utils/timer.hpp" -#include "long_running_common.hpp" +#include "communication/bolt/v1/fmt.hpp" using memgraph::communication::bolt::Edge; using memgraph::communication::bolt::Value; diff --git a/tests/manual/interactive_planning.cpp b/tests/manual/interactive_planning.cpp index f550b9724..3f64c4f37 100644 --- a/tests/manual/interactive_planning.cpp +++ b/tests/manual/interactive_planning.cpp @@ -27,6 +27,7 @@ #include "query/plan/planner.hpp" #include "query/plan/pretty_print.hpp" #include "query/typed_value.hpp" +#include "storage/v2/fmt.hpp" #include "storage/v2/property_value.hpp" #include "utils/string.hpp" diff --git a/tests/manual/query_hash.cpp b/tests/manual/query_hash.cpp index 8688da351..fb16f6db5 100644 --- a/tests/manual/query_hash.cpp +++ b/tests/manual/query_hash.cpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2024 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -15,6 +15,7 @@ #include #include "query/frontend/stripped.hpp" +#include "storage/v2/fmt.hpp" DEFINE_string(q, "CREATE (n) RETURN n", "Query"); diff --git a/tests/unit/query_plan_operator_to_string.cpp b/tests/unit/query_plan_operator_to_string.cpp index 694552cf0..9696050f2 100644 --- a/tests/unit/query_plan_operator_to_string.cpp +++ b/tests/unit/query_plan_operator_to_string.cpp @@ -214,23 +214,22 @@ TYPED_TEST(OperatorToStringTest, Filter) { auto node_ident = IDENT("person"); auto property = this->dba.NameToProperty("name"); auto property_ix = this->storage.GetPropertyIx("name"); - - FilterInfo generic_filter_info = {.type = FilterInfo::Type::Generic, .used_symbols = {node}}; + auto generic_filter_info = FilterInfo{FilterInfo::Type::Generic, nullptr, {node}}; auto id_filter = IdFilter(this->symbol_table, node, LITERAL(42)); - FilterInfo id_filter_info = {.type = FilterInfo::Type::Id, .id_filter = id_filter}; + auto id_filter_info = FilterInfo{FilterInfo::Type::Id, nullptr, {}, {}, id_filter}; std::vector labels{this->storage.GetLabelIx("Customer"), this->storage.GetLabelIx("Visitor")}; auto labels_test = LABELS_TEST(node_ident, labels); - FilterInfo label_filter_info = {.type = FilterInfo::Type::Label, .expression = labels_test}; + auto label_filter_info = FilterInfo{FilterInfo::Type::Label, labels_test}; auto labels_test_2 = LABELS_TEST(PROPERTY_LOOKUP(this->dba, "person", property), labels); - FilterInfo label_filter_2_info = {.type = FilterInfo::Type::Label, .expression = labels_test_2}; + auto label_filter_2_info = FilterInfo{FilterInfo::Type::Label, labels_test_2}; auto property_filter = PropertyFilter(node, property_ix, PropertyFilter::Type::EQUAL); - FilterInfo property_filter_info = {.type = FilterInfo::Type::Property, .property_filter = property_filter}; + auto property_filter_info = FilterInfo{FilterInfo::Type::Property, nullptr, {}, property_filter}; - FilterInfo pattern_filter_info = {.type = FilterInfo::Type::Pattern}; + auto pattern_filter_info = FilterInfo{FilterInfo::Type::Pattern}; Filters filters; filters.SetFilters({generic_filter_info, id_filter_info, label_filter_info, label_filter_2_info, property_filter_info,