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

introduce a random jitter to region cache ttl #1148

Merged
merged 5 commits into from
Feb 2, 2024

Conversation

zyguan
Copy link
Contributor

@zyguan zyguan commented Jan 31, 2024

Ref #1122 (comment) and #1104 .

This PR tries to address #1122 (comment) by introducing a random jitter to region cache TTL.

To observe the reason of region reloading, the methods for searching cached regions are refactored.

Signed-off-by: zyguan <zhongyangguan@gmail.com>
Signed-off-by: zyguan <zhongyangguan@gmail.com>
Signed-off-by: zyguan <zhongyangguan@gmail.com>
@zyguan zyguan marked this pull request as ready for review January 31, 2024 13:51
@cfzjywxk
Copy link
Contributor

cfzjywxk commented Feb 1, 2024

@crazycs520 PTAL

if regionCacheTTLJitterSec > 0 {
jitter = rand.Int63n(regionCacheTTLJitterSec)
}
return ts + regionCacheTTLSec + jitter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to add some constraint checks to make sure the unit of the input ts is second, to avoid being used mistakenly?

Copy link
Contributor Author

@zyguan zyguan Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pass ts here to avoid overhead of time.Now(). To validate it, maybe we can:

  • record process start ts by a global var (eg. processStartTs)
  • the ts might be invalid if ts - processStartTs > 100 years or ts < processStartTs
  • if the ts is invalid, we can fallback to call time.Now()

But do we really need to do that? There are many mechanisms to invalidate a stale region, it might be not a big problem even when we call nextTTL with epoch millis, I guess.

Or, we can just change the function signature (also many releated functions like checkRegionCacheTTL), let it (them) accept an arg of type time.Time. (I've tried this, but gave up, since it will introduce a lot of changes)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could just add some comments to explain the constraints of the input ts in the comment if it's not a big problem when used mistakenly.

Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

Signed-off-by: zyguan <zhongyangguan@gmail.com>
Copy link
Contributor

@you06 you06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rest LGTM

internal/locate/region_cache.go Show resolved Hide resolved
@cfzjywxk cfzjywxk merged commit 8b3b01e into tikv:master Feb 2, 2024
10 checks passed
@zyguan zyguan mentioned this pull request Feb 22, 2024
8 tasks
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.

3 participants