MCPcopy Create free account
hub / github.com/F-Stack/f-stack / trackingLimitUsedSlots

Function trackingLimitUsedSlots

app/redis-6.2.6/src/tracking.c:454–489  ·  view source on GitHub ↗

Tracking forces Redis to remember information about which client may have * certain keys. In workloads where there are a lot of reads, but keys are * hardly modified, the amount of information we have to remember server side * could be a lot, with the number of keys being totally not bound. * * So Redis allows the user to configure a maximum number of keys for the * invalidation table. This

Source from the content-addressed store, hash-verified

452 * a random key, and send invalidation messages to clients like if the key was
453 * modified. */
454void trackingLimitUsedSlots(void) {
455 static unsigned int timeout_counter = 0;
456 if (TrackingTable == NULL) return;
457 if (server.tracking_table_max_keys == 0) return; /* No limits set. */
458 size_t max_keys = server.tracking_table_max_keys;
459 if (raxSize(TrackingTable) <= max_keys) {
460 timeout_counter = 0;
461 return; /* Limit not reached. */
462 }
463
464 /* We have to invalidate a few keys to reach the limit again. The effort
465 * we do here is proportional to the number of times we entered this
466 * function and found that we are still over the limit. */
467 int effort = 100 * (timeout_counter+1);
468
469 /* We just remove one key after another by using a random walk. */
470 raxIterator ri;
471 raxStart(&ri,TrackingTable);
472 while(effort > 0) {
473 effort--;
474 raxSeek(&ri,"^",NULL,0);
475 raxRandomWalk(&ri,0);
476 if (raxEOF(&ri)) break;
477 trackingInvalidateKeyRaw(NULL,(char*)ri.key,ri.key_len,0);
478 if (raxSize(TrackingTable) <= max_keys) {
479 timeout_counter = 0;
480 raxStop(&ri);
481 return; /* Return ASAP: we are again under the limit. */
482 }
483 }
484
485 /* If we reach this point, we were not able to go under the configured
486 * limit using the maximum effort we had for this run. */
487 raxStop(&ri);
488 timeout_counter++;
489}
490
491/* Generate Redis protocol for an array containing all the key names
492 * in the 'keys' radix tree. If the client is not NULL, the list will not

Callers 2

serverCronFunction · 0.85
processCommandFunction · 0.85

Calls 7

raxSizeFunction · 0.85
raxStartFunction · 0.85
raxSeekFunction · 0.85
raxRandomWalkFunction · 0.85
raxEOFFunction · 0.85
trackingInvalidateKeyRawFunction · 0.85
raxStopFunction · 0.85

Tested by

no test coverage detected