Skip to content

Conversation

@Scut-Corgis
Copy link

@Scut-Corgis Scut-Corgis commented Nov 16, 2025

Implement Lazyfree for replicaKeysWithExpire to Avoid Main Thread Blocking in FLUSHALL ASYNC

Problem

When executing FLUSHALL ASYNC on 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 the replicaKeysWithExpire dictionary.

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 ASYNC is designed for asynchronous lazy freeing of core data structures, but the release of replicaKeysWithExpire (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 replicaKeysWithExpire to the lazyfree background thread, aligning it with the asynchronous design of FLUSHALL ASYNC and eliminating main thread blocking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant