diff --git a/helio b/helio index 0f87cb9c5..723774a02 160000 --- a/helio +++ b/helio @@ -1 +1 @@ -Subproject commit 0f87cb9c5e9e846c721eb6c93603d6fdc14223bd +Subproject commit 723774a0248102f97c8b0e71b5078025386c3ac1 diff --git a/src/facade/dragonfly_connection.cc b/src/facade/dragonfly_connection.cc index 21849e476..421f0e338 100644 --- a/src/facade/dragonfly_connection.cc +++ b/src/facade/dragonfly_connection.cc @@ -396,10 +396,11 @@ void Connection::ConnectionFlow(FiberSocketBase* peer) { error_code ec2 = peer->Write(::io::Buffer(sv)); if (ec2) { LOG(WARNING) << "Error " << ec2; - ec = ec; + ec = ec2; } } - peer->Shutdown(SHUT_RDWR); + error_code ec2 = peer->Shutdown(SHUT_RDWR); + LOG_IF(WARNING, ec2) << "Could not shutdown socket " << ec2; } if (ec && !FiberSocketBase::IsConnClosed(ec)) { diff --git a/src/redis/CMakeLists.txt b/src/redis/CMakeLists.txt index ac13627a0..15fd39c73 100644 --- a/src/redis/CMakeLists.txt +++ b/src/redis/CMakeLists.txt @@ -10,12 +10,14 @@ endif() add_library(redis_lib crc64.c crcspeed.c debug.c dict.c intset.c listpack.c mt19937-64.c object.c lzf_c.c lzf_d.c sds.c - quicklist.c rax.c redis_aux.c siphash.c t_hash.c t_stream.c t_zset.c + quicklist.c rax.c redis_aux.c siphash.c t_hash.c t_stream.c t_zset.c util.c ziplist.c ${ZMALLOC_SRC}) cxx_link(redis_lib ${ZMALLOC_DEPS}) -target_compile_options(redis_lib PRIVATE -Wno-maybe-uninitialized) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + target_compile_options(redis_lib PRIVATE -Wno-maybe-uninitialized) +endif() if (REDIS_ZMALLOC_MI) target_compile_definitions(redis_lib PUBLIC USE_ZMALLOC_MI) diff --git a/src/server/CMakeLists.txt b/src/server/CMakeLists.txt index 2864b391e..ad5a90aba 100644 --- a/src/server/CMakeLists.txt +++ b/src/server/CMakeLists.txt @@ -10,7 +10,7 @@ add_library(dragonfly_lib channel_slice.cc command_registry.cc config_flags.cc conn_context.cc debugcmd.cc dflycmd.cc generic_family.cc hset_family.cc json_family.cc list_family.cc main_service.cc rdb_load.cc rdb_save.cc replica.cc - snapshot.cc script_mgr.cc server_family.cc + snapshot.cc script_mgr.cc server_family.cc malloc_stats.cc set_family.cc stream_family.cc string_family.cc zset_family.cc version.cc) diff --git a/src/server/common.h b/src/server/common.h index 2ac515a1d..55c25939a 100644 --- a/src/server/common.h +++ b/src/server/common.h @@ -122,6 +122,9 @@ extern std::atomic_uint64_t used_mem_peak; extern std::atomic_uint64_t used_mem_current; extern size_t max_memory_limit; +// malloc memory stats. +int64_t GetMallocCurrentCommitted(); + // version 5.11 maps to 511 etc. // set upon server start. extern unsigned kernel_version; diff --git a/src/server/list_family.cc b/src/server/list_family.cc index 4759b9893..2224c7c31 100644 --- a/src/server/list_family.cc +++ b/src/server/list_family.cc @@ -251,7 +251,7 @@ OpStatus BPopper::Run(Transaction* t, unsigned msec) { // We got here if (!result) { // cleanups, locks removal etc. - auto cb = [this](Transaction* t, EngineShard* shard) { return OpStatus::OK; }; + auto cb = [](Transaction* t, EngineShard* shard) { return OpStatus::OK; }; t->Execute(std::move(cb), true); return result.status(); diff --git a/src/server/main_service.cc b/src/server/main_service.cc index d3cf0db4d..ef460a5f9 100644 --- a/src/server/main_service.cc +++ b/src/server/main_service.cc @@ -953,10 +953,11 @@ bool CheckWatchedKeyExpiry(ConnectionContext* cntx, const CommandRegistry& regis } atomic_uint32_t watch_exist_count{0}; - auto cb = [&watch_exist_count, &exec_info](Transaction* t, EngineShard* shard) { + auto cb = [&watch_exist_count](Transaction* t, EngineShard* shard) { ArgSlice args = t->ShardArgsInShard(shard->shard_id()); auto res = GenericFamily::OpExists(t->GetOpArgs(shard), args); watch_exist_count.fetch_add(res.value_or(0), memory_order_relaxed); + return OpStatus::OK; }; diff --git a/src/server/malloc_stats.cc b/src/server/malloc_stats.cc new file mode 100644 index 000000000..16f21fb22 --- /dev/null +++ b/src/server/malloc_stats.cc @@ -0,0 +1,23 @@ +// Copyright 2022, Roman Gershman. All rights reserved. +// See LICENSE for licensing terms. +// + +// clang-format off +#include +#include + +// clang-format on + +// This is an internal struct in mimalloc. +// To declare it, we must include mimalloc-types.h which is an internal header in the lib. +// Being such it does not interract well with some other c++ headers, therefore we +// use a clean cc file to extract data from this record. +extern "C" mi_stats_t _mi_stats_main; + +namespace dfly { + +int64_t GetMallocCurrentCommitted() { + return _mi_stats_main.committed.current; +} + +} // namespace dfly diff --git a/src/server/server_family.cc b/src/server/server_family.cc index 359d25a92..b652bdb3b 100644 --- a/src/server/server_family.cc +++ b/src/server/server_family.cc @@ -8,7 +8,7 @@ #include // for master_id_ generation. #include #include -#include + #include #include @@ -56,8 +56,6 @@ ABSL_DECLARE_FLAG(uint32_t, port); ABSL_DECLARE_FLAG(bool, cache_mode); ABSL_DECLARE_FLAG(uint32_t, hz); -extern "C" mi_stats_t _mi_stats_main; - namespace dfly { namespace fibers = ::boost::fibers; @@ -172,9 +170,6 @@ class RdbSnapshot { } private: - // whether this RdbSnapshot captures only a single shard, - // false for legacy - rdb snapshot that captures - bool single_shard_; bool started_ = false; unique_ptr file_; @@ -561,7 +556,7 @@ void PrintPrometheusMetrics(const Metrics& m, StringResponse* resp) { &resp->body()); AppendMetricWithoutLabels("memory_used_peak_bytes", "", used_mem_peak.load(memory_order_relaxed), MetricType::GAUGE, &resp->body()); - AppendMetricWithoutLabels("comitted_memory", "", _mi_stats_main.committed.current, + AppendMetricWithoutLabels("comitted_memory", "", GetMallocCurrentCommitted(), MetricType::GAUGE, &resp->body()); AppendMetricWithoutLabels("memory_max_bytes", "", max_memory_limit, MetricType::GAUGE, &resp->body()); @@ -1116,7 +1111,7 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) { append("used_memory_human", HumanReadableNumBytes(m.heap_used_bytes)); append("used_memory_peak", used_mem_peak.load(memory_order_relaxed)); - append("comitted_memory", _mi_stats_main.committed.current); + append("comitted_memory", GetMallocCurrentCommitted()); if (sdata_res.has_value()) { append("used_memory_rss", sdata_res->vm_rss);