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

storage: use resume span to set ts cache #21304

Merged

Conversation

spencerkimball
Copy link
Member

@spencerkimball spencerkimball commented Jan 7, 2018

Previously, we were updating the timestamp cache based on the rows
returned during scans and reverse scans. However, not only was this
inconsistent with how we gather intent spans for resolving on end
transaction, it was actually out of step with results actually
read, meaning we were not setting the timestamp cache properly to
reflect results read and returned. Consider the following scenario:

  • Scan from "a" to "d", max results stops at "b".
  • Current MVCCScan will seek past "b", find next key (let's say "c")
    and return resume span "c" - "d"
  • However, we were updating timestamp cache for the span "a" - "b".Next().
  • That leaves all of the keys from "b".Next() - "c" unprotected by
    the timestamp cache, so history can be rewritten under the span
    on successive resumes at the same timestamp.

Now, we correctly use the resume span to update the timestamp cache,
which is both consistent with other uses and correctly updates the
timestamp cache based on results actually read.

Release note: None

@spencerkimball spencerkimball requested review from tbg, petermattis and a team January 7, 2018 18:02
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@petermattis
Copy link
Collaborator

:lgtm:

We were previously always seeking to the next key beyond the maximum
keys allowed for a scan in order to find out if there were any more
left in the iteration. However, that case is the exception, not the
rule and the performance is impacted for any iteration which sets
max keys to 1.

How many iterations set max-keys to 1? I don't think SQL queries do that, but perhaps they do. Have you checked?


Review status: 0 of 4 files reviewed at latest revision, all discussions resolved, some commit checks pending.


Comments from Reviewable

@spencerkimball
Copy link
Member Author

@petermattis actually I backed out that part of the change. It broke some really nasty tests and I think it's safer just not to change behavior, but to fix the timestamp cache issues only. PTAL.

@spencerkimball spencerkimball changed the title storage: avoid extra seek on scans, use resume span to set ts cache storage: use resume span to set ts cache Jan 7, 2018
Previously, we were updating the timestamp cache based on the rows
returned during scans and reverse scans. However, not only was this
inconsistent with how we gather intent spans for resolving on end
transaction, it was actually out of step with results actually
read, meaning we were not setting the timestamp cache properly to
reflect results read and returned. Consider the following scenario:
- Scan from "a" to "d", max results stops at "b".
- Current MVCCScan will seek past "b", find next key (let's say "c")
  and return resume span "c" - "d"
- However, we were updating timestamp cache for the span "a" - "b".Next().
- That leaves all of the keys from "b".Next() - "c" unprotected by
  the timestamp cache, so history can be rewritten under the span
  on successive resumes at the same timestamp.

Now, we correctly use the resume span to update the timestamp cache,
which is both consistent with other uses and correctly updates the
timestamp cache based on results actually read.

Release note: None
@petermattis
Copy link
Collaborator

:lgtm:


Review status: 0 of 4 files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from Reviewable

@nvanbenschoten
Copy link
Member

:lgtm:

We were previously always seeking to the next key beyond the maximum
keys allowed for a scan in order to find out if there were any more
left in the iteration. However, that case is the exception, not the
rule and the performance is impacted for any iteration which sets
max keys to 1.

I'm curious what the change that was backed out was doing. Just so we have a documented history, do you mind explaining?

With your comment in mind, it looks to me like resumeSpans may have been defined questionably in the first place. I would expect that we would return lastKey.Next() as the start of a forward resume span, or even just lastKey if we added an "exclusive start" flag on ScanRequests. This way, we would never miss an update to the tscache because any subsequent scans would start immediately after the previous scan stopped, with no gaps in-between. Was adjusting the resumeSpan semantics the change you tried to make?


Reviewed 1 of 4 files at r1.
Review status: 1 of 4 files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from Reviewable

@spencerkimball spencerkimball merged commit 742b93b into cockroachdb:master Jan 8, 2018
@spencerkimball spencerkimball deleted the update-resume-span-calcs branch January 8, 2018 14:54
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.

4 participants