Add explicit assert to ensure thread_shared_qb won't expand (#938)
Although this won't happen now, adding this statement explicitly. Signed-off-by: Binbin <binloveplay1314@qq.com>
This commit is contained in:
parent
c7d1daea05
commit
9f4b1adbea
@ -2521,7 +2521,8 @@ void resetClient(client *c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initializes the shared query buffer to a new sds with the default capacity */
|
/* Initializes the shared query buffer to a new sds with the default capacity.
|
||||||
|
* Need to ensure the initlen is not less than readlen in readToQueryBuf. */
|
||||||
void initSharedQueryBuf(void) {
|
void initSharedQueryBuf(void) {
|
||||||
thread_shared_qb = sdsnewlen(NULL, PROTO_IOBUF_LEN);
|
thread_shared_qb = sdsnewlen(NULL, PROTO_IOBUF_LEN);
|
||||||
sdsclear(thread_shared_qb);
|
sdsclear(thread_shared_qb);
|
||||||
@ -3119,6 +3120,10 @@ void readToQueryBuf(client *c) {
|
|||||||
qblen = sdslen(c->querybuf);
|
qblen = sdslen(c->querybuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* c->querybuf may be expanded. If so, the old thread_shared_qb will be released.
|
||||||
|
* Although we have ensured that c->querybuf will not be expanded in the current
|
||||||
|
* thread_shared_qb, we still add this check for code robustness. */
|
||||||
|
int use_thread_shared_qb = (c->querybuf == thread_shared_qb) ? 1 : 0;
|
||||||
if (!is_primary && // primary client's querybuf can grow greedy.
|
if (!is_primary && // primary client's querybuf can grow greedy.
|
||||||
(big_arg || sdsalloc(c->querybuf) < PROTO_IOBUF_LEN)) {
|
(big_arg || sdsalloc(c->querybuf) < PROTO_IOBUF_LEN)) {
|
||||||
/* When reading a BIG_ARG we won't be reading more than that one arg
|
/* When reading a BIG_ARG we won't be reading more than that one arg
|
||||||
@ -3136,6 +3141,8 @@ void readToQueryBuf(client *c) {
|
|||||||
/* Read as much as possible from the socket to save read(2) system calls. */
|
/* Read as much as possible from the socket to save read(2) system calls. */
|
||||||
readlen = sdsavail(c->querybuf);
|
readlen = sdsavail(c->querybuf);
|
||||||
}
|
}
|
||||||
|
if (use_thread_shared_qb) serverAssert(c->querybuf == thread_shared_qb);
|
||||||
|
|
||||||
c->nread = connRead(c->conn, c->querybuf + qblen, readlen);
|
c->nread = connRead(c->conn, c->querybuf + qblen, readlen);
|
||||||
if (c->nread <= 0) {
|
if (c->nread <= 0) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user