Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear stale region info actively in the background #40461

Closed
sticnarf opened this issue Jan 10, 2023 · 0 comments · Fixed by #40622
Closed

Clear stale region info actively in the background #40461

sticnarf opened this issue Jan 10, 2023 · 0 comments · Fixed by #40622
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 sig/transaction SIG:Transaction type/enhancement The issue or PR belongs to an enhancement.

Comments

@sticnarf
Copy link
Contributor

sticnarf commented Jan 10, 2023

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:

  • Start iterating second
  • Iterate only 50 regions every time
  • Record the end position and resume from the position in the next round

Then, every hour, we can iterate over 180,000 regions, which is enough to cover all regions in the cache in most cases.

@sticnarf sticnarf added the type/enhancement The issue or PR belongs to an enhancement. label Jan 10, 2023
ti-chi-bot pushed a commit that referenced this issue Jan 16, 2023
@VelocityLight VelocityLight added affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 labels Jan 29, 2023
@jebter jebter added the sig/transaction SIG:Transaction label Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects 5.4.x versions. affects-6.1 affects-6.5 sig/transaction SIG:Transaction type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants