未验证 提交 01877076 编写于 作者: T timmy 提交者: GitHub

fix:can't sync binlog when exec redis cmd setnx (#940)

bugfix: can't sync binlog when exec redis command setnx and the key was exist.
when exec cmd setnx, if the key was exist, the value was not update by this cmd.
the binlog of this cmd will be saved into binlog file, but binlog length was zero. so can't do sync log.
so i fixed this issue, by writing binlog of setnx not judge from command return value.
上级 724cedb3
...@@ -517,31 +517,29 @@ std::string SetnxCmd::ToBinlog( ...@@ -517,31 +517,29 @@ std::string SetnxCmd::ToBinlog(
uint32_t filenum, uint32_t filenum,
uint64_t offset) { uint64_t offset) {
std::string content; std::string content;
if (success_) { content.reserve(RAW_ARGS_LEN);
content.reserve(RAW_ARGS_LEN); RedisAppendLen(content, 3, "*");
RedisAppendLen(content, 3, "*");
// to set cmd // don't check variable 'success_', because if 'success_' was false, an empty binlog will be saved into file.
std::string set_cmd("set"); // to setnx cmd
RedisAppendLen(content, set_cmd.size(), "$"); std::string set_cmd("setnx");
RedisAppendContent(content, set_cmd); RedisAppendLen(content, set_cmd.size(), "$");
// key RedisAppendContent(content, set_cmd);
RedisAppendLen(content, key_.size(), "$"); // key
RedisAppendContent(content, key_); RedisAppendLen(content, key_.size(), "$");
// value RedisAppendContent(content, key_);
RedisAppendLen(content, value_.size(), "$"); // value
RedisAppendContent(content, value_); RedisAppendLen(content, value_.size(), "$");
RedisAppendContent(content, value_);
return PikaBinlogTransverter::BinlogEncode(BinlogType::TypeFirst, return PikaBinlogTransverter::BinlogEncode(BinlogType::TypeFirst,
exec_time, exec_time,
term_id, term_id,
logic_id, logic_id,
filenum, filenum,
offset, offset,
content, content,
{}); {});
}
return content;
} }
void SetexCmd::DoInitial() { void SetexCmd::DoInitial() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册