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

release-20.1: kv: batch ranged intent resolution #47032

Merged

Conversation

nvanbenschoten
Copy link
Member

Backport 6/6 commits from #46952.

/cc @cockroachdb/release


Fixes #46752.
Resolves the recent perf regression on TPC-C.

This commit follows in the footsteps of #34803 and introduces batching for ranged intent resolution, where previously only point intent resolution was batched. As we found in #46752, this is more important than it has been in the past, because implicit SELECT FOR UPDATE acquires a ranged lock on each row that it updates instead of a single-key lock.

The change addresses this by adding a third request batcher to IntentResolver. ResolveIntent requests and ResolveIntentRange requests are batched separately, which is necessary for the use of MaxSpanRequestKeys to work properly (in fact, to be accepted by DistSender at all).

To accommodate the ranged nature of ResolveIntentRange request, the notion of pagination is introduced into RequestBatcher. A MaxKeysPerBatchReq option is added to the configuration of a RequestBatcher, which corresponds to the MaxSpanRequestKeys value set on each BatchRequest header. The RequestBatcher is then taught about request pagination and how to work with partial responses. The semantics at play here are clarified in an earlier commit in the PR.

Release justification: important fix to avoid a performance regression when implicit SELECT FOR UPDATE is enabled. All commits except the last are testing-only. The last commit is subtle but small and well-tested.

@andreimatei: I assigned you because I think you know the most about MaxSpanRequestKeys. I'm mostly interested to get your input on the "rationalize Header.MaxSpanRequestKeys" commit (testing + comments only).

Before this change, `var br *roachpb.BatchResponse` was being forced
onto the heap:
```
$ goescape . | grep moved
./batcher.go:262:6: moved to heap: br
```

By moving the closures into the RunWorker function, we avoid the
allocation:
```
$ goescape . | grep moved | wc -l
0
```

Release justification: probably none. I'll sit on this if it's alone.
Previously, the only way to access this functionality outside of
the roachpb package was through the BatchResponse.Combine method.
There doesn't seem to be a strong reason for this encapsulation,
given that Response is an exported part of the roachpb interface.
This has long-since been replaced by `t.Helper()`.
This uses of this have long-since been replaceable by `t.Helper()`.
…uests

This commit improves the contract around MaxSpanRequestKeys and its interaction
with overlapping and unsorted requests. Instead of saying that only sorted,
non-overlapping requests were allowed in a batch with a limit (which was not
being respected by users of the KV API), we now discuss what callers should
expect if they cannot provide one or both of these guarantees.

The commit then improves the testing around this area.
Fixes cockroachdb#46752.
Resolves the recent perf regression on TPC-C.

This commit follows in the footsteps of cockroachdb#34803 and introduces batching for
ranged intent resolution, where previously only point intent resolution was
batched. As we found in cockroachdb#46752, this is more important than it has been in
the past, because implicit SELECT FOR UPDATE acquires a ranged lock on each
row that it updates instead of a single-key lock.

The change addresses this by adding a third request batcher to IntentResolver.
ResolveIntent requests and ResolveIntentRange requests are batched separately,
which is necessary for the use of MaxSpanRequestKeys to work properly (in fact,
to be accepted by DistSender at all).

To accommodate the ranged nature of ResolveIntentRange request, the notion of
pagination is introduced into RequestBatcher. A MaxKeysPerBatchReq option is
added to the configuration of a RequestBatcher, which corresponds to the
MaxSpanRequestKeys value set on each BatchRequest header. The RequestBatcher is
then taught about request pagination and how to work with partial responses. See
the previous commit for clarification about the semantics at play here.

Release justification: important fix to avoid a performance regression when
implicit SELECT FOR UPDATE is enabled.
@nvanbenschoten nvanbenschoten requested a review from ajwerner April 4, 2020 15:47
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@andreimatei
Copy link
Contributor

andreimatei commented Apr 4, 2020 via email

@nvanbenschoten nvanbenschoten merged commit 4deb223 into cockroachdb:release-20.1 Apr 4, 2020
@nvanbenschoten nvanbenschoten deleted the backport20.1-46952 branch April 4, 2020 17:45
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