Commit d756b11f authored by Qu Chen's avatar Qu Chen Committed by Oran Agra
Browse files

Not over-allocate client query buffer when reading large objects. (#5954)

In response to large client query buffer optimization introduced in 1898e6ce. The calculation of the amount of
remaining bytes we need to write to the query buffer was calculated wrong, as a result we are unnecessarily
growing the client query buffer by sdslen(c->querybuf) always. This fix corrects that behavior.

Please note the previous behavior prior to the before-mentioned change was correctly calculating the remaining
additional bytes, and this change makes that calculate to be consistent.

Useful context, the argument of size `ll` starts at qb_pos (which is now the beginning of the sds), but much of it
may have already been read from the socket, so we only need to grow the sds for the remainder of it.

(cherry picked from commit 11b3325e)
parent ec74ae7e
...@@ -1793,7 +1793,7 @@ int processMultibulkBuffer(client *c) { ...@@ -1793,7 +1793,7 @@ int processMultibulkBuffer(client *c) {
c->qb_pos = 0; c->qb_pos = 0;
/* Hint the sds library about the amount of bytes this string is /* Hint the sds library about the amount of bytes this string is
* going to contain. */ * going to contain. */
c->querybuf = sdsMakeRoomFor(c->querybuf,ll+2); c->querybuf = sdsMakeRoomFor(c->querybuf,ll+2-sdslen(c->querybuf));
} }
} }
c->bulklen = ll; c->bulklen = ll;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment