Client side caching: implement trackingInvalidateKeysOnFlush()
This commit is contained in:
parent
3f1c84751a
commit
6191ea90a1
1
src/db.c
1
src/db.c
@ -417,6 +417,7 @@ void signalModifiedKey(redisDb *db, robj *key) {
|
|||||||
|
|
||||||
void signalFlushedDb(int dbid) {
|
void signalFlushedDb(int dbid) {
|
||||||
touchWatchedKeysOnFlush(dbid);
|
touchWatchedKeysOnFlush(dbid);
|
||||||
|
if (server.tracking_clients) trackingInvalidateKeysOnFlush(dbid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------
|
/*-----------------------------------------------------------------------------
|
||||||
|
@ -1638,6 +1638,7 @@ void enableTracking(client *c, uint64_t redirect_to);
|
|||||||
void disableTracking(client *c);
|
void disableTracking(client *c);
|
||||||
void trackingRememberKeys(client *c);
|
void trackingRememberKeys(client *c);
|
||||||
void trackingInvalidateKey(robj *keyobj);
|
void trackingInvalidateKey(robj *keyobj);
|
||||||
|
void trackingInvalidateKeysOnFlush(int dbid);
|
||||||
|
|
||||||
/* List data type */
|
/* List data type */
|
||||||
void listTypeTryConversion(robj *subject, robj *value);
|
void listTypeTryConversion(robj *subject, robj *value);
|
||||||
|
@ -117,23 +117,7 @@ void trackingRememberKeys(client *c) {
|
|||||||
getKeysFreeResult(keys);
|
getKeysFreeResult(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is called from signalModifiedKey() or other places in Redis
|
void sendTrackingMessage(client *c, long long hash) {
|
||||||
* when a key changes value. In the context of keys tracking, our task here is
|
|
||||||
* to send a notification to every client that may have keys about such . */
|
|
||||||
void trackingInvalidateKey(robj *keyobj) {
|
|
||||||
sds sdskey = keyobj->ptr;
|
|
||||||
uint64_t hash = crc64(0,
|
|
||||||
(unsigned char*)sdskey,sdslen(sdskey))&(TRACKING_TABLE_SIZE-1);
|
|
||||||
if (TrackingTable == NULL || TrackingTable[hash] == NULL) return;
|
|
||||||
|
|
||||||
raxIterator ri;
|
|
||||||
raxStart(&ri,TrackingTable[hash]);
|
|
||||||
raxSeek(&ri,"^",NULL,0);
|
|
||||||
while(raxNext(&ri)) {
|
|
||||||
uint64_t id;
|
|
||||||
memcpy(&id,ri.key,ri.key_len);
|
|
||||||
client *c = lookupClientByID(id);
|
|
||||||
if (c == NULL) continue;
|
|
||||||
int using_redirection = 0;
|
int using_redirection = 0;
|
||||||
if (c->client_tracking_redirection) {
|
if (c->client_tracking_redirection) {
|
||||||
client *redir = lookupClientByID(c->client_tracking_redirection);
|
client *redir = lookupClientByID(c->client_tracking_redirection);
|
||||||
@ -146,7 +130,7 @@ void trackingInvalidateKey(robj *keyobj) {
|
|||||||
addReplyBulkCBuffer(c,"tracking-redir-broken",21);
|
addReplyBulkCBuffer(c,"tracking-redir-broken",21);
|
||||||
addReplyLongLong(c,c->client_tracking_redirection);
|
addReplyLongLong(c,c->client_tracking_redirection);
|
||||||
}
|
}
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
c = redir;
|
c = redir;
|
||||||
using_redirection = 1;
|
using_redirection = 1;
|
||||||
@ -166,6 +150,26 @@ void trackingInvalidateKey(robj *keyobj) {
|
|||||||
decrRefCount(msg);
|
decrRefCount(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This function is called from signalModifiedKey() or other places in Redis
|
||||||
|
* when a key changes value. In the context of keys tracking, our task here is
|
||||||
|
* to send a notification to every client that may have keys about such . */
|
||||||
|
void trackingInvalidateKey(robj *keyobj) {
|
||||||
|
sds sdskey = keyobj->ptr;
|
||||||
|
uint64_t hash = crc64(0,
|
||||||
|
(unsigned char*)sdskey,sdslen(sdskey))&(TRACKING_TABLE_SIZE-1);
|
||||||
|
if (TrackingTable == NULL || TrackingTable[hash] == NULL) return;
|
||||||
|
|
||||||
|
raxIterator ri;
|
||||||
|
raxStart(&ri,TrackingTable[hash]);
|
||||||
|
raxSeek(&ri,"^",NULL,0);
|
||||||
|
while(raxNext(&ri)) {
|
||||||
|
uint64_t id;
|
||||||
|
memcpy(&id,ri.key,ri.key_len);
|
||||||
|
client *c = lookupClientByID(id);
|
||||||
|
if (c == NULL) continue;
|
||||||
|
sendTrackingMessage(c,hash);
|
||||||
|
}
|
||||||
raxStop(&ri);
|
raxStop(&ri);
|
||||||
|
|
||||||
/* Free the tracking table: we'll create the radix tree and populate it
|
/* Free the tracking table: we'll create the radix tree and populate it
|
||||||
@ -173,3 +177,18 @@ void trackingInvalidateKey(robj *keyobj) {
|
|||||||
raxFree(TrackingTable[hash]);
|
raxFree(TrackingTable[hash]);
|
||||||
TrackingTable[hash] = NULL;
|
TrackingTable[hash] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trackingInvalidateKeysOnFlush(int dbid) {
|
||||||
|
UNUSED(dbid);
|
||||||
|
if (server.tracking_clients == 0) return;
|
||||||
|
|
||||||
|
listNode *ln;
|
||||||
|
listIter li;
|
||||||
|
listRewind(server.clients,&li);
|
||||||
|
while ((ln = listNext(&li)) != NULL) {
|
||||||
|
client *c = listNodeValue(ln);
|
||||||
|
if (c->flags & CLIENT_TRACKING) {
|
||||||
|
sendTrackingMessage(c,-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user