Skip to content

util/encoding: support deep copying when decoding bytes ascending#70740

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:encoding-deep-copy
Sep 27, 2021
Merged

util/encoding: support deep copying when decoding bytes ascending#70740
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:encoding-deep-copy

Conversation

@yuzefovich
Copy link
Copy Markdown
Member

There is an optimization when decoding bytes ascending when it might
return the decoded value that shares the same storage as the input
buffer. However, this optimization might not be desirable in all cases:
in particular, if the input buffer came from the large BatchResponse,
then the decoded value might keep that whole response from being GCed.
This commit adds a couple of methods to avoid using the shared storage
by always performing a deep copy. It also audits all callers of the
relevant methods on the KV-SQL boundary (the fetchers) to make sure they
perform the deep copy when needed.

Release note: None

@yuzefovich yuzefovich requested a review from a team September 25, 2021 17:41
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

There is an optimization when decoding bytes ascending when it might
return the decoded value that shares the same storage as the input
buffer. However, this optimization might not be desirable in all cases:
in particular, if the input buffer came from the large BatchResponse,
then the decoded value might keep that whole response from being GCed.
This commit adds a couple of methods to avoid using the shared storage
by always performing a deep copy. It also audits all callers of the
relevant methods on the KV-SQL boundary (the fetchers) to make sure they
perform the deep copy when needed.

Release note: None
Copy link
Copy Markdown
Contributor

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)

@yuzefovich
Copy link
Copy Markdown
Member Author

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Sep 27, 2021

Build succeeded:

@craig craig bot merged commit 260cc0a into cockroachdb:master Sep 27, 2021
@yuzefovich yuzefovich deleted the encoding-deep-copy branch September 27, 2021 15:07
craig bot pushed a commit that referenced this pull request Nov 18, 2021
70768: release-21.2: util/encoding: support deep copying when decoding bytes ascending r=yuzefovich a=blathers-crl[bot]

Backport 1/1 commits from #70740 on behalf of @yuzefovich.

/cc @cockroachdb/release

----

There is an optimization when decoding bytes ascending when it might
return the decoded value that shares the same storage as the input
buffer. However, this optimization might not be desirable in all cases:
in particular, if the input buffer came from the large BatchResponse,
then the decoded value might keep that whole response from being GCed.
This commit adds a couple of methods to avoid using the shared storage
by always performing a deep copy. It also audits all callers of the
relevant methods on the KV-SQL boundary (the fetchers) to make sure they
perform the deep copy when needed.

Release note: None

----

Release justification:

72253: release-21.2: coldata: fix BenchmarkAppend so that it could be run with multiple count r=yuzefovich a=blathers-crl[bot]

Backport 1/1 commits from #72132 on behalf of @yuzefovich.

/cc @cockroachdb/release

----

Previously, we could get an index out of bounds because we'd allocate
larger `Bytes.data` slice than `int32` offset can support.

Release note: None

----

Release justification:

Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
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