Skip to content

Commit

Permalink
fix: incr/decr commands will lose TTL on slaves (OpenAtomFoundation#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
fancy-rabbit authored and whoiami committed Sep 29, 2019
1 parent f3fa975 commit cf0c335
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 189 deletions.
30 changes: 0 additions & 30 deletions include/pika_kv.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,6 @@ class IncrCmd : public Cmd {
std::string key_;
int64_t new_value_;
virtual void DoInitial() override;
virtual std::string ToBinlog(
uint32_t exec_time,
const std::string& server_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset) override;
};

class IncrbyCmd : public Cmd {
Expand All @@ -128,12 +122,6 @@ class IncrbyCmd : public Cmd {
std::string key_;
int64_t by_, new_value_;
virtual void DoInitial() override;
virtual std::string ToBinlog(
uint32_t exec_time,
const std::string& server_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset) override;
};

class IncrbyfloatCmd : public Cmd {
Expand All @@ -153,12 +141,6 @@ class IncrbyfloatCmd : public Cmd {
std::string key_, value_, new_value_;
double by_;
virtual void DoInitial() override;
virtual std::string ToBinlog(
uint32_t exec_time,
const std::string& server_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset) override;
};

class DecrCmd : public Cmd {
Expand All @@ -178,12 +160,6 @@ class DecrCmd : public Cmd {
std::string key_;
int64_t new_value_;
virtual void DoInitial() override;
virtual std::string ToBinlog(
uint32_t exec_time,
const std::string& server_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset) override;
};

class DecrbyCmd : public Cmd {
Expand All @@ -203,12 +179,6 @@ class DecrbyCmd : public Cmd {
std::string key_;
int64_t by_, new_value_;
virtual void DoInitial() override;
virtual std::string ToBinlog(
uint32_t exec_time,
const std::string& server_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset) override;
};

class GetsetCmd : public Cmd {
Expand Down
159 changes: 0 additions & 159 deletions src/pika_kv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,38 +208,6 @@ void IncrCmd::Do(std::shared_ptr<Partition> partition) {
return;
}

std::string IncrCmd::ToBinlog(
uint32_t exec_time,
const std::string& server_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset) {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLen(content, 3, "*");

// to set cmd
std::string set_cmd("set");
RedisAppendLen(content, set_cmd.size(), "$");
RedisAppendContent(content, set_cmd);
// key
RedisAppendLen(content, key_.size(), "$");
RedisAppendContent(content, key_);
// value
std::string value = std::to_string(new_value_);
RedisAppendLen(content, value.size(), "$");
RedisAppendContent(content, value);

return PikaBinlogTransverter::BinlogEncode(BinlogType::TypeFirst,
exec_time,
std::stoi(server_id),
logic_id,
filenum,
offset,
content,
{});
}

void IncrbyCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNameIncrby);
Expand Down Expand Up @@ -267,38 +235,6 @@ void IncrbyCmd::Do(std::shared_ptr<Partition> partition) {
return;
}

std::string IncrbyCmd::ToBinlog(
uint32_t exec_time,
const std::string& server_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset) {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLen(content, 3, "*");

// to set cmd
std::string set_cmd("set");
RedisAppendLen(content, set_cmd.size(), "$");
RedisAppendContent(content, set_cmd);
// key
RedisAppendLen(content, key_.size(), "$");
RedisAppendContent(content, key_);
// value
std::string value = std::to_string(new_value_);
RedisAppendLen(content, value.size(), "$");
RedisAppendContent(content, value);

return PikaBinlogTransverter::BinlogEncode(BinlogType::TypeFirst,
exec_time,
std::stoi(server_id),
logic_id,
filenum,
offset,
content,
{});
}

void IncrbyfloatCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNameIncrbyfloat);
Expand Down Expand Up @@ -328,37 +264,6 @@ void IncrbyfloatCmd::Do(std::shared_ptr<Partition> partition) {
return;
}

std::string IncrbyfloatCmd::ToBinlog(
uint32_t exec_time,
const std::string& server_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset) {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLen(content, 3, "*");

// to set cmd
std::string set_cmd("set");
RedisAppendLen(content, set_cmd.size(), "$");
RedisAppendContent(content, set_cmd);
// key
RedisAppendLen(content, key_.size(), "$");
RedisAppendContent(content, key_);
// value
RedisAppendLen(content, new_value_.size(), "$");
RedisAppendContent(content, new_value_);

return PikaBinlogTransverter::BinlogEncode(BinlogType::TypeFirst,
exec_time,
std::stoi(server_id),
logic_id,
filenum,
offset,
content,
{});
}

void DecrCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNameDecr);
Expand All @@ -382,38 +287,6 @@ void DecrCmd::Do(std::shared_ptr<Partition> partition) {
return;
}

std::string DecrCmd::ToBinlog(
uint32_t exec_time,
const std::string& server_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset) {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLen(content, 3, "*");

// to set cmd
std::string set_cmd("set");
RedisAppendLen(content, set_cmd.size(), "$");
RedisAppendContent(content, set_cmd);
// key
RedisAppendLen(content, key_.size(), "$");
RedisAppendContent(content, key_);
// value
std::string value = std::to_string(new_value_);
RedisAppendLen(content, value.size(), "$");
RedisAppendContent(content, value);

return PikaBinlogTransverter::BinlogEncode(BinlogType::TypeFirst,
exec_time,
std::stoi(server_id),
logic_id,
filenum,
offset,
content,
{});
}

void DecrbyCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNameDecrby);
Expand Down Expand Up @@ -441,38 +314,6 @@ void DecrbyCmd::Do(std::shared_ptr<Partition> partition) {
return;
}

std::string DecrbyCmd::ToBinlog(
uint32_t exec_time,
const std::string& server_id,
uint64_t logic_id,
uint32_t filenum,
uint64_t offset) {
std::string content;
content.reserve(RAW_ARGS_LEN);
RedisAppendLen(content, 3, "*");

// to set cmd
std::string set_cmd("set");
RedisAppendLen(content, set_cmd.size(), "$");
RedisAppendContent(content, set_cmd);
// key
RedisAppendLen(content, key_.size(), "$");
RedisAppendContent(content, key_);
// value
std::string value = std::to_string(new_value_);
RedisAppendLen(content, value.size(), "$");
RedisAppendContent(content, value);

return PikaBinlogTransverter::BinlogEncode(BinlogType::TypeFirst,
exec_time,
std::stoi(server_id),
logic_id,
filenum,
offset,
content,
{});
}

void GetsetCmd::DoInitial() {
if (!CheckArg(argv_.size())) {
res_.SetRes(CmdRes::kWrongNum, kCmdNameGetset);
Expand Down

0 comments on commit cf0c335

Please sign in to comment.