From fa3290c44efbb3546f22f7457c758ab504623b58 Mon Sep 17 00:00:00 2001 From: c8ef Date: Tue, 27 Aug 2024 19:17:32 +0800 Subject: [PATCH] chore: Enable -Werror=unused-parameter flag (#2507) --- CMakeLists.txt | 1 + src/cli/main.cc | 2 +- src/cli/signal_util.h | 2 +- src/cluster/cluster.cc | 2 +- src/cluster/replication.h | 8 ++- src/cluster/sync_migrate_context.cc | 2 +- src/commands/cmd_cluster.cc | 6 +- src/commands/cmd_function.cc | 2 +- src/commands/cmd_geo.cc | 4 +- src/commands/cmd_json.cc | 4 +- src/commands/cmd_list.cc | 2 +- src/commands/cmd_pubsub.cc | 12 ++-- src/commands/cmd_replication.cc | 12 ++-- src/commands/cmd_script.cc | 4 +- src/commands/cmd_search.cc | 2 +- src/commands/cmd_server.cc | 30 ++++----- src/commands/cmd_stream.cc | 18 +++--- src/commands/cmd_txn.cc | 2 +- src/commands/commander.h | 7 ++- src/commands/scan_base.h | 2 +- src/common/io_util.cc | 13 ++-- src/common/rdb_stream.h | 4 +- src/config/config.cc | 77 ++++++++++++----------- src/config/config_type.h | 4 +- src/search/indexer.cc | 2 +- src/search/passes/cost_model.h | 8 +-- src/server/redis_connection.cc | 4 +- src/server/worker.cc | 8 ++- src/storage/batch_extractor.cc | 5 +- src/storage/compact_filter.cc | 13 ++-- src/storage/compact_filter.h | 19 +++--- src/storage/event_listener.cc | 8 +-- src/storage/rdb.cc | 2 +- src/storage/rdb_ziplist.cc | 12 ++-- src/storage/scripting.cc | 2 +- src/storage/storage.cc | 11 ++-- src/storage/table_properties_collector.cc | 2 +- src/types/redis_bitmap_string.cc | 2 +- src/vendor/rand.cc | 5 -- utils/kvrocks2redis/main.cc | 2 +- 40 files changed, 174 insertions(+), 153 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 78d0581da94..635c18a7994 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -239,6 +239,7 @@ add_library(kvrocks_objs OBJECT ${KVROCKS_SRCS}) target_include_directories(kvrocks_objs PUBLIC src src/common src/vendor ${PROJECT_BINARY_DIR} ${Backtrace_INCLUDE_DIR}) target_compile_features(kvrocks_objs PUBLIC cxx_std_17) target_compile_options(kvrocks_objs PUBLIC -Wall -Wpedantic -Wsign-compare -Wreturn-type -fno-omit-frame-pointer) +target_compile_options(kvrocks_objs PUBLIC -Werror=unused-parameter) target_compile_options(kvrocks_objs PUBLIC -Werror=unused-result) # disable unused-variable check on GCC < 8 due to the structure bindings diff --git a/src/cli/main.cc b/src/cli/main.cc index 32c957a4ed5..a6ed2025873 100644 --- a/src/cli/main.cc +++ b/src/cli/main.cc @@ -47,7 +47,7 @@ Server *srv = nullptr; -extern "C" void SignalHandler(int sig) { +extern "C" void SignalHandler([[maybe_unused]] int sig) { if (srv && !srv->IsStopped()) { LOG(INFO) << "Bye Bye"; srv->Stop(); diff --git a/src/cli/signal_util.h b/src/cli/signal_util.h index d6f02e614aa..8df0b3e01ce 100644 --- a/src/cli/signal_util.h +++ b/src/cli/signal_util.h @@ -30,7 +30,7 @@ #include "version_util.h" -extern "C" inline void SegvHandler(int sig, siginfo_t *info, void *secret) { +extern "C" inline void SegvHandler(int sig, [[maybe_unused]] siginfo_t *info, [[maybe_unused]] void *secret) { LOG(ERROR) << "Ooops! Apache Kvrocks " << PrintVersion << " got signal: " << strsignal(sig) << " (" << sig << ")"; auto trace = cpptrace::generate_trace(); trace.print(LOG(ERROR)); diff --git a/src/cluster/cluster.cc b/src/cluster/cluster.cc index 69703f7eed0..dc3bdc87325 100644 --- a/src/cluster/cluster.cc +++ b/src/cluster/cluster.cc @@ -353,7 +353,7 @@ Status Cluster::ImportSlotRange(redis::Connection *conn, const SlotRange &slot_r conn->SetImporting(); myself_->importing_slot_range = slot_range; // Set link error callback - conn->close_cb = [object_ptr = srv_->slot_import.get(), slot_range](int fd) { + conn->close_cb = [object_ptr = srv_->slot_import.get(), slot_range]([[maybe_unused]] int fd) { auto s = object_ptr->StopForLinkError(); if (!s.IsOK()) { LOG(ERROR) << fmt::format("[import] Failed to stop importing slot(s) {}: {}", slot_range.String(), s.Msg()); diff --git a/src/cluster/replication.h b/src/cluster/replication.h index 8da25713920..e499de8bcec 100644 --- a/src/cluster/replication.h +++ b/src/cluster/replication.h @@ -217,11 +217,13 @@ class ReplicationThread : private EventCallbackBase { class WriteBatchHandler : public rocksdb::WriteBatch::Handler { public: rocksdb::Status PutCF(uint32_t column_family_id, const rocksdb::Slice &key, const rocksdb::Slice &value) override; - rocksdb::Status DeleteCF(uint32_t column_family_id, const rocksdb::Slice &key) override { + rocksdb::Status DeleteCF([[maybe_unused]] uint32_t column_family_id, + [[maybe_unused]] const rocksdb::Slice &key) override { return rocksdb::Status::OK(); } - rocksdb::Status DeleteRangeCF(uint32_t column_family_id, const rocksdb::Slice &begin_key, - const rocksdb::Slice &end_key) override { + rocksdb::Status DeleteRangeCF([[maybe_unused]] uint32_t column_family_id, + [[maybe_unused]] const rocksdb::Slice &begin_key, + [[maybe_unused]] const rocksdb::Slice &end_key) override { return rocksdb::Status::OK(); } WriteBatchType Type() { return type_; } diff --git a/src/cluster/sync_migrate_context.cc b/src/cluster/sync_migrate_context.cc index f1de89b6e26..a7caf73c853 100644 --- a/src/cluster/sync_migrate_context.cc +++ b/src/cluster/sync_migrate_context.cc @@ -51,7 +51,7 @@ void SyncMigrateContext::OnEvent(bufferevent *bev, int16_t events) { conn_->OnEvent(bev, events); } -void SyncMigrateContext::TimerCB(int, int16_t events) { +void SyncMigrateContext::TimerCB(int, [[maybe_unused]] int16_t events) { auto &&slot_migrator = srv_->slot_migrator; conn_->Reply(conn_->NilString()); diff --git a/src/commands/cmd_cluster.cc b/src/commands/cmd_cluster.cc index 958e261d97a..9f4aa27d8dc 100644 --- a/src/commands/cmd_cluster.cc +++ b/src/commands/cmd_cluster.cc @@ -329,7 +329,7 @@ static uint64_t GenerateClusterFlag(uint64_t flags, const std::vectorEnableFlag(redis::Connection::kReadOnly); return Status::OK(); @@ -338,7 +338,7 @@ class CommandReadOnly : public Commander { class CommandReadWrite : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { *output = redis::SimpleString("OK"); conn->DisableFlag(redis::Connection::kReadOnly); return Status::OK(); @@ -347,7 +347,7 @@ class CommandReadWrite : public Commander { class CommandAsking : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { conn->EnableFlag(redis::Connection::kAsking); *output = redis::SimpleString("OK"); return Status::OK(); diff --git a/src/commands/cmd_function.cc b/src/commands/cmd_function.cc index 475ed72481f..c28eed12fa6 100644 --- a/src/commands/cmd_function.cc +++ b/src/commands/cmd_function.cc @@ -85,7 +85,7 @@ struct CommandFunction : Commander { template struct CommandFCall : Commander { - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { int64_t numkeys = GET_OR_RET(ParseInt(args_[2], 10)); if (numkeys > int64_t(args_.size() - 3)) { return {Status::NotOK, "Number of keys can't be greater than number of args"}; diff --git a/src/commands/cmd_geo.cc b/src/commands/cmd_geo.cc index 4c01a665f70..80dc62e8adf 100644 --- a/src/commands/cmd_geo.cc +++ b/src/commands/cmd_geo.cc @@ -631,7 +631,9 @@ class CommandGeoSearchStore : public CommandGeoSearch { return Status::OK(); } - static std::vector Range(const std::vector &args) { return {{1, 1, 1}, {2, 2, 1}}; } + static std::vector Range([[maybe_unused]] const std::vector &args) { + return {{1, 1, 1}, {2, 2, 1}}; + } private: bool store_distance_ = false; diff --git a/src/commands/cmd_json.cc b/src/commands/cmd_json.cc index 571b96074aa..1b9c1b32511 100644 --- a/src/commands/cmd_json.cc +++ b/src/commands/cmd_json.cc @@ -348,7 +348,7 @@ class CommandJsonMerge : public Commander { class CommandJsonArrPop : public Commander { public: - Status Parse(const std::vector &args) override { + Status Parse([[maybe_unused]] const std::vector &args) override { path_ = (args_.size() > 2) ? args_[2] : "$"; if (args_.size() == 4) { @@ -417,7 +417,7 @@ class CommandJsonObjLen : public Commander { class CommandJsonArrTrim : public Commander { public: - Status Parse(const std::vector &args) override { + Status Parse([[maybe_unused]] const std::vector &args) override { path_ = args_[2]; start_ = GET_OR_RET(ParseInt(args_[3], 10)); stop_ = GET_OR_RET(ParseInt(args_[4], 10)); diff --git a/src/commands/cmd_list.cc b/src/commands/cmd_list.cc index 1cc11ec9f39..132ffcc5c57 100644 --- a/src/commands/cmd_list.cc +++ b/src/commands/cmd_list.cc @@ -684,7 +684,7 @@ class CommandRPopLPUSH : public Commander { class CommandLMove : public Commander { public: - Status Parse(const std::vector &args) override { + Status Parse([[maybe_unused]] const std::vector &args) override { auto arg_val = util::ToLower(args_[3]); if (arg_val != "left" && arg_val != "right") { return {Status::RedisParseErr, errInvalidSyntax}; diff --git a/src/commands/cmd_pubsub.cc b/src/commands/cmd_pubsub.cc index 0d67c49de85..f8c8ca01605 100644 --- a/src/commands/cmd_pubsub.cc +++ b/src/commands/cmd_pubsub.cc @@ -27,7 +27,7 @@ namespace redis { class CommandPublish : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { if (!srv->IsSlave()) { // Compromise: can't replicate a message to sub-replicas in a cascading-like structure. // Replication relies on WAL seq; increasing the seq on a replica will break the replication process, @@ -50,7 +50,7 @@ class CommandPublish : public Commander { class CommandMPublish : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { int total_receivers = 0; engine::Context ctx(srv->storage); for (size_t i = 2; i < args_.size(); i++) { @@ -83,7 +83,7 @@ void SubscribeCommandReply(const Connection *conn, std::string *output, const st class CommandSubscribe : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { for (unsigned i = 1; i < args_.size(); i++) { conn->SubscribeChannel(args_[i]); SubscribeCommandReply(conn, output, "subscribe", args_[i], @@ -95,7 +95,7 @@ class CommandSubscribe : public Commander { class CommandUnSubscribe : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { if (args_.size() == 1) { conn->UnsubscribeAll([conn, output](const std::string &sub_name, int num) { SubscribeCommandReply(conn, output, "unsubscribe", sub_name, num); @@ -113,7 +113,7 @@ class CommandUnSubscribe : public Commander { class CommandPSubscribe : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { for (size_t i = 1; i < args_.size(); i++) { conn->PSubscribeChannel(args_[i]); SubscribeCommandReply(conn, output, "psubscribe", args_[i], @@ -125,7 +125,7 @@ class CommandPSubscribe : public Commander { class CommandPUnSubscribe : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { if (args_.size() == 1) { conn->PUnsubscribeAll([conn, output](const std::string &sub_name, int num) { SubscribeCommandReply(conn, output, "punsubscribe", sub_name, num); diff --git a/src/commands/cmd_replication.cc b/src/commands/cmd_replication.cc index 91fdcae9d8e..cb2869e3426 100644 --- a/src/commands/cmd_replication.cc +++ b/src/commands/cmd_replication.cc @@ -186,7 +186,7 @@ class CommandReplConf : public Commander { return Status::OK(); } - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { if (port_ != 0) { conn->SetListeningPort(port_); } @@ -204,9 +204,9 @@ class CommandReplConf : public Commander { class CommandFetchMeta : public Commander { public: - Status Parse(const std::vector &args) override { return Status::OK(); } + Status Parse([[maybe_unused]] const std::vector &args) override { return Status::OK(); } - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, [[maybe_unused]] std::string *output) override { int repl_fd = conn->GetFD(); std::string ip = conn->GetAnnounceIP(); @@ -262,7 +262,7 @@ class CommandFetchFile : public Commander { return Status::OK(); } - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, [[maybe_unused]] std::string *output) override { std::vector files = util::Split(files_str_, ","); int repl_fd = conn->GetFD(); @@ -332,9 +332,9 @@ class CommandFetchFile : public Commander { class CommandDBName : public Commander { public: - Status Parse(const std::vector &args) override { return Status::OK(); } + Status Parse([[maybe_unused]] const std::vector &args) override { return Status::OK(); } - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, [[maybe_unused]] std::string *output) override { conn->Reply(srv->storage->GetName() + CRLF); return Status::OK(); } diff --git a/src/commands/cmd_script.cc b/src/commands/cmd_script.cc index 71bd32cf81c..ec440ba29f4 100644 --- a/src/commands/cmd_script.cc +++ b/src/commands/cmd_script.cc @@ -29,7 +29,7 @@ namespace redis { template class CommandEvalImpl : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { if (evalsha && args_[1].size() != 40) { return {Status::RedisNoScript, errNoMatchingScript}; } @@ -62,7 +62,7 @@ class CommandScript : public Commander { return Status::OK(); } - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { // There's a little tricky here since the script command was the write type // command but some subcommands like `exists` were readonly, so we want to allow // executing on slave here. Maybe we should find other way to do this. diff --git a/src/commands/cmd_search.cc b/src/commands/cmd_search.cc index 1cd42b4bff0..7dbaa4af02b 100644 --- a/src/commands/cmd_search.cc +++ b/src/commands/cmd_search.cc @@ -254,7 +254,7 @@ static StatusOr ParseSQLQuery(const std::vector &args) override { + Status Parse([[maybe_unused]] const std::vector &args) override { auto [parser, ir] = GET_OR_RET(ParseSQLQuery(args_)); ir_ = std::move(ir); diff --git a/src/commands/cmd_server.cc b/src/commands/cmd_server.cc index 1603f0f1892..445f20d4601 100644 --- a/src/commands/cmd_server.cc +++ b/src/commands/cmd_server.cc @@ -187,7 +187,7 @@ class CommandFlushAll : public Commander { class CommandPing : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { if (args_.size() == 1) { *output = redis::SimpleString("PONG"); } else if (args_.size() == 2) { @@ -201,7 +201,7 @@ class CommandPing : public Commander { class CommandSelect : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { *output = redis::SimpleString("OK"); return Status::OK(); } @@ -296,7 +296,7 @@ class CommandMemory : public CommandDisk {}; class CommandRole : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { srv->GetRoleInfo(output); return Status::OK(); } @@ -343,7 +343,7 @@ class CommandPerfLog : public Commander { return Status::OK(); } - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { auto perf_log = srv->GetPerfLog(); if (subcommand_ == "len") { *output = redis::Integer(static_cast(perf_log->Size())); @@ -380,7 +380,7 @@ class CommandSlowlog : public Commander { return Status::OK(); } - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { auto slowlog = srv->GetSlowLog(); if (subcommand_ == "reset") { slowlog->Reset(); @@ -527,7 +527,7 @@ class CommandClient : public Commander { class CommandMonitor : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { conn->Owner()->BecomeMonitorConn(conn); *output = redis::SimpleString("OK"); return Status::OK(); @@ -536,7 +536,7 @@ class CommandMonitor : public Commander { class CommandShutdown : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, Connection *conn, [[maybe_unused]] std::string *output) override { if (!conn->IsAdmin()) { return {Status::RedisExecErr, errAdminPermissionRequired}; } @@ -551,7 +551,7 @@ class CommandShutdown : public Commander { class CommandQuit : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { conn->EnableFlag(redis::Connection::kCloseAfterReply); *output = redis::SimpleString("OK"); return Status::OK(); @@ -652,7 +652,7 @@ class CommandDebug : public Commander { class CommandCommand : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { if (args_.size() == 1) { CommandTable::GetAllCommandsInfo(output); } else { @@ -697,7 +697,7 @@ class CommandCommand : public Commander { class CommandEcho : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { *output = redis::BulkString(args_[1]); return Status::OK(); } @@ -705,7 +705,7 @@ class CommandEcho : public Commander { class CommandTime : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { uint64_t now = util::GetTimeStampUS(); uint64_t s = now / 1000 / 1000; // unix time in seconds. uint64_t us = now - (s * 1000 * 1000); // microseconds. @@ -820,8 +820,8 @@ class CommandScan : public CommandScanBase { public: CommandScan() : CommandScanBase() {} - static std::string GenerateOutput(Server *srv, const Connection *conn, const std::vector &keys, - const std::string &end_cursor) { + static std::string GenerateOutput(Server *srv, [[maybe_unused]] const Connection *conn, + const std::vector &keys, const std::string &end_cursor) { std::vector list; if (!end_cursor.empty()) { list.emplace_back( @@ -1011,7 +1011,7 @@ class CommandSlaveOf : public Commander { class CommandStats : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute(Server *srv, [[maybe_unused]] Connection *conn, std::string *output) override { std::string stats_json = srv->GetRocksDBStatsJson(); *output = redis::BulkString(stats_json); return Status::OK(); @@ -1210,7 +1210,7 @@ class CommandApplyBatch : public Commander { return Commander::Parse(args); } - Status Execute(Server *svr, Connection *conn, std::string *output) override { + Status Execute(Server *svr, [[maybe_unused]] Connection *conn, std::string *output) override { size_t size = raw_batch_.size(); auto options = svr->storage->DefaultWriteOptions(); options.low_pri = low_pri_; diff --git a/src/commands/cmd_stream.cc b/src/commands/cmd_stream.cc index 35ec15cbecd..f02d5b34d13 100644 --- a/src/commands/cmd_stream.cc +++ b/src/commands/cmd_stream.cc @@ -424,7 +424,8 @@ class CommandAutoClaim : public Commander { } private: - Status sendResults(Connection *conn, const StreamAutoClaimResult &result, std::string *output) const { + Status sendResults([[maybe_unused]] Connection *conn, const StreamAutoClaimResult &result, + std::string *output) const { output->append(redis::MultiLen(3)); output->append(redis::BulkString(result.next_claim_id)); output->append(redis::MultiLen(result.entries.size())); @@ -893,7 +894,8 @@ class CommandXPending : public Commander { return SendResults(conn, output, results); } - static Status SendResults(Connection *conn, std::string *output, StreamGetPendingEntryResult &results) { + static Status SendResults([[maybe_unused]] Connection *conn, std::string *output, + StreamGetPendingEntryResult &results) { output->append(redis::MultiLen(3 + results.consumer_infos.size())); output->append(redis::Integer(results.pending_number)); output->append(redis::BulkString(results.first_entry_id.ToString())); @@ -908,7 +910,8 @@ class CommandXPending : public Commander { return Status::OK(); } - static Status SendExtResults(Connection *conn, std::string *output, std::vector &ext_results) { + static Status SendExtResults([[maybe_unused]] Connection *conn, std::string *output, + std::vector &ext_results) { output->append(redis::MultiLen(ext_results.size())); for (const auto &entry : ext_results) { output->append(redis::MultiLen(4)); @@ -1265,7 +1268,8 @@ class CommandXRead : public Commander, return Status::OK(); } - Status BlockingRead(const engine::Context &ctx, Server *srv, Connection *conn, redis::Stream *stream_db) { + Status BlockingRead([[maybe_unused]] const engine::Context &ctx, Server *srv, Connection *conn, + redis::Stream *stream_db) { if (!with_count_) { with_count_ = true; count_ = blocked_default_count_; @@ -1380,7 +1384,7 @@ class CommandXRead : public Commander, conn_->OnEvent(bev, events); } - void TimerCB(int, int16_t events) { + void TimerCB(int, [[maybe_unused]] int16_t events) { conn_->Reply(conn_->NilString()); timer_.reset(); @@ -1570,7 +1574,7 @@ class CommandXReadGroup : public Commander, return Status::OK(); } - Status BlockingRead(Server *srv, Connection *conn, redis::Stream *stream_db) { + Status BlockingRead(Server *srv, Connection *conn, [[maybe_unused]] redis::Stream *stream_db) { if (!with_count_) { with_count_ = true; count_ = blocked_default_count_; @@ -1673,7 +1677,7 @@ class CommandXReadGroup : public Commander, conn_->OnEvent(bev, events); } - void TimerCB(int, int16_t events) { + void TimerCB(int, [[maybe_unused]] int16_t events) { conn_->Reply(conn_->NilString()); timer_.reset(); diff --git a/src/commands/cmd_txn.cc b/src/commands/cmd_txn.cc index 3e2495d2e6f..fcd74e8fd73 100644 --- a/src/commands/cmd_txn.cc +++ b/src/commands/cmd_txn.cc @@ -29,7 +29,7 @@ namespace redis { class CommandMulti : public Commander { public: - Status Execute(Server *srv, Connection *conn, std::string *output) override { + Status Execute([[maybe_unused]] Server *srv, Connection *conn, std::string *output) override { if (conn->IsFlagEnabled(Connection::kMultiExec)) { return {Status::RedisExecErr, "MULTI calls can not be nested"}; } diff --git a/src/commands/commander.h b/src/commands/commander.h index 39d55bfc6f2..9d8dd23932d 100644 --- a/src/commands/commander.h +++ b/src/commands/commander.h @@ -99,8 +99,9 @@ class Commander { const CommandAttributes *GetAttributes() const { return attributes_; } void SetArgs(const std::vector &args) { args_ = args; } virtual Status Parse() { return Parse(args_); } - virtual Status Parse(const std::vector &args) { return Status::OK(); } - virtual Status Execute(Server *srv, Connection *conn, std::string *output) { + virtual Status Parse([[maybe_unused]] const std::vector &args) { return Status::OK(); } + virtual Status Execute([[maybe_unused]] Server *srv, [[maybe_unused]] Connection *conn, + [[maybe_unused]] std::string *output) { return {Status::RedisExecErr, errNotImplemented}; } @@ -114,7 +115,7 @@ class Commander { class CommanderWithParseMove : Commander { public: Status Parse() override { return ParseMove(std::move(args_)); } - virtual Status ParseMove(std::vector &&args) { return Status::OK(); } + virtual Status ParseMove([[maybe_unused]] std::vector &&args) { return Status::OK(); } }; using CommanderFactory = std::function()>; diff --git a/src/commands/scan_base.h b/src/commands/scan_base.h index 3a6438c2f09..007e49ff1e8 100644 --- a/src/commands/scan_base.h +++ b/src/commands/scan_base.h @@ -80,7 +80,7 @@ class CommandScanBase : public Commander { } } - std::string GenerateOutput(Server *srv, const Connection *conn, const std::vector &keys, + std::string GenerateOutput(Server *srv, [[maybe_unused]] const Connection *conn, const std::vector &keys, CursorType cursor_type) const { std::vector list; if (keys.size() == static_cast(limit_)) { diff --git a/src/common/io_util.cc b/src/common/io_util.cc index 1bdc8522cd8..35fa80d9472 100644 --- a/src/common/io_util.cc +++ b/src/common/io_util.cc @@ -271,7 +271,7 @@ Status SockSendFileImpl(FD out_fd, int in_fd, size_t size, Args... args) { // please note that, the out socket fd should be in blocking mode. Status SockSendFile(int out_fd, int in_fd, size_t size) { return SockSendFileImpl(out_fd, in_fd, size); } -Status SockSendFile(int out_fd, int in_fd, size_t size, ssl_st *ssl) { +Status SockSendFile(int out_fd, int in_fd, size_t size, [[maybe_unused]] ssl_st *ssl) { #ifdef ENABLE_OPENSSL if (ssl) { #if OPENSSL_VERSION_NUMBER >= 0x30000000L @@ -284,7 +284,7 @@ Status SockSendFile(int out_fd, int in_fd, size_t size, ssl_st *ssl) { return SockSendFile(out_fd, in_fd, size); } -Status SockSendFile(int out_fd, int in_fd, size_t size, bufferevent *bev) { +Status SockSendFile(int out_fd, int in_fd, size_t size, [[maybe_unused]] bufferevent *bev) { #ifdef ENABLE_OPENSSL return SockSendFile(out_fd, in_fd, size, bufferevent_openssl_get_ssl(bev)); #else @@ -454,7 +454,7 @@ Status Write(int fd, const std::string &data) { return WriteImpl(fd, data Status Pwrite(int fd, const std::string &data, off_t offset) { return WriteImpl(fd, data, offset); } -Status SockSend(int fd, const std::string &data, ssl_st *ssl) { +Status SockSend(int fd, const std::string &data, [[maybe_unused]] ssl_st *ssl) { #ifdef ENABLE_OPENSSL if (ssl) { return WriteImpl(ssl, data); @@ -463,7 +463,7 @@ Status SockSend(int fd, const std::string &data, ssl_st *ssl) { return SockSend(fd, data); } -Status SockSend(int fd, const std::string &data, bufferevent *bev) { +Status SockSend(int fd, const std::string &data, [[maybe_unused]] bufferevent *bev) { #ifdef ENABLE_OPENSSL return SockSend(fd, data, bufferevent_openssl_get_ssl(bev)); #else @@ -471,7 +471,8 @@ Status SockSend(int fd, const std::string &data, bufferevent *bev) { #endif } -StatusOr SockConnect(const std::string &host, uint32_t port, ssl_st *ssl, int conn_timeout, int timeout) { +StatusOr SockConnect(const std::string &host, uint32_t port, [[maybe_unused]] ssl_st *ssl, int conn_timeout, + int timeout) { #ifdef ENABLE_OPENSSL if (ssl) { auto fd = GET_OR_RET(SockConnect(host, port, conn_timeout, timeout)); @@ -491,7 +492,7 @@ StatusOr SockConnect(const std::string &host, uint32_t port, ssl_st *ssl, i return SockConnect(host, port, conn_timeout, timeout); } -StatusOr EvbufferRead(evbuffer *buf, evutil_socket_t fd, int howmuch, ssl_st *ssl) { +StatusOr EvbufferRead(evbuffer *buf, evutil_socket_t fd, int howmuch, [[maybe_unused]] ssl_st *ssl) { #ifdef ENABLE_OPENSSL if (ssl) { constexpr int BUFFER_SIZE = 4096; diff --git a/src/common/rdb_stream.h b/src/common/rdb_stream.h index 824808ae052..004b5b89704 100644 --- a/src/common/rdb_stream.h +++ b/src/common/rdb_stream.h @@ -72,7 +72,9 @@ class RdbFileStream : public RdbStream { Status Open(); Status Read(char *buf, size_t len) override; - Status Write(const char *buf, size_t len) override { return {Status::NotOK, fmt::format("No implement")}; }; + Status Write([[maybe_unused]] const char *buf, [[maybe_unused]] size_t len) override { + return {Status::NotOK, fmt::format("No implement")}; + }; StatusOr GetCheckSum() const override { uint64_t crc = check_sum_; memrev64ifbe(&crc); diff --git a/src/config/config.cc b/src/config/config.cc index dcb504f9def..1fbfe928f97 100644 --- a/src/config/config.cc +++ b/src/config/config.cc @@ -271,7 +271,7 @@ Config::Config() { void Config::initFieldValidator() { std::map validators = { {"requirepass", - [this](const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] const std::string &k, const std::string &v) -> Status { if (v.empty() && !load_tokens.empty()) { return {Status::NotOK, "requirepass empty not allowed while the namespace exists"}; } @@ -281,29 +281,29 @@ void Config::initFieldValidator() { return Status::OK(); }}, {"masterauth", - [this](const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] const std::string &k, const std::string &v) -> Status { if (load_tokens.find(v) != load_tokens.end()) { return {Status::NotOK, "masterauth is duplicated with namespace tokens"}; } return Status::OK(); }}, {"compact-cron", - [this](const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] const std::string &k, const std::string &v) -> Status { std::vector args = util::Split(v, " \t"); return compact_cron.SetScheduleTime(args); }}, {"bgsave-cron", - [this](const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] const std::string &k, const std::string &v) -> Status { std::vector args = util::Split(v, " \t"); return bgsave_cron.SetScheduleTime(args); }}, {"dbsize-scan-cron", - [this](const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] const std::string &k, const std::string &v) -> Status { std::vector args = util::Split(v, " \t"); return dbsize_scan_cron.SetScheduleTime(args); }}, {"compaction-checker-range", - [this](const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] const std::string &k, const std::string &v) -> Status { if (!compaction_checker_cron_str_.empty()) { return {Status::NotOK, "compaction-checker-range cannot be set while compaction-checker-cron is set"}; } @@ -314,12 +314,12 @@ void Config::initFieldValidator() { return compaction_checker_cron.SetScheduleTime({"*", v, "*", "*", "*"}); }}, {"compaction-checker-cron", - [this](const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] const std::string &k, const std::string &v) -> Status { std::vector args = util::Split(v, " \t"); return compaction_checker_cron.SetScheduleTime(args); }}, {"rename-command", - [](const std::string &k, const std::string &v) -> Status { + []([[maybe_unused]] const std::string &k, const std::string &v) -> Status { std::vector all_args = util::Split(v, "\n"); for (auto &p : all_args) { std::vector args = util::Split(p, " \t"); @@ -363,7 +363,8 @@ void Config::initFieldCallback() { if (!srv) return Status::OK(); // srv is nullptr when load config from file return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), v); }; - auto set_compression_type_cb = [](Server *srv, const std::string &k, const std::string &v) -> Status { + auto set_compression_type_cb = [](Server *srv, [[maybe_unused]] const std::string &k, + const std::string &v) -> Status { if (!srv) return Status::OK(); std::string compression_option; @@ -388,7 +389,7 @@ void Config::initFieldCallback() { return srv->storage->SetOptionForAllColumnFamilies("compression_per_level", compression_levels); }; #ifdef ENABLE_OPENSSL - auto set_tls_option = [](Server *srv, const std::string &k, const std::string &v) { + auto set_tls_option = [](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) { if (!srv) return Status::OK(); // srv is nullptr when load config from file auto new_ctx = CreateSSLContext(srv->GetConfig()); if (!new_ctx) { @@ -402,13 +403,14 @@ void Config::initFieldCallback() { std::map callbacks = { {"workers", - [](Server *srv, const std::string &k, const std::string &v) -> Status { + [](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); srv->AdjustWorkerThreads(); return Status::OK(); }}, {"dir", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] Server *srv, [[maybe_unused]] const std::string &k, + [[maybe_unused]] const std::string &v) -> Status { db_dir = dir + "/db"; if (log_dir.empty()) log_dir = dir; checkpoint_dir = dir + "/checkpoint"; @@ -419,7 +421,7 @@ void Config::initFieldCallback() { return Status::OK(); }}, {"backup-dir", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, const std::string &v) -> Status { std::string previous_backup; { // Note: currently, backup_mu_ may block by backing up or purging, @@ -435,24 +437,25 @@ void Config::initFieldCallback() { return Status::OK(); }}, {"cluster-enabled", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] Server *srv, [[maybe_unused]] const std::string &k, + [[maybe_unused]] const std::string &v) -> Status { if (cluster_enabled) slot_id_encoded = true; return Status::OK(); }}, {"bind", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] Server *srv, [[maybe_unused]] const std::string &k, const std::string &v) -> Status { std::vector args = util::Split(v, " \t"); binds = std::move(args); return Status::OK(); }}, {"maxclients", - [](Server *srv, const std::string &k, const std::string &v) -> Status { + [](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); srv->AdjustOpenFilesLimit(); return Status::OK(); }}, {"slaveof", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] Server *srv, [[maybe_unused]] const std::string &k, const std::string &v) -> Status { if (v.empty()) { return Status::OK(); } @@ -469,7 +472,7 @@ void Config::initFieldCallback() { return Status::OK(); }}, {"profiling-sample-commands", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this]([[maybe_unused]] Server *srv, [[maybe_unused]] const std::string &k, const std::string &v) -> Status { std::vector cmds = util::Split(v, ","); profiling_sample_all_commands = false; profiling_sample_commands.clear(); @@ -488,67 +491,67 @@ void Config::initFieldCallback() { return Status::OK(); }}, {"slowlog-max-len", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); srv->GetSlowLog()->SetMaxEntries(slowlog_max_len); return Status::OK(); }}, {"max-db-size", - [](Server *srv, const std::string &k, const std::string &v) -> Status { + [](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); srv->storage->CheckDBSizeLimit(); return Status::OK(); }}, {"max-io-mb", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); srv->storage->SetIORateLimit(max_io_mb); return Status::OK(); }}, {"profiling-sample-record-max-len", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); srv->GetPerfLog()->SetMaxEntries(profiling_sample_record_max_len); return Status::OK(); }}, {"migrate-speed", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); if (cluster_enabled) srv->slot_migrator->SetMaxMigrationSpeed(migrate_speed); return Status::OK(); }}, {"migrate-pipeline-size", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); if (cluster_enabled) srv->slot_migrator->SetMaxPipelineSize(pipeline_size); return Status::OK(); }}, {"migrate-sequence-gap", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); if (cluster_enabled) srv->slot_migrator->SetSequenceGapLimit(sequence_gap); return Status::OK(); }}, {"migrate-batch-rate-limit-mb", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); srv->slot_migrator->SetMigrateBatchRateLimit(migrate_batch_rate_limit_mb * MiB); return Status::OK(); }}, {"migrate-batch-size-kb", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); srv->slot_migrator->SetMigrateBatchSize(migrate_batch_size_kb * KiB); return Status::OK(); }}, {"log-level", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); FLAGS_minloglevel = log_level; return Status::OK(); }}, {"log-retention-days", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); if (util::ToLower(log_dir) == "stdout") { return {Status::NotOK, "can't set the 'log-retention-days' when the log dir is stdout"}; @@ -562,7 +565,7 @@ void Config::initFieldCallback() { return Status::OK(); }}, {"persist-cluster-nodes-enabled", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, [[maybe_unused]] const std::string &k, const std::string &v) -> Status { if (!srv || !cluster_enabled) return Status::OK(); auto nodes_file_path = NodesFilePath(); if (v == "yes") { @@ -573,19 +576,19 @@ void Config::initFieldCallback() { return Status::OK(); }}, {"repl-namespace-enabled", - [](Server *srv, const std::string &k, const std::string &v) -> Status { + [](Server *srv, [[maybe_unused]] const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); return srv->GetNamespace()->LoadAndRewrite(); }}, {"rocksdb.target_file_size_base", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), std::to_string(rocks_db.target_file_size_base * MiB)); }}, {"rocksdb.write_buffer_size", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), std::to_string(rocks_db.write_buffer_size * MiB)); @@ -597,12 +600,12 @@ void Config::initFieldCallback() { return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), disable_auto_compactions); }}, {"rocksdb.max_total_wal_size", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); return srv->storage->SetDBOption(TrimRocksDbPrefix(k), std::to_string(rocks_db.max_total_wal_size * MiB)); }}, {"rocksdb.enable_blob_files", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); std::string enable_blob_files = rocks_db.enable_blob_files ? "true" : "false"; return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), enable_blob_files); @@ -616,7 +619,7 @@ void Config::initFieldCallback() { return srv->storage->SetOptionForAllColumnFamilies(TrimRocksDbPrefix(k), v); }}, {"rocksdb.blob_file_size", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); if (!rocks_db.enable_blob_files) { return {Status::NotOK, errBlobDbNotEnabled}; @@ -659,7 +662,7 @@ void Config::initFieldCallback() { return srv->storage->SetDBOption(TrimRocksDbPrefix(k), level_compaction_dynamic_level_bytes); }}, {"rocksdb.max_bytes_for_level_base", - [this](Server *srv, const std::string &k, const std::string &v) -> Status { + [this](Server *srv, const std::string &k, [[maybe_unused]] const std::string &v) -> Status { if (!srv) return Status::OK(); if (!rocks_db.level_compaction_dynamic_level_bytes) { return {Status::NotOK, errLevelCompactionDynamicLevelBytesNotSet}; diff --git a/src/config/config_type.h b/src/config/config_type.h index 36fa37997b0..c11e369430d 100644 --- a/src/config/config_type.h +++ b/src/config/config_type.h @@ -65,8 +65,8 @@ class ConfigField { virtual std::string ToString() const = 0; virtual std::string ToStringForRewrite() const { return ToString(); } virtual Status Set(const std::string &v) = 0; - virtual Status ToNumber(int64_t *n) const { return {Status::NotOK, "not supported"}; } - virtual Status ToBool(bool *b) const { return {Status::NotOK, "not supported"}; } + virtual Status ToNumber([[maybe_unused]] int64_t *n) const { return {Status::NotOK, "not supported"}; } + virtual Status ToBool([[maybe_unused]] bool *b) const { return {Status::NotOK, "not supported"}; } ConfigType GetConfigType() const { return config_type; } bool IsMultiConfig() const { return config_type == ConfigType::MultiConfig; } diff --git a/src/search/indexer.cc b/src/search/indexer.cc index 79a614374aa..26d653c1c68 100644 --- a/src/search/indexer.cc +++ b/src/search/indexer.cc @@ -242,7 +242,7 @@ Status IndexUpdater::UpdateTagIndex(engine::Context &ctx, std::string_view key, Status IndexUpdater::UpdateNumericIndex(engine::Context &ctx, std::string_view key, const kqir::Value &original, const kqir::Value ¤t, const SearchKey &search_key, - const NumericFieldMetadata *num) const { + [[maybe_unused]] const NumericFieldMetadata *num) const { CHECK(original.IsNull() || original.Is()); CHECK(current.IsNull() || current.Is()); diff --git a/src/search/passes/cost_model.h b/src/search/passes/cost_model.h index 960708d740c..3b648f7d999 100644 --- a/src/search/passes/cost_model.h +++ b/src/search/passes/cost_model.h @@ -58,7 +58,7 @@ struct CostModel { CHECK(false) << "plan operator type not supported"; } - static size_t Visit(const FullIndexScan *node) { return 100; } + static size_t Visit([[maybe_unused]] const FullIndexScan *node) { return 100; } static size_t Visit(const NumericFieldScan *node) { if (node->range.r == IntervalSet::NextNum(node->range.l)) { @@ -78,11 +78,11 @@ struct CostModel { return base; } - static size_t Visit(const TagFieldScan *node) { return 10; } + static size_t Visit([[maybe_unused]] const TagFieldScan *node) { return 10; } - static size_t Visit(const HnswVectorFieldKnnScan *node) { return 3; } + static size_t Visit([[maybe_unused]] const HnswVectorFieldKnnScan *node) { return 3; } - static size_t Visit(const HnswVectorFieldRangeScan *node) { return 4; } + static size_t Visit([[maybe_unused]] const HnswVectorFieldRangeScan *node) { return 4; } static size_t Visit(const Filter *node) { return Transform(node->source.get()) + 1; } diff --git a/src/server/redis_connection.cc b/src/server/redis_connection.cc index 09f53b8b3cd..f7276249e4c 100644 --- a/src/server/redis_connection.cc +++ b/src/server/redis_connection.cc @@ -80,7 +80,7 @@ void Connection::Close() { void Connection::Detach() { owner_->DetachConnection(this); } -void Connection::OnRead(struct bufferevent *bev) { +void Connection::OnRead([[maybe_unused]] struct bufferevent *bev) { is_running_ = true; MakeScopeExit([this] { is_running_ = false; }); @@ -99,7 +99,7 @@ void Connection::OnRead(struct bufferevent *bev) { } } -void Connection::OnWrite(bufferevent *bev) { +void Connection::OnWrite([[maybe_unused]] bufferevent *bev) { if (IsFlagEnabled(kCloseAfterReply) || IsFlagEnabled(kCloseAsync)) { Close(); } diff --git a/src/server/worker.cc b/src/server/worker.cc index 0b37bcef30d..d5a751e1578 100644 --- a/src/server/worker.cc +++ b/src/server/worker.cc @@ -100,13 +100,14 @@ Worker::~Worker() { lua::DestroyState(lua_); } -void Worker::TimerCB(int, int16_t events) { +void Worker::TimerCB(int, [[maybe_unused]] int16_t events) { auto config = srv->GetConfig(); if (config->timeout == 0) return; KickoutIdleClients(config->timeout); } -void Worker::newTCPConnection(evconnlistener *listener, evutil_socket_t fd, sockaddr *address, int socklen) { +void Worker::newTCPConnection(evconnlistener *listener, evutil_socket_t fd, [[maybe_unused]] sockaddr *address, + [[maybe_unused]] int socklen) { int local_port = util::GetLocalPort(fd); // NOLINT DLOG(INFO) << "[worker] New connection: fd=" << fd << " from port: " << local_port << " thread #" << tid_; @@ -186,7 +187,8 @@ void Worker::newTCPConnection(evconnlistener *listener, evutil_socket_t fd, sock } } -void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t fd, sockaddr *address, int socklen) { +void Worker::newUnixSocketConnection(evconnlistener *listener, evutil_socket_t fd, [[maybe_unused]] sockaddr *address, + [[maybe_unused]] int socklen) { DLOG(INFO) << "[worker] New connection: fd=" << fd << " from unixsocket: " << srv->GetConfig()->unixsocket << " thread #" << tid_; event_base *base = evconnlistener_get_base(listener); diff --git a/src/storage/batch_extractor.cc b/src/storage/batch_extractor.cc index e9ac4925d67..8ab8f04ee58 100644 --- a/src/storage/batch_extractor.cc +++ b/src/storage/batch_extractor.cc @@ -396,8 +396,9 @@ rocksdb::Status WriteBatchExtractor::DeleteCF(uint32_t column_family_id, const S return rocksdb::Status::OK(); } -rocksdb::Status WriteBatchExtractor::DeleteRangeCF(uint32_t column_family_id, const Slice &begin_key, - const Slice &end_key) { +rocksdb::Status WriteBatchExtractor::DeleteRangeCF([[maybe_unused]] uint32_t column_family_id, + [[maybe_unused]] const Slice &begin_key, + [[maybe_unused]] const Slice &end_key) { // Do nothing with DeleteRange operations return rocksdb::Status::OK(); } diff --git a/src/storage/compact_filter.cc b/src/storage/compact_filter.cc index 5353608eea9..b79219ec423 100644 --- a/src/storage/compact_filter.cc +++ b/src/storage/compact_filter.cc @@ -33,8 +33,8 @@ namespace engine { using rocksdb::Slice; -bool MetadataFilter::Filter(int level, const Slice &key, const Slice &value, std::string *new_value, - bool *modified) const { +bool MetadataFilter::Filter([[maybe_unused]] int level, const Slice &key, const Slice &value, + [[maybe_unused]] std::string *new_value, [[maybe_unused]] bool *modified) const { Metadata metadata(kRedisNone, false); rocksdb::Status s = metadata.Decode(value); auto [ns, user_key] = ExtractNamespaceKey(key, stor_->IsSlotIdEncoded()); @@ -95,8 +95,9 @@ bool SubKeyFilter::IsMetadataExpired(const InternalKey &ikey, const Metadata &me || metadata.ExpireAt(lazy_expired_ts) || ikey.GetVersion() != metadata.version; } -rocksdb::CompactionFilter::Decision SubKeyFilter::FilterBlobByKey(int level, const Slice &key, std::string *new_value, - std::string *skip_until) const { +rocksdb::CompactionFilter::Decision SubKeyFilter::FilterBlobByKey([[maybe_unused]] int level, const Slice &key, + [[maybe_unused]] std::string *new_value, + [[maybe_unused]] std::string *skip_until) const { InternalKey ikey(key, stor_->IsSlotIdEncoded()); Metadata metadata(kRedisNone, false); Status s = GetMetadata(ikey, &metadata); @@ -117,8 +118,8 @@ rocksdb::CompactionFilter::Decision SubKeyFilter::FilterBlobByKey(int level, con return result ? rocksdb::CompactionFilter::Decision::kRemove : rocksdb::CompactionFilter::Decision::kKeep; } -bool SubKeyFilter::Filter(int level, const Slice &key, const Slice &value, std::string *new_value, - bool *modified) const { +bool SubKeyFilter::Filter([[maybe_unused]] int level, const Slice &key, const Slice &value, + [[maybe_unused]] std::string *new_value, [[maybe_unused]] bool *modified) const { InternalKey ikey(key, stor_->IsSlotIdEncoded()); Metadata metadata(kRedisNone, false); Status s = GetMetadata(ikey, &metadata); diff --git a/src/storage/compact_filter.h b/src/storage/compact_filter.h index 118bb8f6c7b..561ad6b0d05 100644 --- a/src/storage/compact_filter.h +++ b/src/storage/compact_filter.h @@ -47,7 +47,7 @@ class MetadataFilterFactory : public rocksdb::CompactionFilterFactory { explicit MetadataFilterFactory(engine::Storage *storage) : stor_(storage) {} const char *Name() const override { return "MetadataFilterFactory"; } std::unique_ptr CreateCompactionFilter( - const rocksdb::CompactionFilter::Context &context) override { + [[maybe_unused]] const rocksdb::CompactionFilter::Context &context) override { return std::unique_ptr(new MetadataFilter(stor_)); } @@ -78,7 +78,7 @@ class SubKeyFilterFactory : public rocksdb::CompactionFilterFactory { const char *Name() const override { return "SubKeyFilterFactory"; } std::unique_ptr CreateCompactionFilter( - const rocksdb::CompactionFilter::Context &context) override { + [[maybe_unused]] const rocksdb::CompactionFilter::Context &context) override { return std::unique_ptr(new SubKeyFilter(stor_)); } @@ -89,7 +89,8 @@ class SubKeyFilterFactory : public rocksdb::CompactionFilterFactory { class PropagateFilter : public rocksdb::CompactionFilter { public: const char *Name() const override { return "PropagateFilter"; } - bool Filter(int level, const Slice &key, const Slice &value, std::string *new_value, bool *modified) const override { + bool Filter([[maybe_unused]] int level, const Slice &key, [[maybe_unused]] const Slice &value, + [[maybe_unused]] std::string *new_value, [[maybe_unused]] bool *modified) const override { // We propagate Lua commands which don't store data, // just in order to implement updating Lua state. return key == engine::kPropagateScriptCommand; @@ -101,7 +102,7 @@ class PropagateFilterFactory : public rocksdb::CompactionFilterFactory { PropagateFilterFactory() = default; const char *Name() const override { return "PropagateFilterFactory"; } std::unique_ptr CreateCompactionFilter( - const rocksdb::CompactionFilter::Context &context) override { + [[maybe_unused]] const rocksdb::CompactionFilter::Context &context) override { return std::unique_ptr(new PropagateFilter()); } }; @@ -109,7 +110,8 @@ class PropagateFilterFactory : public rocksdb::CompactionFilterFactory { class PubSubFilter : public rocksdb::CompactionFilter { public: const char *Name() const override { return "PubSubFilter"; } - bool Filter(int level, const Slice &key, const Slice &value, std::string *new_value, bool *modified) const override { + bool Filter([[maybe_unused]] int level, [[maybe_unused]] const Slice &key, [[maybe_unused]] const Slice &value, + [[maybe_unused]] std::string *new_value, [[maybe_unused]] bool *modified) const override { return true; } }; @@ -119,7 +121,7 @@ class PubSubFilterFactory : public rocksdb::CompactionFilterFactory { PubSubFilterFactory() = default; const char *Name() const override { return "PubSubFilterFactory"; } std::unique_ptr CreateCompactionFilter( - const rocksdb::CompactionFilter::Context &context) override { + [[maybe_unused]] const rocksdb::CompactionFilter::Context &context) override { return std::unique_ptr(new PubSubFilter()); } }; @@ -127,7 +129,8 @@ class PubSubFilterFactory : public rocksdb::CompactionFilterFactory { class SearchFilter : public rocksdb::CompactionFilter { public: const char *Name() const override { return "SearchFilter"; } - bool Filter(int level, const Slice &key, const Slice &value, std::string *new_value, bool *modified) const override { + bool Filter([[maybe_unused]] int level, [[maybe_unused]] const Slice &key, [[maybe_unused]] const Slice &value, + [[maybe_unused]] std::string *new_value, [[maybe_unused]] bool *modified) const override { // TODO: just a dummy one here return false; } @@ -138,7 +141,7 @@ class SearchFilterFactory : public rocksdb::CompactionFilterFactory { SearchFilterFactory() = default; const char *Name() const override { return "SearchFilterFactory"; } std::unique_ptr CreateCompactionFilter( - const rocksdb::CompactionFilter::Context &context) override { + [[maybe_unused]] const rocksdb::CompactionFilter::Context &context) override { return std::unique_ptr(new SearchFilter()); } }; diff --git a/src/storage/event_listener.cc b/src/storage/event_listener.cc index a32f8b70300..ab1c42338ed 100644 --- a/src/storage/event_listener.cc +++ b/src/storage/event_listener.cc @@ -75,7 +75,7 @@ bool IsDiskQuotaExceeded(const rocksdb::Status &bg_error) { return err_msg.find(exceeded_quota_str) != std::string::npos; } -void EventListener::OnCompactionBegin(rocksdb::DB *db, const rocksdb::CompactionJobInfo &ci) { +void EventListener::OnCompactionBegin([[maybe_unused]] rocksdb::DB *db, const rocksdb::CompactionJobInfo &ci) { LOG(INFO) << "[event_listener/compaction_begin] column family: " << ci.cf_name << ", job_id: " << ci.job_id << ", compaction reason: " << rocksdb::GetCompactionReasonString(ci.compaction_reason) << ", output compression type: " << CompressType2String(ci.compression) @@ -85,7 +85,7 @@ void EventListener::OnCompactionBegin(rocksdb::DB *db, const rocksdb::Compaction << ", is_manual_compaction:" << (ci.stats.is_manual_compaction ? "yes" : "no"); } -void EventListener::OnCompactionCompleted(rocksdb::DB *db, const rocksdb::CompactionJobInfo &ci) { +void EventListener::OnCompactionCompleted([[maybe_unused]] rocksdb::DB *db, const rocksdb::CompactionJobInfo &ci) { LOG(INFO) << "[event_listener/compaction_completed] column family: " << ci.cf_name << ", job_id: " << ci.job_id << ", compaction reason: " << rocksdb::GetCompactionReasonString(ci.compaction_reason) << ", output compression type: " << CompressType2String(ci.compression) @@ -114,12 +114,12 @@ void EventListener::OnSubcompactionCompleted(const rocksdb::SubcompactionJobInfo << ", elapsed(micro): " << si.stats.elapsed_micros; } -void EventListener::OnFlushBegin(rocksdb::DB *db, const rocksdb::FlushJobInfo &fi) { +void EventListener::OnFlushBegin([[maybe_unused]] rocksdb::DB *db, const rocksdb::FlushJobInfo &fi) { LOG(INFO) << "[event_listener/flush_begin] column family: " << fi.cf_name << ", thread_id: " << fi.thread_id << ", job_id: " << fi.job_id << ", reason: " << rocksdb::GetFlushReasonString(fi.flush_reason); } -void EventListener::OnFlushCompleted(rocksdb::DB *db, const rocksdb::FlushJobInfo &fi) { +void EventListener::OnFlushCompleted([[maybe_unused]] rocksdb::DB *db, const rocksdb::FlushJobInfo &fi) { storage_->RecordStat(engine::StatType::FlushCount, 1); storage_->CheckDBSizeLimit(); LOG(INFO) << "[event_listener/flush_completed] column family: " << fi.cf_name << ", thread_id: " << fi.thread_id diff --git a/src/storage/rdb.cc b/src/storage/rdb.cc index 2d684f10ab6..ed55ddcdcd3 100644 --- a/src/storage/rdb.cc +++ b/src/storage/rdb.cc @@ -401,7 +401,7 @@ StatusOr RDB::loadRdbType() { return type; } -StatusOr RDB::loadRdbObject(int type, const std::string &key) { +StatusOr RDB::loadRdbObject(int type, [[maybe_unused]] const std::string &key) { if (type == RDBTypeString) { auto value = GET_OR_RET(LoadStringObject()); return value; diff --git a/src/storage/rdb_ziplist.cc b/src/storage/rdb_ziplist.cc index b51dc8ddadc..ad005661cd9 100644 --- a/src/storage/rdb_ziplist.cc +++ b/src/storage/rdb_ziplist.cc @@ -151,7 +151,7 @@ Status ZipList::peekOK(size_t n) { uint32_t ZipList::getEncodedLengthSize(uint32_t len) { return len < ZipListBigLen ? 1 : 5; } -uint32_t ZipList::ZipStorePrevEntryLengthLarge(unsigned char *p, size_t zl_size, unsigned int len) { +uint32_t ZipList::ZipStorePrevEntryLengthLarge(unsigned char *p, [[maybe_unused]] size_t zl_size, unsigned int len) { uint32_t u32 = 0; if (p != nullptr) { p[0] = ZipListBigLen; @@ -174,7 +174,7 @@ uint32_t ZipList::ZipStorePrevEntryLength(unsigned char *p, size_t zl_size, unsi return ZipStorePrevEntryLengthLarge(p, zl_size, len); } -uint32_t ZipList::ZipStoreEntryEncoding(unsigned char *p, size_t zl_size, unsigned int rawlen) { +uint32_t ZipList::ZipStoreEntryEncoding(unsigned char *p, [[maybe_unused]] size_t zl_size, unsigned int rawlen) { unsigned char len = 1, buf[5]; /* Although encoding is given it may not be set for strings, @@ -202,20 +202,20 @@ uint32_t ZipList::ZipStoreEntryEncoding(unsigned char *p, size_t zl_size, unsign return len; } -void ZipList::SetZipListBytes(unsigned char *zl, size_t zl_size, uint32_t value) { +void ZipList::SetZipListBytes(unsigned char *zl, [[maybe_unused]] size_t zl_size, uint32_t value) { assert(zl_size >= sizeof(uint32_t)); memcpy(zl, &value, sizeof(uint32_t)); } -void ZipList::SetZipListTailOffset(unsigned char *zl, size_t zl_size, uint32_t value) { +void ZipList::SetZipListTailOffset(unsigned char *zl, [[maybe_unused]] size_t zl_size, uint32_t value) { assert(zl_size >= sizeof(uint32_t) * 2); memcpy(zl + sizeof(uint32_t), &value, sizeof(uint32_t)); } -void ZipList::SetZipListLength(unsigned char *zl, size_t zl_size, uint16_t value) { +void ZipList::SetZipListLength(unsigned char *zl, [[maybe_unused]] size_t zl_size, uint16_t value) { assert(zl_size >= sizeof(uint32_t) * 2 + sizeof(uint16_t)); memcpy(zl + sizeof(uint32_t) * 2, &value, sizeof(uint16_t)); } -unsigned char *ZipList::GetZipListEntryHead(unsigned char *zl, size_t zl_size) { +unsigned char *ZipList::GetZipListEntryHead(unsigned char *zl, [[maybe_unused]] size_t zl_size) { assert(zl_size >= zlHeaderSize); return ((zl) + zlHeaderSize); } diff --git a/src/storage/scripting.cc b/src/storage/scripting.cc index 33f133d9836..9d728f74d7d 100644 --- a/src/storage/scripting.cc +++ b/src/storage/scripting.cc @@ -282,7 +282,7 @@ int RedisRegisterFunction(lua_State *lua) { } Status FunctionLoad(redis::Connection *conn, const std::string &script, bool need_to_store, bool replace, - std::string *lib_name, bool read_only) { + [[maybe_unused]] std::string *lib_name, bool read_only) { std::string first_line, lua_code; if (auto pos = script.find('\n'); pos != std::string::npos) { first_line = script.substr(0, pos); diff --git a/src/storage/storage.cc b/src/storage/storage.cc index dae8f326dfc..b5d07d97330 100644 --- a/src/storage/storage.cc +++ b/src/storage/storage.cc @@ -933,14 +933,17 @@ std::string Storage::GetReplIdFromWalBySeq(rocksdb::SequenceNumber seq) { // An extractor to extract update from raw writebatch class ReplIdExtractor : public rocksdb::WriteBatch::Handler { public: - rocksdb::Status PutCF(uint32_t column_family_id, const Slice &key, const Slice &value) override { + rocksdb::Status PutCF([[maybe_unused]] uint32_t column_family_id, [[maybe_unused]] const Slice &key, + [[maybe_unused]] const Slice &value) override { return rocksdb::Status::OK(); } - rocksdb::Status DeleteCF(uint32_t column_family_id, const rocksdb::Slice &key) override { + rocksdb::Status DeleteCF([[maybe_unused]] uint32_t column_family_id, + [[maybe_unused]] const rocksdb::Slice &key) override { return rocksdb::Status::OK(); } - rocksdb::Status DeleteRangeCF(uint32_t column_family_id, const rocksdb::Slice &begin_key, - const rocksdb::Slice &end_key) override { + rocksdb::Status DeleteRangeCF([[maybe_unused]] uint32_t column_family_id, + [[maybe_unused]] const rocksdb::Slice &begin_key, + [[maybe_unused]] const rocksdb::Slice &end_key) override { return rocksdb::Status::OK(); } diff --git a/src/storage/table_properties_collector.cc b/src/storage/table_properties_collector.cc index df760617f49..8e89a56f8d7 100644 --- a/src/storage/table_properties_collector.cc +++ b/src/storage/table_properties_collector.cc @@ -80,7 +80,7 @@ bool CompactOnExpiredCollector::NeedCompact() const { } rocksdb::TablePropertiesCollector *CompactOnExpiredTableCollectorFactory::CreateTablePropertiesCollector( - rocksdb::TablePropertiesCollectorFactory::Context context) { + [[maybe_unused]] rocksdb::TablePropertiesCollectorFactory::Context context) { return new CompactOnExpiredCollector(cf_name_, trigger_threshold_); } diff --git a/src/types/redis_bitmap_string.cc b/src/types/redis_bitmap_string.cc index 1c0dff817ac..1f91ee3d579 100644 --- a/src/types/redis_bitmap_string.cc +++ b/src/types/redis_bitmap_string.cc @@ -263,7 +263,7 @@ rocksdb::Status BitmapString::Bitfield(engine::Context &ctx, const Slice &ns_key return storage_->Write(ctx, storage_->DefaultWriteOptions(), batch->GetWriteBatch()); } -rocksdb::Status BitmapString::BitfieldReadOnly(const Slice &ns_key, const std::string &raw_value, +rocksdb::Status BitmapString::BitfieldReadOnly([[maybe_unused]] const Slice &ns_key, const std::string &raw_value, const std::vector &ops, std::vector> *rets) { std::string_view string_value = raw_value; diff --git a/src/vendor/rand.cc b/src/vendor/rand.cc index 2d6b0a3614a..a164d4253b1 100644 --- a/src/vendor/rand.cc +++ b/src/vendor/rand.cc @@ -106,11 +106,6 @@ constexpr void SEED(const T x0, const T x1, const T x2) { SET3(x, x0, x1, x2), SET3(a, A0, A1, A2), c = C; } -template -constexpr T HiBit(const T x) { - return (1L << (2 * N - 1)); -} - static void Next() { uint32_t p[2], q[2], r[2], carry0 = 0, carry1 = 0; diff --git a/utils/kvrocks2redis/main.cc b/utils/kvrocks2redis/main.cc index e6ca93bf422..8522fd0962a 100644 --- a/utils/kvrocks2redis/main.cc +++ b/utils/kvrocks2redis/main.cc @@ -46,7 +46,7 @@ struct Options { std::string conf_file = kDefaultConfPath; }; -extern "C" void SignalHandler(int sig) { +extern "C" void SignalHandler([[maybe_unused]] int sig) { if (hup_handler) hup_handler(); }