Skip to content

Commit

Permalink
fix: modify cmdId assignment time to assgining after registering cmdt…
Browse files Browse the repository at this point in the history
…able (#2692)

* change cmdId assignment time to assign after intializing cmdtable

* 修改 PikaCmdTableManager中 getCmdId,删除pika_command.cc中多余的头文件引用
  • Loading branch information
gukj-spel authored and brother-jin committed Aug 15, 2024
1 parent 7dcd4f6 commit 2eb389f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/pika_cmd_table_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PikaCmdTableManager {
std::shared_ptr<Cmd> GetCmd(const std::string& opt);
bool CmdExist(const std::string& cmd) const;
CmdTable* GetCmdTable();
uint32_t GetCmdId();
uint32_t GetMaxCmdId();

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

Expand Down
1 change: 1 addition & 0 deletions include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ class Cmd : public std::enable_shared_from_this<Cmd> {
std::shared_ptr<std::string> GetResp();

void SetStage(CmdStage stage);
void SetCmdId(uint32_t cmdId){cmdId_ = cmdId;}

virtual void DoBinlog();

Expand Down
3 changes: 2 additions & 1 deletion src/pika_cmd_table_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void PikaCmdTableManager::InitCmdTable(void) {
CommandStatistics statistics;
for (auto& iter : *cmds_) {
cmdstat_map_.emplace(iter.first, statistics);
iter.second->SetCmdId(cmdId_++);
}
}

Expand Down Expand Up @@ -81,7 +82,7 @@ std::shared_ptr<Cmd> 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_);
Expand Down
3 changes: 0 additions & 3 deletions src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2eb389f

Please sign in to comment.