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

rename function ToBinlog to ToRedisProtocol #2140

Merged
merged 1 commit into from
Nov 22, 2023
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
6 changes: 2 additions & 4 deletions include/pika_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ class FlushallCmd : public Cmd {
void FlushAllWithoutLock();
private:
void DoInitial() override;
std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
std::string ToRedisProtocol() override;
void DoWithoutLock(std::shared_ptr<Slot> slot);
};

Expand Down Expand Up @@ -405,8 +404,7 @@ class PaddingCmd : public Cmd {

private:
void DoInitial() override;
std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
std::string ToRedisProtocol() override;
};

class PKPatternMatchDelCmd : public Cmd {
Expand Down
3 changes: 1 addition & 2 deletions include/pika_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,7 @@ class Cmd : public std::enable_shared_from_this<Cmd> {
std::string db_name() const;
BinlogOffset binlog_offset() const;
PikaCmdArgsType& argv();
virtual std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset);
virtual std::string ToRedisProtocol();

void SetConn(const std::shared_ptr<net::NetConn>& conn);
std::shared_ptr<net::NetConn> GetConn();
Expand Down
21 changes: 7 additions & 14 deletions include/pika_kv.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ class SetCmd : public Cmd {
success_ = 0;
condition_ = kNONE;
}
std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
std::string ToRedisProtocol() override;
};

class GetCmd : public Cmd {
Expand Down Expand Up @@ -259,8 +258,7 @@ class SetnxCmd : public Cmd {
std::string value_;
int32_t success_ = 0;
void DoInitial() override;
std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
std::string ToRedisProtocol() override;
};

class SetexCmd : public Cmd {
Expand All @@ -281,8 +279,7 @@ class SetexCmd : public Cmd {
int64_t sec_ = 0;
std::string value_;
void DoInitial() override;
std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
std::string ToRedisProtocol() override;
};

class PsetexCmd : public Cmd {
Expand All @@ -303,8 +300,7 @@ class PsetexCmd : public Cmd {
int64_t usec_ = 0;
std::string value_;
void DoInitial() override;
std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
std::string ToRedisProtocol() override;
};

class DelvxCmd : public Cmd {
Expand Down Expand Up @@ -476,8 +472,7 @@ class ExpireCmd : public Cmd {
std::string key_;
int64_t sec_ = 0;
void DoInitial() override;
std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
std::string ToRedisProtocol() override;
};

class PexpireCmd : public Cmd {
Expand All @@ -497,8 +492,7 @@ class PexpireCmd : public Cmd {
std::string key_;
int64_t msec_ = 0;
void DoInitial() override;
std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
std::string ToRedisProtocol() override;
};

class ExpireatCmd : public Cmd {
Expand Down Expand Up @@ -537,8 +531,7 @@ class PexpireatCmd : public Cmd {
std::string key_;
int64_t time_stamp_ms_ = 0;
void DoInitial() override;
std::string ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) override;
std::string ToRedisProtocol() override;
};

class TtlCmd : public Cmd {
Expand Down
6 changes: 2 additions & 4 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ void FlushallCmd::Do(std::shared_ptr<Slot> slot) {
}

// flushall convert flushdb writes to every slot binlog
std::string FlushallCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) {
std::string FlushallCmd::ToRedisProtocol() {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLen(content, 1, "*");
Expand Down Expand Up @@ -2559,8 +2558,7 @@ void PaddingCmd::DoInitial() {

void PaddingCmd::Do(std::shared_ptr<Slot> slot) { res_.SetRes(CmdRes::kOk); }

std::string PaddingCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) {
std::string PaddingCmd::ToRedisProtocol() {
return PikaBinlogTransverter::ConstructPaddingBinlog(
BinlogType::TypeFirst,
argv_[1].size() + BINLOG_ITEM_HEADER_SIZE + PADDING_BINLOG_PROTOCOL_SIZE + SPACE_STROE_PARAMETER_LENGTH);
Expand Down
2 changes: 1 addition & 1 deletion src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ std::string Cmd::db_name() const { return db_name_; }

PikaCmdArgsType& Cmd::argv() { return argv_; }

std::string Cmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum, uint64_t offset) {
std::string Cmd::ToRedisProtocol() {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLenUint64(content, argv_.size(), "*");
Expand Down
5 changes: 2 additions & 3 deletions src/pika_consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,8 @@ Status ConsensusCoordinator::UpdateSlave(const std::string& ip, int port, const

Status ConsensusCoordinator::InternalAppendBinlog(const BinlogItem& item, const std::shared_ptr<Cmd>& cmd_ptr,
LogOffset* log_offset) {
std::string binlog =
cmd_ptr->ToBinlog(item.exec_time(), item.term_id(), item.logic_id(), item.filenum(), item.offset());
Status s = stable_logger_->Logger()->Put(binlog);
std::string content = cmd_ptr->ToRedisProtocol();
Status s = stable_logger_->Logger()->Put(content);
if (!s.ok()) {
std::string db_name = cmd_ptr->db_name().empty() ? g_pika_conf->default_db() : cmd_ptr->db_name();
std::shared_ptr<DB> db = g_pika_server->GetDB(db_name);
Expand Down
23 changes: 8 additions & 15 deletions src/pika_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ void SetCmd::Do(std::shared_ptr<Slot> slot) {
}
}

std::string SetCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) {
std::string SetCmd::ToRedisProtocol() {
if (condition_ == SetCmd::kEXORPX) {
std::string content;
content.reserve(RAW_ARGS_LEN);
Expand All @@ -128,7 +127,7 @@ std::string SetCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logi
RedisAppendContent(content, value_);
return content;
} else {
return Cmd::ToBinlog(exec_time, term_id, logic_id, filenum, offset);
return Cmd::ToRedisProtocol();
}
}

Expand Down Expand Up @@ -492,8 +491,7 @@ void SetnxCmd::Do(std::shared_ptr<Slot> slot) {
}
}

std::string SetnxCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) {
std::string SetnxCmd::ToRedisProtocol() {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLen(content, 3, "*");
Expand Down Expand Up @@ -535,8 +533,7 @@ void SetexCmd::Do(std::shared_ptr<Slot> slot) {
}
}

std::string SetexCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) {
std::string SetexCmd::ToRedisProtocol() {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLen(content, 4, "*");
Expand Down Expand Up @@ -583,8 +580,7 @@ void PsetexCmd::Do(std::shared_ptr<Slot> slot) {
}
}

std::string PsetexCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) {
std::string PsetexCmd::ToRedisProtocol() {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLen(content, 4, "*");
Expand Down Expand Up @@ -866,8 +862,7 @@ void ExpireCmd::Do(std::shared_ptr<Slot> slot) {
}
}

std::string ExpireCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) {
std::string ExpireCmd::ToRedisProtocol() {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLen(content, 3, "*");
Expand Down Expand Up @@ -911,8 +906,7 @@ void PexpireCmd::Do(std::shared_ptr<Slot> slot) {
}
}

std::string PexpireCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) {
std::string PexpireCmd::ToRedisProtocol() {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLenUint64(content, argv_.size(), "*");
Expand Down Expand Up @@ -968,8 +962,7 @@ void PexpireatCmd::DoInitial() {
}
}

std::string PexpireatCmd::ToBinlog(uint32_t exec_time, uint32_t term_id, uint64_t logic_id, uint32_t filenum,
uint64_t offset) {
std::string PexpireatCmd::ToRedisProtocol() {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLenUint64(content, argv_.size(), "*");
Expand Down