diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c965cf0903a4..169b888db26d 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -27,8 +27,9 @@ add_library(dfly_core allocation_tracker.cc bloom.cc compact_object.cc dense_set dragonfly_core.cc extent_tree.cc huff_coder.cc interpreter.cc glob_matcher.cc mi_memory_resource.cc qlist.cc sds_utils.cc segment_allocator.cc score_map.cc small_string.cc sorted_map.cc task_queue.cc - tx_queue.cc string_set.cc string_map.cc top_keys.cc detail/bitpacking.cc detail/listpack_wrap.cc - detail/listpack.cc count_min_sketch.cc oah_entry.cc) + tx_queue.cc string_set.cc string_map.cc top_keys.cc + detail/bitpacking.cc detail/listpack_wrap.cc detail/listpack.cc + count_min_sketch.cc oah_entry.cc) cxx_link(dfly_core base dfly_search_core dfly_page_usage fibers2 jsonpath absl::flat_hash_map absl::str_format absl::random_random redis_lib diff --git a/src/core/detail/gen_utils.h b/src/core/detail/gen_utils.h new file mode 100644 index 000000000000..cd40f9645dcb --- /dev/null +++ b/src/core/detail/gen_utils.h @@ -0,0 +1,40 @@ +// Copyright 2026, DragonflyDB authors. All rights reserved. +// See LICENSE for licensing terms. +// + +#pragma once + +#include +#include + +#include + +namespace dfly { + +inline std::string GetRandomHex(absl::InsecureBitGen& gen, size_t len, size_t len_deviation = 0) { + static_assert(std::is_same::value); + if (len_deviation) { + len += (gen() % len_deviation); + } + + std::string res(len, '\0'); + size_t indx = 0; + + for (size_t i = 0; i < len / 16; ++i) { // 2 chars per byte + absl::numbers_internal::FastHexToBufferZeroPad16(gen(), res.data() + indx); + indx += 16; + } + + if (indx < res.size()) { + char buf[32]; + absl::numbers_internal::FastHexToBufferZeroPad16(gen(), buf); + + for (unsigned j = 0; indx < res.size(); indx++, j++) { + res[indx] = buf[j]; + } + } + + return res; +} + +} // namespace dfly diff --git a/src/facade/dragonfly_connection.h b/src/facade/dragonfly_connection.h index 642d54d6835a..d32825896240 100644 --- a/src/facade/dragonfly_connection.h +++ b/src/facade/dragonfly_connection.h @@ -15,6 +15,7 @@ #include "common/backed_args.h" #include "facade/connection_ref.h" +#include "facade/facade_stats.h" #include "facade/facade_types.h" #include "facade/parsed_command.h" #include "io/io_buf.h" diff --git a/src/facade/facade.cc b/src/facade/facade.cc index 089893d5c7ff..5904036cd4b8 100644 --- a/src/facade/facade.cc +++ b/src/facade/facade.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "facade/command_id.h" #include "facade/error.h" +#include "facade/facade_stats.h" #include "facade/parsed_command.h" #include "facade/reply_builder.h" #include "facade/resp_expr.h" diff --git a/src/facade/facade_stats.h b/src/facade/facade_stats.h new file mode 100644 index 000000000000..d7b0efec4132 --- /dev/null +++ b/src/facade/facade_stats.h @@ -0,0 +1,111 @@ +// Copyright 2026, DragonflyDB authors. All rights reserved. +// See LICENSE for licensing terms. +// + +#pragma once + +#include + +#include +#include + +namespace facade { + +struct ConnectionStats { + size_t read_buf_capacity = 0; // total capacity of input buffers + // Count of pending messages in dispatch queue + uint64_t dispatch_queue_entries = 0; + // Memory used by pending messages in dispatch queue + size_t dispatch_queue_bytes = 0; + // Count of pending parsed commands in the pipeline queue (Data Path) + uint64_t pipeline_queue_entries = 0; + // Memory used by pending parsed commands in the pipeline queue (Data Path) + size_t pipeline_queue_bytes = 0; + // total size of all publish messages (subset of dispatch_queue_bytes) + size_t dispatch_queue_subscriber_bytes = 0; + + size_t pipeline_cmd_cache_bytes = 0; + + uint64_t io_read_cnt = 0; + size_t io_read_bytes = 0; + + uint64_t command_cnt_main = 0; + uint64_t command_cnt_other = 0; + uint64_t pipelined_cmd_cnt = 0; + uint64_t pipelined_cmd_latency = 0; // in microseconds + + // in microseconds, time spent waiting for the pipelined commands to start executing + uint64_t pipelined_wait_latency = 0; + uint64_t conn_received_cnt = 0; + + uint32_t num_conns_main = 0; + uint32_t num_conns_other = 0; + uint32_t num_blocked_clients = 0; + + // number of times the connection yielded due to max_busy_read_usec limit + uint32_t num_read_yields = 0; + uint64_t num_migrations = 0; + uint64_t num_recv_provided_calls = 0; + + // Number of times the tls connection was closed by the time we started reading from it. + uint64_t tls_accept_disconnects = 0; // number of TLS socket disconnects during the handshake + // + uint64_t handshakes_started = 0; + uint64_t handshakes_completed = 0; + + // Number of events when the pipeline queue was over the limit and was throttled. + uint64_t pipeline_throttle_count = 0; + uint64_t pipeline_dispatch_calls = 0; + uint64_t pipeline_dispatch_commands = 0; + uint64_t pipeline_dispatch_flush_usec = 0; + + uint64_t skip_pipeline_flushing = 0; // number of times we skipped flushing the pipeline + + ConnectionStats& operator+=(const ConnectionStats& o); +}; + +struct ReplyStats { + struct SendStats { + int64_t count = 0; + int64_t total_duration = 0; + + SendStats& operator+=(const SendStats& other) { + static_assert(sizeof(SendStats) == 16u); + + count += other.count; + total_duration += other.total_duration; + return *this; + } + }; + + // Send() operations that are written to sockets + SendStats send_stats; + + size_t io_write_cnt = 0; + size_t io_write_bytes = 0; + absl::flat_hash_map err_count; + size_t script_error_count = 0; + + // This variable can be updated directly from shard threads when they allocate memory for replies. + std::atomic squashing_current_reply_size{0}; + + ReplyStats() = default; + ReplyStats(ReplyStats&& other) noexcept; + ReplyStats& operator+=(const ReplyStats& other); + ReplyStats& operator=(const ReplyStats& other); +}; + +struct FacadeStats { + ConnectionStats conn_stats; + ReplyStats reply_stats; + + FacadeStats& operator+=(const FacadeStats& other) { + conn_stats += other.conn_stats; + reply_stats += other.reply_stats; + return *this; + } +}; + +inline thread_local FacadeStats* tl_facade_stats = nullptr; + +} // namespace facade diff --git a/src/facade/facade_types.h b/src/facade/facade_types.h index 97e303c4809e..a3d58d40ae1b 100644 --- a/src/facade/facade_types.h +++ b/src/facade/facade_types.h @@ -4,15 +4,11 @@ #pragma once -#include -#include - #include #include #include #include -#include "base/iterator.h" #include "common/arg_range.h" #include "common/backed_args.h" #include "facade/op_status.h" @@ -152,101 +148,6 @@ inline std::string_view ArgS(ArgSlice args, size_t i) { return args[i]; } -struct ConnectionStats { - size_t read_buf_capacity = 0; // total capacity of input buffers - // Count of pending messages in dispatch queue - uint64_t dispatch_queue_entries = 0; - // Memory used by pending messages in dispatch queue - size_t dispatch_queue_bytes = 0; - // Count of pending parsed commands in the pipeline queue (Data Path) - uint64_t pipeline_queue_entries = 0; - // Memory used by pending parsed commands in the pipeline queue (Data Path) - size_t pipeline_queue_bytes = 0; - // total size of all publish messages (subset of dispatch_queue_bytes) - size_t dispatch_queue_subscriber_bytes = 0; - - size_t pipeline_cmd_cache_bytes = 0; - - uint64_t io_read_cnt = 0; - size_t io_read_bytes = 0; - - uint64_t command_cnt_main = 0; - uint64_t command_cnt_other = 0; - uint64_t pipelined_cmd_cnt = 0; - uint64_t pipelined_cmd_latency = 0; // in microseconds - - // in microseconds, time spent waiting for the pipelined commands to start executing - uint64_t pipelined_wait_latency = 0; - uint64_t conn_received_cnt = 0; - - uint32_t num_conns_main = 0; - uint32_t num_conns_other = 0; - uint32_t num_blocked_clients = 0; - - // number of times the connection yielded due to max_busy_read_usec limit - uint32_t num_read_yields = 0; - uint64_t num_migrations = 0; - uint64_t num_recv_provided_calls = 0; - - // Number of times the tls connection was closed by the time we started reading from it. - uint64_t tls_accept_disconnects = 0; // number of TLS socket disconnects during the handshake - // - uint64_t handshakes_started = 0; - uint64_t handshakes_completed = 0; - - // Number of events when the pipeline queue was over the limit and was throttled. - uint64_t pipeline_throttle_count = 0; - uint64_t pipeline_dispatch_calls = 0; - uint64_t pipeline_dispatch_commands = 0; - uint64_t pipeline_dispatch_flush_usec = 0; - - uint64_t skip_pipeline_flushing = 0; // number of times we skipped flushing the pipeline - - ConnectionStats& operator+=(const ConnectionStats& o); -}; - -struct ReplyStats { - struct SendStats { - int64_t count = 0; - int64_t total_duration = 0; - - SendStats& operator+=(const SendStats& other) { - static_assert(sizeof(SendStats) == 16u); - - count += other.count; - total_duration += other.total_duration; - return *this; - } - }; - - // Send() operations that are written to sockets - SendStats send_stats; - - size_t io_write_cnt = 0; - size_t io_write_bytes = 0; - absl::flat_hash_map err_count; - size_t script_error_count = 0; - - // This variable can be updated directly from shard threads when they allocate memory for replies. - std::atomic squashing_current_reply_size{0}; - - ReplyStats() = default; - ReplyStats(ReplyStats&& other) noexcept; - ReplyStats& operator+=(const ReplyStats& other); - ReplyStats& operator=(const ReplyStats& other); -}; - -struct FacadeStats { - ConnectionStats conn_stats; - ReplyStats reply_stats; - - FacadeStats& operator+=(const FacadeStats& other) { - conn_stats += other.conn_stats; - reply_stats += other.reply_stats; - return *this; - } -}; - struct ErrorReply { explicit ErrorReply(std::string&& msg, std::string_view kind = {}) : message{std::move(msg)}, kind{kind} { @@ -303,8 +204,6 @@ constexpr unsigned long long operator""_KB(unsigned long long x) { return 1024L * x; } -inline thread_local FacadeStats* tl_facade_stats = nullptr; - void ResetStats(); using MemoryBytesFlag = strings::MemoryBytesFlag; diff --git a/src/facade/reply_builder.h b/src/facade/reply_builder.h index ad4a8ab915ff..34e6a40b22b4 100644 --- a/src/facade/reply_builder.h +++ b/src/facade/reply_builder.h @@ -9,6 +9,7 @@ #include #include +#include "facade/facade_stats.h" #include "facade/facade_types.h" #include "facade/op_status.h" #include "io/io.h" diff --git a/src/facade/resp_validator.cc b/src/facade/resp_validator.cc index a4d73e0adadf..c1c1bd738925 100644 --- a/src/facade/resp_validator.cc +++ b/src/facade/resp_validator.cc @@ -6,6 +6,7 @@ #include #include +#include #include "base/flags.h" #include "base/init.h" diff --git a/src/facade/tls_helpers.cc b/src/facade/tls_helpers.cc index 80033c1653d4..d4016a4996b0 100644 --- a/src/facade/tls_helpers.cc +++ b/src/facade/tls_helpers.cc @@ -9,11 +9,13 @@ #include #endif +#include + #include -#include "absl/functional/bind_front.h" #include "base/flags.h" #include "base/logging.h" +#include "facade/facade_stats.h" #include "facade/facade_types.h" ABSL_FLAG(std::string, tls_cert_file, "", "cert file for tls connections"); diff --git a/src/server/bitops_family.cc b/src/server/bitops_family.cc index d569cbeddc3e..238df44aea9a 100644 --- a/src/server/bitops_family.cc +++ b/src/server/bitops_family.cc @@ -2,6 +2,7 @@ // See LICENSE for licensing terms. // +#include #include #include diff --git a/src/server/blocking_controller_test.cc b/src/server/blocking_controller_test.cc index 569b0980ca2e..68f402906f3e 100644 --- a/src/server/blocking_controller_test.cc +++ b/src/server/blocking_controller_test.cc @@ -7,6 +7,7 @@ #include #include "base/logging.h" +#include "facade/facade_stats.h" #include "server/acl/acl_commands_def.h" #include "server/command_registry.h" #include "server/engine_shard_set.h" diff --git a/src/server/cluster/cluster_family.cc b/src/server/cluster/cluster_family.cc index 33687b7d1c9f..2ffb149ab3b1 100644 --- a/src/server/cluster/cluster_family.cc +++ b/src/server/cluster/cluster_family.cc @@ -4,11 +4,13 @@ #include "server/cluster/cluster_family.h" +#include +#include + #include #include #include -#include "absl/cleanup/cleanup.h" #include "base/flags.h" #include "base/logging.h" #include "facade/cmd_arg_parser.h" diff --git a/src/server/cluster/cluster_family_test.cc b/src/server/cluster/cluster_family_test.cc index 2366bdee931b..445e8ada8beb 100644 --- a/src/server/cluster/cluster_family_test.cc +++ b/src/server/cluster/cluster_family_test.cc @@ -15,6 +15,7 @@ #include "absl/time/time.h" #include "base/gtest.h" #include "base/logging.h" +#include "core/detail/gen_utils.h" #include "facade/facade_test.h" #include "server/test_utils.h" diff --git a/src/server/common.cc b/src/server/common.cc index f600781dffde..922888dc876f 100644 --- a/src/server/common.cc +++ b/src/server/common.cc @@ -4,6 +4,7 @@ #include "server/common.h" +#include #include #include #include @@ -17,6 +18,7 @@ extern "C" { #include "base/flags.h" #include "base/logging.h" #include "core/compact_object.h" +#include "core/glob_matcher.h" #include "core/interpreter.h" #include "facade/cmd_arg_parser.h" #include "server/conn_context.h" @@ -352,6 +354,9 @@ std::ostream& operator<<(std::ostream& os, const GlobalState& state) { return os << GlobalStateName(state); } +ScanOpts::~ScanOpts() { +} + ThreadLocalMutex::ThreadLocalMutex() { shard_ = EngineShard::tlocal(); } diff --git a/src/server/common.h b/src/server/common.h index af00ac32d6db..690afa1c7cb6 100644 --- a/src/server/common.h +++ b/src/server/common.h @@ -4,26 +4,22 @@ #pragma once -#include -#include -#include - #include #include #include #include #include -#include "core/compact_object.h" -#include "core/glob_matcher.h" #include "facade/facade_types.h" #include "facade/op_status.h" -#include "helio/io/proc_reader.h" #include "util/fibers/fibers.h" #include "util/fibers/synchronization.h" namespace dfly { +using CompactObjType = unsigned; +class GlobMatcher; + // Dependent on ExpirePeriod representation of the value. constexpr int64_t kMaxExpireDeadlineSec = (1u << 28) - 1; // 8.5 years constexpr int64_t kMaxExpireDeadlineMs = kMaxExpireDeadlineSec * 1000; @@ -41,9 +37,6 @@ using facade::OpResult; using StringVec = std::vector; -// keys are RDB_TYPE_xxx constants. -using RdbTypeFreqMap = absl::flat_hash_map; - class CommandId; class Transaction; class EngineShard; @@ -144,33 +137,6 @@ inline unsigned kernel_version = 0; const char* GlobalStateName(GlobalState gs); -template -std::string GetRandomHex(RandGen& gen, size_t len, size_t len_deviation = 0) { - static_assert(std::is_same::value); - if (len_deviation) { - len += (gen() % len_deviation); - } - - std::string res(len, '\0'); - size_t indx = 0; - - for (size_t i = 0; i < len / 16; ++i) { // 2 chars per byte - absl::numbers_internal::FastHexToBufferZeroPad16(gen(), res.data() + indx); - indx += 16; - } - - if (indx < res.size()) { - char buf[32]; - absl::numbers_internal::FastHexToBufferZeroPad16(gen(), buf); - - for (unsigned j = 0; indx < res.size(); indx++, j++) { - res[indx] = buf[j]; - } - } - - return res; -} - // AggregateValue is a thread safe utility to store the first // truthy value; template struct AggregateValue { @@ -311,6 +277,13 @@ class ExecutionState { }; struct ScanOpts { + ~ScanOpts(); // because of forward declaration + ScanOpts() = default; + ScanOpts(ScanOpts&& other) = default; + + bool Matches(std::string_view val_name) const; + static OpResult TryFrom(CmdArgList args, bool allow_novalues = false); + std::unique_ptr matcher; size_t limit = 10; std::optional type_filter; @@ -325,8 +298,6 @@ struct ScanOpts { std::optional mask; size_t min_malloc_size = 0; bool novalues = false; - bool Matches(std::string_view val_name) const; - static OpResult TryFrom(CmdArgList args, bool allow_novalues = false); }; // I use relative time from Feb 1, 2023 in seconds. diff --git a/src/server/conn_context.h b/src/server/conn_context.h index 0070811e16c2..de1710453b7d 100644 --- a/src/server/conn_context.h +++ b/src/server/conn_context.h @@ -4,7 +4,6 @@ #pragma once -#include #include #include "acl/acl_commands_def.h" diff --git a/src/server/debugcmd.cc b/src/server/debugcmd.cc index ae348d8ab822..7df4e0ca4a5f 100644 --- a/src/server/debugcmd.cc +++ b/src/server/debugcmd.cc @@ -3,6 +3,8 @@ // #include "server/debugcmd.h" +#include "core/detail/gen_utils.h" + #define HUF_STATIC_LINKING_ONLY extern "C" { diff --git a/src/server/detail/save_stages_controller.cc b/src/server/detail/save_stages_controller.cc index cfbba8d750e8..07bea5462a44 100644 --- a/src/server/detail/save_stages_controller.cc +++ b/src/server/detail/save_stages_controller.cc @@ -11,6 +11,7 @@ #include "base/flags.h" #include "base/logging.h" +#include "core/detail/gen_utils.h" #include "server/detail/snapshot_storage.h" #include "server/main_service.h" #include "server/namespaces.h" diff --git a/src/server/dflycmd.cc b/src/server/dflycmd.cc index 7811d4e43767..c6eaccc5a046 100644 --- a/src/server/dflycmd.cc +++ b/src/server/dflycmd.cc @@ -17,6 +17,7 @@ #include "absl/strings/numbers.h" #include "base/flags.h" #include "base/logging.h" +#include "core/detail/gen_utils.h" #include "facade/cmd_arg_parser.h" #include "facade/dragonfly_connection.h" #include "facade/dragonfly_listener.h" diff --git a/src/server/generic_family.cc b/src/server/generic_family.cc index 481fc46ecd39..e935f895efe7 100644 --- a/src/server/generic_family.cc +++ b/src/server/generic_family.cc @@ -4,6 +4,7 @@ #include "server/generic_family.h" +#include #include #include @@ -18,6 +19,7 @@ extern "C" { #include "base/cycle_clock.h" #include "base/flags.h" #include "base/logging.h" +#include "core/glob_matcher.h" #include "core/qlist.h" #include "redis/rdb.h" #include "server/acl/acl_commands_def.h" diff --git a/src/server/geo_family.cc b/src/server/geo_family.cc index a73f89a045f5..865900f65d55 100644 --- a/src/server/geo_family.cc +++ b/src/server/geo_family.cc @@ -2,6 +2,8 @@ // See LICENSE for licensing terms. // +#include + extern "C" { #include "redis/geo.h" #include "redis/geohash.h" diff --git a/src/server/hset_family.cc b/src/server/hset_family.cc index acbb8d2f33a5..f3a24a2e284f 100644 --- a/src/server/hset_family.cc +++ b/src/server/hset_family.cc @@ -4,10 +4,7 @@ #include "server/hset_family.h" -#include "server/family_utils.h" -#include "server/tiered_storage.h" -#include "server/tiering/decoders.h" -#include "server/tiering/serialized_map.h" +#include extern "C" { #include "redis/listpack.h" @@ -27,7 +24,11 @@ extern "C" { #include "server/container_utils.h" #include "server/engine_shard_set.h" #include "server/error.h" +#include "server/family_utils.h" #include "server/search/doc_index.h" +#include "server/tiered_storage.h" +#include "server/tiering/decoders.h" +#include "server/tiering/serialized_map.h" #include "server/transaction.h" using namespace std; diff --git a/src/server/hset_family_test.cc b/src/server/hset_family_test.cc index 2ff83b26f909..1caa0dec9a58 100644 --- a/src/server/hset_family_test.cc +++ b/src/server/hset_family_test.cc @@ -15,6 +15,7 @@ extern "C" { #include "base/gtest.h" #include "base/logging.h" +#include "core/detail/gen_utils.h" #include "facade/facade_test.h" #include "server/test_utils.h" diff --git a/src/server/journal/journal_slice.h b/src/server/journal/journal_slice.h index 6a4495364cf4..a391ee96310d 100644 --- a/src/server/journal/journal_slice.h +++ b/src/server/journal/journal_slice.h @@ -9,6 +9,7 @@ #include #include +#include "base/io_buf.h" #include "server/common.h" #include "server/journal/types.h" diff --git a/src/server/journal/journal_test.cc b/src/server/journal/journal_test.cc index 12bb033591ef..f97b119731dc 100644 --- a/src/server/journal/journal_test.cc +++ b/src/server/journal/journal_test.cc @@ -3,6 +3,7 @@ #include "base/gtest.h" #include "base/logging.h" +#include "core/detail/gen_utils.h" #include "server/journal/pending_buf.h" #include "server/journal/serializer.h" #include "server/journal/types.h" diff --git a/src/server/journal/types.cc b/src/server/journal/types.cc index da9f7f151df0..7885736656e0 100644 --- a/src/server/journal/types.cc +++ b/src/server/journal/types.cc @@ -4,6 +4,8 @@ #include "server/journal/types.h" +#include + namespace dfly::journal { using namespace std; diff --git a/src/server/protocol_client.h b/src/server/protocol_client.h index e9dccfc1636a..9a36d651fa57 100644 --- a/src/server/protocol_client.h +++ b/src/server/protocol_client.h @@ -13,7 +13,6 @@ #include "facade/resp_parser.h" #include "io/io_buf.h" #include "server/common.h" -#include "server/journal/types.h" #include "server/version.h" #include "util/fiber_socket_base.h" diff --git a/src/server/rdb_save.h b/src/server/rdb_save.h index a5d82f43db4d..10e9e4a46599 100644 --- a/src/server/rdb_save.h +++ b/src/server/rdb_save.h @@ -30,6 +30,9 @@ struct HnswNodeData; namespace dfly { +// keys are RDB_TYPE_xxx constants. +using RdbTypeFreqMap = absl::flat_hash_map; + uint8_t RdbObjectType(const CompactObj& pv); class EngineShard; diff --git a/src/server/script_mgr.cc b/src/server/script_mgr.cc index 24f3564d7b7c..ed95d2421d59 100644 --- a/src/server/script_mgr.cc +++ b/src/server/script_mgr.cc @@ -253,7 +253,8 @@ unique_ptr CharBufFromSV(string_view sv) { return ptr; } -io::Result ScriptMgr::Insert(string_view body, Interpreter* interpreter) { +nonstd::expected ScriptMgr::Insert(string_view body, + Interpreter* interpreter) { char sha_buf[64]; Interpreter::FuncSha1(body, sha_buf); string_view sha{sha_buf, std::strlen(sha_buf)}; diff --git a/src/server/script_mgr.h b/src/server/script_mgr.h index a89d8a5eccf5..cbb742c30902 100644 --- a/src/server/script_mgr.h +++ b/src/server/script_mgr.h @@ -7,6 +7,7 @@ #include #include +#include #include #include "server/conn_context.h" @@ -53,7 +54,8 @@ class ScriptMgr { void Run(CmdArgList args, Transaction* tx, SinkReplyBuilder* builder, ConnectionContext* cntx); // Insert script and return sha. Get possible error from compilation or parsing script flags. - io::Result Insert(std::string_view body, Interpreter* interpreter); + nonstd::expected Insert(std::string_view body, + Interpreter* interpreter); // Get script body by sha, returns nullptr if not found. std::optional Find(std::string_view sha) const; diff --git a/src/server/search/search_family_test.cc b/src/server/search/search_family_test.cc index f25580ed3d0f..00958fb888c4 100644 --- a/src/server/search/search_family_test.cc +++ b/src/server/search/search_family_test.cc @@ -5,12 +5,13 @@ #include "server/search/search_family.h" #include +#include #include -#include "absl/strings/str_format.h" #include "base/gtest.h" #include "base/logging.h" +#include "core/detail/gen_utils.h" #include "facade/error.h" #include "facade/facade_test.h" #include "facade/resp_parser.h" @@ -994,7 +995,7 @@ TEST_P(SortTest, BasicSort) { absl::InsecureBitGen gen; vector random_strs; for (size_t i = 0; i < 10; i++) - random_strs.emplace_back(dfly::GetRandomHex(gen, 7)); + random_strs.emplace_back(GetRandomHex(gen, 7)); sort(random_strs.begin(), random_strs.end()); for (size_t i = 0; i < 10; i++) diff --git a/src/server/server_family.cc b/src/server/server_family.cc index 5fb799755264..3369fdaf3d82 100644 --- a/src/server/server_family.cc +++ b/src/server/server_family.cc @@ -26,9 +26,10 @@ #include #include "absl/strings/ascii.h" +#include "core/detail/gen_utils.h" #include "facade/error.h" #include "server/common.h" -#include "slowlog.h" +#include "server/slowlog.h" #include "util/fibers/synchronization.h" extern "C" { diff --git a/src/server/server_family.h b/src/server/server_family.h index 1d945b9146a1..238d66d2fd4e 100644 --- a/src/server/server_family.h +++ b/src/server/server_family.h @@ -11,6 +11,7 @@ #include "core/qlist.h" #include "facade/dragonfly_listener.h" +#include "facade/facade_stats.h" #include "server/detail/save_stages_controller.h" #include "server/dflycmd.h" #include "server/engine_shard_set.h" diff --git a/src/server/server_state.cc b/src/server/server_state.cc index 2ce4f6c5f3b4..65ef85c7a669 100644 --- a/src/server/server_state.cc +++ b/src/server/server_state.cc @@ -48,6 +48,10 @@ using namespace std::chrono_literals; __thread ServerState* ServerState::state_ = nullptr; +facade::ConnectionStats* ServerState::tl_connection_stats() { + return &facade::tl_facade_stats->conn_stats; +} + ServerState::Stats::Stats(unsigned num_shards) : tx_width_freq_arr(num_shards), squash_width_freq_arr(num_shards) { } @@ -347,4 +351,12 @@ void ServerState::UnsubscribeSlotsAndUpdateChannelStore(const ChannelStore::Chan channel_store_ = replacement; } +void ServerState::RecordCmd(bool is_main_conn) { + if (is_main_conn) { + ++tl_connection_stats()->command_cnt_main; + } else { + ++tl_connection_stats()->command_cnt_other; + } + qps_.Inc(); +} } // end of namespace dfly diff --git a/src/server/server_state.h b/src/server/server_state.h index 1b61b35ade70..b02f55adb3b7 100644 --- a/src/server/server_state.h +++ b/src/server/server_state.h @@ -22,7 +22,8 @@ typedef struct mi_heap_s mi_heap_t; namespace facade { class Connection; -} +struct ConnectionStats; +} // namespace facade namespace util { class ListenerInterface; @@ -153,9 +154,7 @@ class ServerState { // public struct - to allow initialization. // function to avoid this and access the correct thread local after the migration. static ServerState* __attribute__((noinline)) SafeTLocal(); - static facade::ConnectionStats* tl_connection_stats() { - return &facade::tl_facade_stats->conn_stats; - } + static facade::ConnectionStats* tl_connection_stats(); ServerState(); ~ServerState(); @@ -214,14 +213,7 @@ class ServerState { // public struct - to allow initialization. return qps_.SumTail(); } - void RecordCmd(const bool is_main_conn) { - if (is_main_conn) { - ++tl_connection_stats()->command_cnt_main; - } else { - ++tl_connection_stats()->command_cnt_other; - } - qps_.Inc(); - } + void RecordCmd(bool is_main_conn); // data heap used by zmalloc and shards. mi_heap_t* data_heap() { diff --git a/src/server/stream_family.cc b/src/server/stream_family.cc index 22746b5f8461..ac46f5040554 100644 --- a/src/server/stream_family.cc +++ b/src/server/stream_family.cc @@ -5,6 +5,7 @@ #include "server/stream_family.h" #include +#include #include extern "C" { diff --git a/src/server/stream_family.h b/src/server/stream_family.h index d3a9d42745e6..e073aa664f77 100644 --- a/src/server/stream_family.h +++ b/src/server/stream_family.h @@ -9,15 +9,13 @@ namespace dfly { class CommandRegistry; - -class CompactObj; -using PrimeValue = CompactValue; +class CompactValue; class StreamMemTracker { public: StreamMemTracker(); - void UpdateStreamSize(PrimeValue& pv) const; + void UpdateStreamSize(CompactValue& pv) const; private: size_t start_size_{0}; diff --git a/src/server/table.h b/src/server/table.h index 726103e3acc9..8de71aa30500 100644 --- a/src/server/table.h +++ b/src/server/table.h @@ -9,7 +9,6 @@ #include #include -#include "base/histogram.h" #include "core/expire_period.h" #include "core/intent_lock.h" #include "server/detail/table.h" @@ -18,6 +17,10 @@ extern "C" { #include "redis/redis_aux.h" } +namespace base { +class Histogram; +} + namespace dfly { using PrimeKey = detail::PrimeKey; diff --git a/src/server/tiered_storage.h b/src/server/tiered_storage.h index 85e5129fdb01..c3a5ba209817 100644 --- a/src/server/tiered_storage.h +++ b/src/server/tiered_storage.h @@ -10,6 +10,7 @@ #include #include +#include "io/io.h" // for io::Result (TODO: replace with nonstd/expected) #include "server/common.h" #include "server/table.h" #include "server/tiering/common.h" diff --git a/src/server/transaction.cc b/src/server/transaction.cc index 84f47a8e5e64..7c8a4b4acb4e 100644 --- a/src/server/transaction.cc +++ b/src/server/transaction.cc @@ -10,6 +10,7 @@ #include "base/flags.h" #include "base/logging.h" +#include "facade/facade_stats.h" #include "facade/op_status.h" #include "redis/redis_aux.h" #include "server/blocking_controller.h" diff --git a/src/server/zset_family.cc b/src/server/zset_family.cc index 5ae0536b3b1a..a9f9520b411c 100644 --- a/src/server/zset_family.cc +++ b/src/server/zset_family.cc @@ -4,7 +4,7 @@ #include "server/zset_family.h" -#include "server/acl/acl_commands_def.h" +#include extern "C" { #include "redis/listpack.h" @@ -18,6 +18,7 @@ extern "C" { #include "core/sorted_map.h" #include "facade/cmd_arg_parser.h" #include "facade/error.h" +#include "server/acl/acl_commands_def.h" #include "server/blocking_controller.h" #include "server/cluster/cluster_defs.h" #include "server/command_registry.h"