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