Send null for invalidate on flush (#7469)

(cherry picked from commit df4c74ef07139d51b06e3d250107c6f71264c33c)
This commit is contained in:
Luke Palmer 2020-07-15 13:53:41 -04:00 committed by Oran Agra
parent 81d36bc6c8
commit 2871eb287a

View File

@ -198,9 +198,11 @@ void trackingRememberKeys(client *c) {
* *
* In case the 'proto' argument is non zero, the function will assume that * 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 * 'keyname' points to a buffer of 'keylen' bytes already expressed in the
* form of Redis RESP protocol, representing an array of keys to send * form of Redis RESP protocol. This is used for:
* to the client as value of the invalidation. This is used in BCAST mode * - In BCAST mode, to send an array of invalidated keys to all
* in order to optimized the implementation to use less CPU time. */ * 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) { void sendTrackingMessage(client *c, char *keyname, size_t keylen, int proto) {
int using_redirection = 0; int using_redirection = 0;
if (c->client_tracking_redirection) { if (c->client_tracking_redirection) {
@ -342,17 +344,19 @@ void trackingInvalidateKey(client *c, robj *keyobj) {
trackingInvalidateKeyRaw(c,keyobj->ptr,sdslen(keyobj->ptr),1); trackingInvalidateKeyRaw(c,keyobj->ptr,sdslen(keyobj->ptr),1);
} }
/* This function is called when one or all the Redis databases are flushed /* This function is called when one or all the Redis databases are
* (dbid == -1 in case of FLUSHALL). Caching keys are not specific for * flushed (dbid == -1 in case of FLUSHALL). Caching keys are not
* each DB but are global: currently what we do is send a special * specific for each DB but are global: currently what we do is send a
* notification to clients with tracking enabled, invalidating the caching * special notification to clients with tracking enabled, sending a
* key "", which means, "all the keys", in order to avoid flooding clients * RESP NULL, which means, "all the keys", in order to avoid flooding
* with many invalidation messages for all the keys they may hold. * clients with many invalidation messages for all the keys they may
* hold.
*/ */
void freeTrackingRadixTree(void *rt) { void freeTrackingRadixTree(void *rt) {
raxFree(rt); raxFree(rt);
} }
/* A RESP NULL is sent to indicate that all keys are invalid */
void trackingInvalidateKeysOnFlush(int dbid) { void trackingInvalidateKeysOnFlush(int dbid) {
if (server.tracking_clients) { if (server.tracking_clients) {
listNode *ln; listNode *ln;
@ -361,7 +365,7 @@ void trackingInvalidateKeysOnFlush(int dbid) {
while ((ln = listNext(&li)) != NULL) { while ((ln = listNext(&li)) != NULL) {
client *c = listNodeValue(ln); client *c = listNodeValue(ln);
if (c->flags & CLIENT_TRACKING) { if (c->flags & CLIENT_TRACKING) {
sendTrackingMessage(c,"",1,0); sendTrackingMessage(c,shared.null[c->resp]->ptr,sdslen(shared.null[c->resp]->ptr),1);
} }
} }
} }