Skip to content

Commit 1705916

Browse files
authored
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 1bb76ed commit 1705916

4 files changed

Lines changed: 4 additions & 5 deletions

File tree

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
@@ -566,6 +566,7 @@ class Cmd : public std::enable_shared_from_this<Cmd> {
566566
std::shared_ptr<std::string> GetResp();
567567

568568
void SetStage(CmdStage stage);
569+
void SetCmdId(uint32_t cmdId){cmdId_ = cmdId;}
569570

570571
virtual void DoBinlog();
571572

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"
@@ -830,8 +829,6 @@ bool Cmd::CheckArg(uint64_t num) const { return !((arity_ > 0 && num != arity_)
830829

831830
Cmd::Cmd(std::string name, int arity, uint32_t flag, uint32_t aclCategory)
832831
: name_(std::move(name)), arity_(arity), flag_(flag), aclCategory_(aclCategory) {
833-
// assign cmd id
834-
cmdId_ = g_pika_cmd_table_manager->GetCmdId();
835832
}
836833

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

0 commit comments

Comments
 (0)