Implement Lazyfree for replicaKeysWithExpire to Avoid Main Thread Blocking in FLUSHALL ASYNC #2849
+26
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement Lazyfree for replicaKeysWithExpire to Avoid Main Thread Blocking in FLUSHALL ASYNC
Problem
When executing
FLUSHALL ASYNCon a writable replica that has a large number of expired keys directly written to it, the main thread gets blocked for an extended period while synchronously releasing thereplicaKeysWithExpiredictionary.In local testing, this blocking lasts approximately 1 second per 1 million expired keys. With a substantial number of keys (e.g., tens of millions), the main thread becomes completely unresponsive, leading to service outages.
Root Cause
FLUSHALL ASYNCis designed for asynchronous lazy freeing of core data structures, but the release ofreplicaKeysWithExpire(a dictionary tracking expired keys on replicas) still happens synchronously in the main thread. This synchronous operation becomes a bottleneck when dealing with massive key volumes, as it cannot be offloaded to the lazyfree background thread.This PR addresses the issue by moving the release of
replicaKeysWithExpireto the lazyfree background thread, aligning it with the asynchronous design ofFLUSHALL ASYNCand eliminating main thread blocking.