Skip to content

Commit

Permalink
Merge pull request #1959 from dorothy00dd2/fix-redis
Browse files Browse the repository at this point in the history
fix arena cleared early when parse redis message
  • Loading branch information
lorinlee committed Oct 24, 2022
2 parents 329c626 + 03ad6bc commit 5d89893
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/brpc/policy/redis_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ ParseResult ParseRedisMessage(butil::IOBuf* source, Socket* socket,
wopt.ignore_eovercrowded = true;
LOG_IF(WARNING, socket->Write(&sendbuf, &wopt) != 0)
<< "Fail to send redis reply";
ctx->arena.clear();
if(ctx->parser.ParsedArgsSize() == 0) {
ctx->arena.clear();
}
return MakeParseError(err);
} else {
// NOTE(gejun): PopPipelinedInfo() is actually more contended than what
Expand Down
4 changes: 4 additions & 0 deletions src/brpc/redis_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ RedisCommandParser::RedisCommandParser()
, _length(0)
, _index(0) {}

size_t RedisCommandParser::ParsedArgsSize() {
return _args.size();
}

ParseError RedisCommandParser::Consume(butil::IOBuf& buf,
std::vector<butil::StringPiece>* args,
butil::Arena* arena) {
Expand Down
1 change: 1 addition & 0 deletions src/brpc/redis_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class RedisCommandParser {
// in `arena'.
ParseError Consume(butil::IOBuf& buf, std::vector<butil::StringPiece>* args,
butil::Arena* arena);
size_t ParsedArgsSize();

private:
// Reset parser to the initial state.
Expand Down

0 comments on commit 5d89893

Please sign in to comment.