Add support for asynchronous release to slaveKeysWithExpire on writable replica #14583
+28
−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.
Problem
When executing
FLUSHALL ASYNCon a writable replica that hasa large number of expired keys directly written to it, the main thread
gets blocked for an extended period while synchronously releasing the
slaveKeysWithExpiredictionary.Root Cause
FLUSHALL ASYNCis designed for asynchronous lazy freeing of core datastructures, but the release of
slaveKeysWithExpire(a dictionary trackingexpired 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
slaveKeysWithExpireto the lazyfree background thread, aligning it with the asynchronous design
of
FLUSHALL ASYNCand eliminating main thread blocking.User scenarios
In some operations, people often need to do primary-replica switches.
One goal is to avoid noticeable impact on the business—like key loss
or reduced availability (e.g., write failures).
Here is the process: First, temporarily switch traffic to writable replicas.
Then we wait for the primary pending replication data to be fully synced
(so primry and replicas are in sync), before finishing the switch. We don't
usually need to do the flush in this case, but it's an optimization that can
be done.
other infomation
This PR includes the same changes that were previously submitted to valkey and have been merged.
valkey-io/valkey#2849