Skip to content

Commit 2eb389f

Browse files
gukj-spelbrother-jin
authored andcommitted
fix: modify cmdId assignment time to assgining after registering cmdtable (#2692)
* change cmdId assignment time to assign after intializing cmdtable * 修改 PikaCmdTableManager中 getCmdId,删除pika_command.cc中多余的头文件引用
1 parent 7dcd4f6 commit 2eb389f

File tree

4 files changed

+4
-5
lines changed

4 files changed

+4
-5
lines changed

include/pika_cmd_table_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class PikaCmdTableManager {
3434
std::shared_ptr<Cmd> GetCmd(const std::string& opt);
3535
bool CmdExist(const std::string& cmd) const;
3636
CmdTable* GetCmdTable();
37-
uint32_t GetCmdId();
37+
uint32_t GetMaxCmdId();
3838

3939
std::vector<std::string> GetAclCategoryCmdNames(uint32_t flag);
4040

include/pika_command.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ class Cmd : public std::enable_shared_from_this<Cmd> {
563563
std::shared_ptr<std::string> GetResp();
564564

565565
void SetStage(CmdStage stage);
566+
void SetCmdId(uint32_t cmdId){cmdId_ = cmdId;}
566567

567568
virtual void DoBinlog();
568569

src/pika_cmd_table_manager.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void PikaCmdTableManager::InitCmdTable(void) {
4747
CommandStatistics statistics;
4848
for (auto& iter : *cmds_) {
4949
cmdstat_map_.emplace(iter.first, statistics);
50+
iter.second->SetCmdId(cmdId_++);
5051
}
5152
}
5253

@@ -81,7 +82,7 @@ std::shared_ptr<Cmd> PikaCmdTableManager::NewCommand(const std::string& opt) {
8182

8283
CmdTable* PikaCmdTableManager::GetCmdTable() { return cmds_.get(); }
8384

84-
uint32_t PikaCmdTableManager::GetCmdId() { return ++cmdId_; }
85+
uint32_t PikaCmdTableManager::GetMaxCmdId() { return cmdId_; }
8586

8687
bool PikaCmdTableManager::CheckCurrentThreadDistributionMapExist(const std::thread::id& tid) {
8788
std::shared_lock l(map_protector_);

src/pika_command.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "include/pika_acl.h"
1111
#include "include/pika_admin.h"
1212
#include "include/pika_bit.h"
13-
#include "include/pika_cmd_table_manager.h"
1413
#include "include/pika_command.h"
1514
#include "include/pika_geo.h"
1615
#include "include/pika_hash.h"
@@ -834,8 +833,6 @@ bool Cmd::CheckArg(uint64_t num) const { return !((arity_ > 0 && num != arity_)
834833

835834
Cmd::Cmd(std::string name, int arity, uint32_t flag, uint32_t aclCategory)
836835
: name_(std::move(name)), arity_(arity), flag_(flag), aclCategory_(aclCategory), cache_missed_in_rtc_(false) {
837-
// assign cmd id
838-
cmdId_ = g_pika_cmd_table_manager->GetCmdId();
839836
}
840837

841838
void Cmd::Initial(const PikaCmdArgsType& argv, const std::string& db_name) {

0 commit comments

Comments
 (0)