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

Function trackingRememberKeys

src/tracking.cpp:217–248  ·  view source on GitHub ↗

This function is called after the execution of a readonly command in the * case the client 'c' has keys tracking enabled and the tracking is not * in BCAST mode. It will populate the tracking invalidation table according * to the keys the user fetched, so that Redis will know what are the clients * that should receive an invalidation message with certain groups of keys * are modified. */

Source from the content-addressed store, hash-verified

215 * that should receive an invalidation message with certain groups of keys
216 * are modified. */
217void trackingRememberKeys(client *c) {
218 /* Return if we are in optin/out mode and the right CACHING command
219 * was/wasn't given in order to modify the default behavior. */
220 uint64_t optin = c->flags & CLIENT_TRACKING_OPTIN;
221 uint64_t optout = c->flags & CLIENT_TRACKING_OPTOUT;
222 uint64_t caching_given = c->flags & CLIENT_TRACKING_CACHING;
223 if ((optin && !caching_given) || (optout && caching_given)) return;
224
225 getKeysResult result = GETKEYS_RESULT_INIT;
226 int numkeys = getKeysFromCommand(c->cmd,c->argv,c->argc,&result);
227 if (!numkeys) {
228 getKeysFreeResult(&result);
229 return;
230 }
231
232 int *keys = result.keys;
233
234 for(int j = 0; j < numkeys; j++) {
235 int idx = keys[j];
236 sds sdskey = szFromObj(c->argv[idx]);
237 rax *ids = (rax*)raxFind(TrackingTable,(unsigned char*)sdskey,sdslen(sdskey));
238 if (ids == raxNotFound) {
239 ids = raxNew();
240 int inserted = raxTryInsert(TrackingTable,(unsigned char*)sdskey,
241 sdslen(sdskey),ids, NULL);
242 serverAssert(inserted == 1);
243 }
244 if (raxTryInsert(ids,(unsigned char*)&c->id,sizeof(c->id),NULL,NULL))
245 TrackingTableTotalItems++;
246 }
247 getKeysFreeResult(&result);
248}
249
250/* Given a key name, this function sends an invalidation message in the
251 * proper channel (depending on RESP version: PubSub or Push message) and

Callers 1

callFunction · 0.85

Calls 7

getKeysFromCommandFunction · 0.85
getKeysFreeResultFunction · 0.85
szFromObjFunction · 0.85
raxFindFunction · 0.85
sdslenFunction · 0.85
raxNewFunction · 0.85
raxTryInsertFunction · 0.85

Tested by

no test coverage detected