resize query buffer more accurately

1. querybuf_peak has not been updated correctly in readQueryFromClient.
2. qbuf shrinking uses sdsalloc instead of sdsAllocSize

see more details in issue #4983
This commit is contained in:
zhaozhao.zz 2018-06-12 23:57:55 +08:00 committed by Oran Agra
parent 9894ce5fc4
commit 2248eaacac
2 changed files with 4 additions and 2 deletions

View File

@ -2147,7 +2147,6 @@ void readQueryFromClient(connection *conn) {
}
qblen = sdslen(c->querybuf);
if (c->querybuf_peak < qblen) c->querybuf_peak = qblen;
if (big_arg || sdsalloc(c->querybuf) < PROTO_IOBUF_LEN) {
/* When reading a BIG_ARG we won't be reading more than that one arg
* into the query buffer, so we don't need to pre-allocate more than we
@ -2187,6 +2186,9 @@ void readQueryFromClient(connection *conn) {
}
sdsIncrLen(c->querybuf,nread);
qblen = sdslen(c->querybuf);
if (c->querybuf_peak < qblen) c->querybuf_peak = qblen;
c->lastinteraction = server.unixtime;
if (c->flags & CLIENT_MASTER) c->read_reploff += nread;
atomicIncr(server.stat_net_input_bytes, nread);

View File

@ -1664,7 +1664,7 @@ long long getInstantaneousMetric(int metric) {
*
* The function always returns 0 as it never terminates the client. */
int clientsCronResizeQueryBuffer(client *c) {
size_t querybuf_size = sdsAllocSize(c->querybuf);
size_t querybuf_size = sdsalloc(c->querybuf);
time_t idletime = server.unixtime - c->lastinteraction;
/* There are two conditions to resize the query buffer: