Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: modify cmdId assignment time to assgining after registering cmdtable #2692

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为什么要改成 GetMaxCmdId 而且这个函数应该是没用了吧

Copy link
Contributor Author

@gukj-spel gukj-spel Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个函数确实没用了,当时想着之后可能有获取全局 cmdId 的需求就保留下来。改名是因为此时获取cmdId 是全局最大的 cmdId,所以改下名字更加直观。


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 @@ -566,6 +566,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 @@ -830,8 +829,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) {
// assign cmd id
cmdId_ = g_pika_cmd_table_manager->GetCmdId();
}

void Cmd::Initial(const PikaCmdArgsType& argv, const std::string& db_name) {
Expand Down
Loading