From 5f716ea467d29059a89f90b6ccbdee5a60443200 Mon Sep 17 00:00:00 2001 From: Luke Palmer Date: Wed, 15 Jul 2020 13:53:41 -0400 Subject: Send null for invalidate on flush (#7469) --- src/tracking.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/tracking.c') diff --git a/src/tracking.c b/src/tracking.c index 8c2dca7ba..2721de32a 100644 --- a/src/tracking.c +++ b/src/tracking.c @@ -198,9 +198,11 @@ void trackingRememberKeys(client *c) { * * In case the 'proto' argument is non zero, the function will assume that * 'keyname' points to a buffer of 'keylen' bytes already expressed in the - * form of Redis RESP protocol, representing an array of keys to send - * to the client as value of the invalidation. This is used in BCAST mode - * in order to optimized the implementation to use less CPU time. */ + * form of Redis RESP protocol. This is used for: + * - In BCAST mode, to send an array of invalidated keys to all + * applicable clients + * - Following a flush command, to send a single RESP NULL to indicate + * that all keys are now invalid. */ void sendTrackingMessage(client *c, char *keyname, size_t keylen, int proto) { int using_redirection = 0; if (c->client_tracking_redirection) { @@ -342,17 +344,19 @@ void trackingInvalidateKey(client *c, robj *keyobj) { trackingInvalidateKeyRaw(c,keyobj->ptr,sdslen(keyobj->ptr),1); } -/* This function is called when one or all the Redis databases are flushed - * (dbid == -1 in case of FLUSHALL). Caching keys are not specific for - * each DB but are global: currently what we do is send a special - * notification to clients with tracking enabled, invalidating the caching - * key "", which means, "all the keys", in order to avoid flooding clients - * with many invalidation messages for all the keys they may hold. +/* This function is called when one or all the Redis databases are + * flushed (dbid == -1 in case of FLUSHALL). Caching keys are not + * specific for each DB but are global: currently what we do is send a + * special notification to clients with tracking enabled, sending a + * RESP NULL, which means, "all the keys", in order to avoid flooding + * clients with many invalidation messages for all the keys they may + * hold. */ void freeTrackingRadixTree(void *rt) { raxFree(rt); } +/* A RESP NULL is sent to indicate that all keys are invalid */ void trackingInvalidateKeysOnFlush(int dbid) { if (server.tracking_clients) { listNode *ln; @@ -361,7 +365,7 @@ void trackingInvalidateKeysOnFlush(int dbid) { while ((ln = listNext(&li)) != NULL) { client *c = listNodeValue(ln); if (c->flags & CLIENT_TRACKING) { - sendTrackingMessage(c,"",1,0); + sendTrackingMessage(c,shared.null[c->resp]->ptr,sdslen(shared.null[c->resp]->ptr),1); } } } -- cgit v1.2.1