MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / trackingInvalidateKeyRaw

Function trackingInvalidateKeyRaw

src/tracking.cpp:354–399  ·  view source on GitHub ↗

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 caching * slot. * * Note that 'c' may be NULL in case the operation was performed outside the * context of a client modifying the database (for instance when we delete a

Source from the content-addressed store, hash-verified

352 * just to notify the clients that are in the table for this key, that would
353 * otherwise miss the fact we are no longer tracking the key for them. */
354void trackingInvalidateKeyRaw(client *c, char *key, size_t keylen, int bcast) {
355 if (TrackingTable == NULL) return;
356
357 if (bcast && raxSize(PrefixTable) > 0)
358 trackingRememberKeyToBroadcast(c,key,keylen);
359
360 rax *ids = (rax*)raxFind(TrackingTable,(unsigned char*)key,keylen);
361 if (ids == raxNotFound) return;
362
363 raxIterator ri;
364 raxStart(&ri,ids);
365 raxSeek(&ri,"^",NULL,0);
366 while(raxNext(&ri)) {
367 uint64_t id;
368 memcpy(&id,ri.key,sizeof(id));
369 client *target = lookupClientByID(id);
370 /* Note that if the client is in BCAST mode, we don't want to
371 * send invalidation messages that were pending in the case
372 * previously the client was not in BCAST mode. This can happen if
373 * TRACKING is enabled normally, and then the client switches to
374 * BCAST mode. */
375 if (target == NULL ||
376 !(target->flags & CLIENT_TRACKING)||
377 target->flags & CLIENT_TRACKING_BCAST)
378 {
379 continue;
380 }
381
382 /* If the client enabled the NOLOOP mode, don't send notifications
383 * about keys changed by the client itself. */
384 if (target->flags & CLIENT_TRACKING_NOLOOP &&
385 target == c)
386 {
387 continue;
388 }
389
390 sendTrackingMessage(target,key,keylen,0);
391 }
392 raxStop(&ri);
393
394 /* Free the tracking table: we'll create the radix tree and populate it
395 * again if more keys will be modified in this caching slot. */
396 TrackingTableTotalItems -= raxSize(ids);
397 raxFree(ids);
398 raxRemove(TrackingTable,(unsigned char*)key,keylen,NULL);
399}
400
401/* Wrapper (the one actually called across the core) to pass the key
402 * as object. */

Callers 2

trackingInvalidateKeyFunction · 0.85
trackingLimitUsedSlotsFunction · 0.85

Calls 11

raxSizeFunction · 0.85
raxFindFunction · 0.85
raxStartFunction · 0.85
raxSeekFunction · 0.85
raxNextFunction · 0.85
lookupClientByIDFunction · 0.85
sendTrackingMessageFunction · 0.85
raxStopFunction · 0.85
raxFreeFunction · 0.85
raxRemoveFunction · 0.85

Tested by

no test coverage detected