Skip to content

sql: add RevertTable wrapper for RevertRangeRequest#39206

Merged
craig[bot] merged 3 commits intocockroachdb:masterfrom
dt:revert-table
Aug 8, 2019
Merged

sql: add RevertTable wrapper for RevertRangeRequest#39206
craig[bot] merged 3 commits intocockroachdb:masterfrom
dt:revert-table

Conversation

@dt
Copy link
Copy Markdown
Contributor

@dt dt commented Aug 1, 2019

(first commit is #39251)

kv,batcheval: fix RevertRange to work with DistSender and ResumeSpans

This patch includes several changes required to make RevertRange requests
get along with DistSender:

1) add RevertRange to the explicit check for maxkey-supported requests.
2) makes RevertRangeResponse combinable, however combining assumes
that at-most-one reply returned a ResumeSpan, so it also
3) sets NumKeys to MaxKeys in RevertRange when returning a ResumeSpan,
to stop distsender from sending any further requests that might also hit
a resume and then trip up combining.

Together these make it possible to send batches of RevertRange requests
via DistSender and get back resume spans.

Release note: none.

sql: add RevertTables helper for reverting a Table via RevertRange

This adds a helper that can revert a collection of tables to a target
timestamp using the RevertRange RPC.

It checks that the tables do not  overlap the key space of another table
not being reverted (i.e. that all the reverting tables are interleaved,
if at all, only with each other) and that the tables are offline.

It then reverts the table spans using RevertRange, including handling
the ResumeSpan pagination.

Release note: none.

@dt dt requested review from a team, adityamaru27, nvb and thoszhang August 1, 2019 14:29
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@nvb nvb left a comment

Choose a reason for hiding this comment

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

Reviewed the Core portion of this.

Reviewed 1 of 1 files at r2, 4 of 4 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru27, @dt, @lucy-zhang, and @nvanbenschoten)


pkg/storage/batcheval/cmd_revert_range.go, line 101 at r3 (raw file):

		log.VEventf(ctx, 2, "hit limit while clearing keys, resume span [%v, %v)", resume.Key, resume.EndKey)
		reply.ResumeSpan = resume
		reply.NumKeys = cArgs.MaxKeys

I think we should be returning this from MVCCClearTimeRange and setting it unconditionally.

Copy link
Copy Markdown
Contributor Author

@dt dt left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru27, @lucy-zhang, and @nvanbenschoten)


pkg/storage/batcheval/cmd_revert_range.go, line 101 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

I think we should be returning this from MVCCClearTimeRange and setting it unconditionally.

I initially didn't want to set it at all -- unlike, say, ScanRequest, I don't care about how many total keys I've touched since there isn't a result set of that size coming back to me. The MaxScanRequestKeys is being set to, and only to, limit the max batch sizes. That said, I found that distsender didn't behave well with multiple ResumeSpans, so I ended up setting it when, and only when, returning a resume span, to make DistSender break out of its send loop, and thus we want to set it to exactly the limit.

If we were actually always returning the number of keys cleared or the number of writes in the batch, then I could see having it come from MVCCClearTimeRange, but we don't want to set it to either of those, since the first doesn't make sense if we're able to clear thousands of keys with a single ClearRange, and both don't really make sense when they debit from an overall limit shared access requests. Since the the number being returned here is being picked solely for distsender's benefit, it felt odd to have that logic in MVCCClearTimeRange.

Copy link
Copy Markdown

@thoszhang thoszhang left a comment

Choose a reason for hiding this comment

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

I reviewed the sql part.

Reviewed 3 of 3 files at r1, 1 of 1 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru27, @lucy-zhang, and @nvanbenschoten)

Copy link
Copy Markdown
Contributor

@nvb nvb left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru27)


pkg/storage/batcheval/cmd_revert_range.go, line 101 at r3 (raw file):

Previously, dt (David Taylor) wrote…

I initially didn't want to set it at all -- unlike, say, ScanRequest, I don't care about how many total keys I've touched since there isn't a result set of that size coming back to me. The MaxScanRequestKeys is being set to, and only to, limit the max batch sizes. That said, I found that distsender didn't behave well with multiple ResumeSpans, so I ended up setting it when, and only when, returning a resume span.

