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

Make stale read and history read compatible with coprocessor cache #22510

Open
djshow832 opened this issue Jan 25, 2021 · 0 comments
Open

Make stale read and history read compatible with coprocessor cache #22510

djshow832 opened this issue Jan 25, 2021 · 0 comments
Labels
component/coprocessor sig/execution SIG execution sig/transaction SIG:Transaction type/enhancement The issue or PR belongs to an enhancement.

Comments

@djshow832
Copy link
Contributor

Background

This is a subtask of #21094.

The coprocessor cache caches a response for each request on the TiDB side. If two coprocessor requests are equivalent, the second request may skip being processed on the TiKV side. However, the request is still sent to TiKV, because TiKV needs to judge whether the cached response is still valid.

For stale read and history read, the requested snapshot is older than the current. What concerns us is whether the coprocessor cache is still always valid for these kinds of reading.

Analysis

The coprocessor cache is hit when (see copIteratorWorker.handleTaskOnce and copIteratorWorker.handleCopResponse):

  • The number of requested ranges, the data size of the response, and the processing time of the request are all within the thresholds. That is, the response deserves to be cached.
  • The region ID of the request and the cached response equals. That is, the region doesn't split or merge after it's cached.
  • The start TS of the cached response is not greater than the start TS of the request. That is, the cached response won't be too new for the request.
  • The applied index of this region doesn't change between the start TS of the cached response and the request. That is, the region is untouched after the response is cached. This is judged on the TiKV side.

Through the last two conditions, we can infer that as long as the start TS of the transactions of stale read and history read is set correctly, the cached response will be valid.

Conclusion

We don't need to change anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/coprocessor sig/execution SIG execution sig/transaction SIG:Transaction type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

1 participant