From e4a4a536bed6225d1bf04bdca67e2e21f99a3f4a Mon Sep 17 00:00:00 2001 From: Huang Zhw Date: Tue, 26 Jul 2022 14:06:51 +0800 Subject: [PATCH] When client tracking is on, invalidation message of flushdb in a transaction is interleaved with transaction response. --- src/tracking.c | 7 ++++++- tests/unit/tracking.tcl | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/tracking.c b/src/tracking.c index a659e98dd687..c98421edbfe0 100644 --- a/src/tracking.c +++ b/src/tracking.c @@ -454,7 +454,12 @@ void trackingInvalidateKeysOnFlush(int async) { while ((ln = listNext(&li)) != NULL) { client *c = listNodeValue(ln); if (c->flags & CLIENT_TRACKING) { - sendTrackingMessage(c,shared.null[c->resp]->ptr,sdslen(shared.null[c->resp]->ptr),1); + if (c == server.current_client) { + incrRefCount(shared.null[c->resp]); + listAddNodeTail(server.tracking_pending_keys,shared.null[c->resp]); + } else { + sendTrackingMessage(c,shared.null[c->resp]->ptr,sdslen(shared.null[c->resp]->ptr),1); + } } } } diff --git a/tests/unit/tracking.tcl b/tests/unit/tracking.tcl index 6270ce47290a..9660b487bf46 100644 --- a/tests/unit/tracking.tcl +++ b/tests/unit/tracking.tcl @@ -548,6 +548,20 @@ start_server {tags {"tracking network"}} { assert_equal [lindex [$rd_redirection read] 2] {} } + test {flushdb tracking invalidation message is not interleaved with transaction response} { + clean_all + r HELLO 3 + r CLIENT TRACKING on + r SET a{t} 1 + r GET a{t} + r MULTI + r FLUSHDB + set res [r EXEC] + assert_equal $res {OK} + # Consume the invalidate message which is after command response + r read + } {invalidate *_*} + # Keys are defined to be evicted 100 at a time by default. # If after eviction the number of keys still surpasses the limit # defined in tracking-table-max-keys, we increases eviction