chore(server): Fix clang warnings and errors (#290)

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2022-09-13 23:05:51 -07:00 committed by GitHub
parent b8d791961e
commit 4522f2fdd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 16 deletions

2
helio

@ -1 +1 @@
Subproject commit 0f87cb9c5e9e846c721eb6c93603d6fdc14223bd Subproject commit 723774a0248102f97c8b0e71b5078025386c3ac1

View File

@ -396,10 +396,11 @@ void Connection::ConnectionFlow(FiberSocketBase* peer) {
error_code ec2 = peer->Write(::io::Buffer(sv)); error_code ec2 = peer->Write(::io::Buffer(sv));
if (ec2) { if (ec2) {
LOG(WARNING) << "Error " << 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)) { if (ec && !FiberSocketBase::IsConnClosed(ec)) {

View File

@ -15,7 +15,9 @@ add_library(redis_lib crc64.c crcspeed.c debug.c dict.c intset.c
cxx_link(redis_lib ${ZMALLOC_DEPS}) cxx_link(redis_lib ${ZMALLOC_DEPS})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(redis_lib PRIVATE -Wno-maybe-uninitialized) target_compile_options(redis_lib PRIVATE -Wno-maybe-uninitialized)
endif()
if (REDIS_ZMALLOC_MI) if (REDIS_ZMALLOC_MI)
target_compile_definitions(redis_lib PUBLIC USE_ZMALLOC_MI) target_compile_definitions(redis_lib PUBLIC USE_ZMALLOC_MI)

View File

@ -10,7 +10,7 @@ add_library(dragonfly_lib channel_slice.cc command_registry.cc
config_flags.cc conn_context.cc debugcmd.cc dflycmd.cc config_flags.cc conn_context.cc debugcmd.cc dflycmd.cc
generic_family.cc hset_family.cc json_family.cc generic_family.cc hset_family.cc json_family.cc
list_family.cc main_service.cc rdb_load.cc rdb_save.cc replica.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 set_family.cc stream_family.cc string_family.cc
zset_family.cc version.cc) zset_family.cc version.cc)

View File

@ -122,6 +122,9 @@ extern std::atomic_uint64_t used_mem_peak;
extern std::atomic_uint64_t used_mem_current; extern std::atomic_uint64_t used_mem_current;
extern size_t max_memory_limit; extern size_t max_memory_limit;
// malloc memory stats.
int64_t GetMallocCurrentCommitted();
// version 5.11 maps to 511 etc. // version 5.11 maps to 511 etc.
// set upon server start. // set upon server start.
extern unsigned kernel_version; extern unsigned kernel_version;

View File

@ -251,7 +251,7 @@ OpStatus BPopper::Run(Transaction* t, unsigned msec) {
// We got here // We got here
if (!result) { if (!result) {
// cleanups, locks removal etc. // 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); t->Execute(std::move(cb), true);
return result.status(); return result.status();

View File

@ -953,10 +953,11 @@ bool CheckWatchedKeyExpiry(ConnectionContext* cntx, const CommandRegistry& regis
} }
atomic_uint32_t watch_exist_count{0}; 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()); ArgSlice args = t->ShardArgsInShard(shard->shard_id());
auto res = GenericFamily::OpExists(t->GetOpArgs(shard), args); auto res = GenericFamily::OpExists(t->GetOpArgs(shard), args);
watch_exist_count.fetch_add(res.value_or(0), memory_order_relaxed); watch_exist_count.fetch_add(res.value_or(0), memory_order_relaxed);
return OpStatus::OK; return OpStatus::OK;
}; };

View File

@ -0,0 +1,23 @@
// Copyright 2022, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.
//
// clang-format off
#include <mimalloc.h>
#include <mimalloc-types.h>
// 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

View File

@ -8,7 +8,7 @@
#include <absl/random/random.h> // for master_id_ generation. #include <absl/random/random.h> // for master_id_ generation.
#include <absl/strings/match.h> #include <absl/strings/match.h>
#include <absl/strings/str_join.h> #include <absl/strings/str_join.h>
#include <mimalloc-types.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <chrono> #include <chrono>
@ -56,8 +56,6 @@ ABSL_DECLARE_FLAG(uint32_t, port);
ABSL_DECLARE_FLAG(bool, cache_mode); ABSL_DECLARE_FLAG(bool, cache_mode);
ABSL_DECLARE_FLAG(uint32_t, hz); ABSL_DECLARE_FLAG(uint32_t, hz);
extern "C" mi_stats_t _mi_stats_main;
namespace dfly { namespace dfly {
namespace fibers = ::boost::fibers; namespace fibers = ::boost::fibers;
@ -172,9 +170,6 @@ class RdbSnapshot {
} }
private: private:
// whether this RdbSnapshot captures only a single shard,
// false for legacy - rdb snapshot that captures
bool single_shard_;
bool started_ = false; bool started_ = false;
unique_ptr<uring::LinuxFile> file_; unique_ptr<uring::LinuxFile> file_;
@ -561,7 +556,7 @@ void PrintPrometheusMetrics(const Metrics& m, StringResponse* resp) {
&resp->body()); &resp->body());
AppendMetricWithoutLabels("memory_used_peak_bytes", "", used_mem_peak.load(memory_order_relaxed), AppendMetricWithoutLabels("memory_used_peak_bytes", "", used_mem_peak.load(memory_order_relaxed),
MetricType::GAUGE, &resp->body()); MetricType::GAUGE, &resp->body());
AppendMetricWithoutLabels("comitted_memory", "", _mi_stats_main.committed.current, AppendMetricWithoutLabels("comitted_memory", "", GetMallocCurrentCommitted(),
MetricType::GAUGE, &resp->body()); MetricType::GAUGE, &resp->body());
AppendMetricWithoutLabels("memory_max_bytes", "", max_memory_limit, MetricType::GAUGE, AppendMetricWithoutLabels("memory_max_bytes", "", max_memory_limit, MetricType::GAUGE,
&resp->body()); &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_human", HumanReadableNumBytes(m.heap_used_bytes));
append("used_memory_peak", used_mem_peak.load(memory_order_relaxed)); 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()) { if (sdata_res.has_value()) {
append("used_memory_rss", sdata_res->vm_rss); append("used_memory_rss", sdata_res->vm_rss);