Clear stale region info actively in the background #40461
Labels
affects-5.4
This bug affects the 5.4.x(LTS) versions.
affects-6.1
This bug affects the 6.1.x(LTS) versions.
affects-6.5
This bug affects the 6.5.x(LTS) versions.
sig/transaction
SIG:Transaction
type/enhancement
The issue or PR belongs to an enhancement.
Enhancement
tikv/client-go#566 is a lazy approach to clear stale region info in the region cache. It only removes intersecting regions when a new region is inserted into the region cache.
To make this approach work, the region that covers the ranges of stale regions must be touched again. If the user never touches these regions, the stale region info may stay in the memory forever.
Therefore, it's better to have a mechanism to clear stale region info actively.
We can start a background goroutine for cleanup work. It runs in an infinite loop, iterating the whole region cache and find stale region info to clean. Now, the TTL of a region in the cache is 10 minutes.
It requires a lock to manipulate the region cache. We don't want the cleanup goroutine to affect normal jobs. We can cut the work into very small pieces:
Then, every hour, we can iterate over 180,000 regions, which is enough to cover all regions in the cache in most cases.
The text was updated successfully, but these errors were encountered: