Skip to content

Commit

Permalink
fix arena cleared early when parse redis message
Browse files Browse the repository at this point in the history
  • Loading branch information
jiumei committed Oct 19, 2022
1 parent 8bd6385 commit ab2c1da
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) {}

int 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);
int ParsedArgsSize();

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

0 comments on commit ab2c1da

Please sign in to comment.