From 2eb389f545317db9e546f019b150e3befdf392ed Mon Sep 17 00:00:00 2001 From: Kaijie Gu <2459548460@qq.com> Date: Tue, 4 Jun 2024 20:53:44 +0800 Subject: [PATCH] fix: modify cmdId assignment time to assgining after registering cmdtable (#2692) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * change cmdId assignment time to assign after intializing cmdtable * 修改 PikaCmdTableManager中 getCmdId,删除pika_command.cc中多余的头文件引用 --- include/pika_cmd_table_manager.h | 2 +- include/pika_command.h | 1 + src/pika_cmd_table_manager.cc | 3 ++- src/pika_command.cc | 3 --- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/pika_cmd_table_manager.h b/include/pika_cmd_table_manager.h index 27393da4ec..8177fa63b9 100644 --- a/include/pika_cmd_table_manager.h +++ b/include/pika_cmd_table_manager.h @@ -34,7 +34,7 @@ class PikaCmdTableManager { std::shared_ptr GetCmd(const std::string& opt); bool CmdExist(const std::string& cmd) const; CmdTable* GetCmdTable(); - uint32_t GetCmdId(); + uint32_t GetMaxCmdId(); std::vector GetAclCategoryCmdNames(uint32_t flag); diff --git a/include/pika_command.h b/include/pika_command.h index 23502dcc45..94bf5fab09 100644 --- a/include/pika_command.h +++ b/include/pika_command.h @@ -563,6 +563,7 @@ class Cmd : public std::enable_shared_from_this { std::shared_ptr GetResp(); void SetStage(CmdStage stage); + void SetCmdId(uint32_t cmdId){cmdId_ = cmdId;} virtual void DoBinlog(); diff --git a/src/pika_cmd_table_manager.cc b/src/pika_cmd_table_manager.cc index 2be143a84e..974fceb0ee 100644 --- a/src/pika_cmd_table_manager.cc +++ b/src/pika_cmd_table_manager.cc @@ -47,6 +47,7 @@ void PikaCmdTableManager::InitCmdTable(void) { CommandStatistics statistics; for (auto& iter : *cmds_) { cmdstat_map_.emplace(iter.first, statistics); + iter.second->SetCmdId(cmdId_++); } } @@ -81,7 +82,7 @@ std::shared_ptr PikaCmdTableManager::NewCommand(const std::string& opt) { CmdTable* PikaCmdTableManager::GetCmdTable() { return cmds_.get(); } -uint32_t PikaCmdTableManager::GetCmdId() { return ++cmdId_; } +uint32_t PikaCmdTableManager::GetMaxCmdId() { return cmdId_; } bool PikaCmdTableManager::CheckCurrentThreadDistributionMapExist(const std::thread::id& tid) { std::shared_lock l(map_protector_); diff --git a/src/pika_command.cc b/src/pika_command.cc index f053509d0c..853aa44ea5 100644 --- a/src/pika_command.cc +++ b/src/pika_command.cc @@ -10,7 +10,6 @@ #include "include/pika_acl.h" #include "include/pika_admin.h" #include "include/pika_bit.h" -#include "include/pika_cmd_table_manager.h" #include "include/pika_command.h" #include "include/pika_geo.h" #include "include/pika_hash.h" @@ -834,8 +833,6 @@ bool Cmd::CheckArg(uint64_t num) const { return !((arity_ > 0 && num != arity_) Cmd::Cmd(std::string name, int arity, uint32_t flag, uint32_t aclCategory) : name_(std::move(name)), arity_(arity), flag_(flag), aclCategory_(aclCategory), cache_missed_in_rtc_(false) { - // assign cmd id - cmdId_ = g_pika_cmd_table_manager->GetCmdId(); } void Cmd::Initial(const PikaCmdArgsType& argv, const std::string& db_name) {