summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHuang Zhw <huang_zhw@126.com>2022-07-26 18:28:37 +0800
committerOran Agra <oran@redislabs.com>2022-09-21 22:42:01 +0300
commitba6ed445a397b36e68e2a33bb2b3504d7a133304 (patch)
tree843cf91c359aa836b0d2a640113fd6260f9f2b9d
parentddf1bcf788c81b6b89d4c2949a437633fea09f91 (diff)
downloadredis-ba6ed445a397b36e68e2a33bb2b3504d7a133304.tar.gz
When client tracking is on, invalidation message of flushdb in a (#11038)
When FLUSHDB / FLUSHALL / SWAPDB is inside MULTI / EXEC, the client side tracking invalidation message was interleaved with transaction response. (cherry picked from commit 6f0a27e38e6dc1258f5f5790ec672f7fb555fcfb)
-rw-r--r--src/tracking.c7
-rw-r--r--tests/unit/tracking.tcl14
2 files changed, 20 insertions, 1 deletions
diff --git a/src/tracking.c b/src/tracking.c
index a659e98dd..c98421edb 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 6270ce472..9660b487b 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