If we were actually always returning the number of keys cleared (certainly don't want to do that since I don't want to bail early if a single ClearRange could get them all), or the number of writes in the batch (Clears+ClearRanges), then I could see having it come from MVCCClearTimeRange, but given that the number returned here is being picked for distsender's benefit, it felt odd to have that logic in MVCCClearTimeRange.

Ok, this all sounds reasonable to me. Please document this here then.

Copy link
Copy Markdown
Contributor Author

@dt dt left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru27 and @nvanbenschoten)


pkg/storage/batcheval/cmd_revert_range.go, line 101 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Ok, this all sounds reasonable to me. Please document this here then.

Done.

dt added 3 commits August 7, 2019 13:03
This patch includes several changes required to make RevertRange requests
get along with DistSender:

1) add RevertRange to the explicit check for maxkey-supported requests.
2) makes RevertRangeResponse combinable, however combining assumes
that at-most-one reply returned a ResumeSpan, so it also
3) sets NumKeys to MaxKeys in RevertRange when returning a ResumeSpan,
to stop distsender from sending any further requests that might also hit
a resume and then trip up combining.

Together these make it possible to send batches of RevertRange requests
via DistSender and get back resume spans.

Release note: none.
This adds a helper that can revert a collection of tables to a target 
timestamp using the RevertRange RPC.

It checks that the tables do not  overlap the key space of another table
not being reverted (i.e. that all the reverting tables are interleaved, 
if at all, only with each other) and that the tables are offline.

It then reverts the table spans using RevertRange, including handling
the ResumeSpan pagination.

Release note: none.
@dt
Copy link
Copy Markdown
Contributor Author

dt commented Aug 7, 2019

bors r+

@dt
Copy link
Copy Markdown
Contributor Author

dt commented Aug 8, 2019

looks like bors timed out

bors r+

craig bot pushed a commit that referenced this pull request Aug 8, 2019
39206: sql: add RevertTable wrapper for RevertRangeRequest r=dt a=dt

(first commit is #39251)

kv,batcheval: fix RevertRange to work with DistSender and ResumeSpans

    This patch includes several changes required to make RevertRange requests
    get along with DistSender:

    1) add RevertRange to the explicit check for maxkey-supported requests.
    2) makes RevertRangeResponse combinable, however combining assumes
    that at-most-one reply returned a ResumeSpan, so it also
    3) sets NumKeys to MaxKeys in RevertRange when returning a ResumeSpan,
    to stop distsender from sending any further requests that might also hit
    a resume and then trip up combining.

    Together these make it possible to send batches of RevertRange requests
    via DistSender and get back resume spans.

    Release note: none.

sql: add RevertTables helper for reverting a Table via RevertRange

    This adds a helper that can revert a collection of tables to a target
    timestamp using the RevertRange RPC.

    It checks that the tables do not  overlap the key space of another table
    not being reverted (i.e. that all the reverting tables are interleaved,
    if at all, only with each other) and that the tables are offline.

    It then reverts the table spans using RevertRange, including handling
    the ResumeSpan pagination.

    Release note: none.

39427: storage/engine: don't decrement IntentCount on system intent abort r=nvanbenschoten a=nvanbenschoten

Fixes #39390.
Fixes #39407.
Fixes #39370.
Fixes #39419.

A bug introduced in #39251 was causing the IntentCount field in MVCCStats to get out of sync.

I was expecting `TestMVCCStatsRandomized/sys/inline=false` to easily catch the bug, but it wasn't. It turns out that the test was updating the transaction's write timestamp but not its read timestamp, which was causing it to hit this error:
https://github.com/cockroachdb/cockroach/blob/41cb28e85575292926790e79912c893d13e1054d/pkg/storage/engine/mvcc.go#L1349
This was preventing the randomized test from performing the series of steps we needed it to hit the bug.

This commit fixes the bug, fixes the randomized test so that it would have caught it, and adds a targeted regression test for this case.

Release note: None

Co-authored-by: David Taylor <tinystatemachine@gmail.com>
Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Aug 8, 2019

Build succeeded

@craig craig bot merged commit fd8871a into cockroachdb:master Aug 8, 2019
@dt dt deleted the revert-table branch August 8, 2019 11:31
@dt dt restored the revert-table branch August 8, 2019 11:35
@dt dt deleted the revert-table branch August 8, 2019 11:35
@dt dt restored the revert-table branch August 8, 2019 11:37
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