Skip to content

coldata: prohibit Vec.Append from a vector into itself#76529

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:cleanup-append
Feb 14, 2022
Merged

coldata: prohibit Vec.Append from a vector into itself#76529
craig[bot] merged 1 commit intocockroachdb:masterfrom
yuzefovich:cleanup-append

Conversation

@yuzefovich
Copy link
Copy Markdown
Member

Currently, Vec.Append works in cases when the destination and the
source vectors are the same; this, however, is not necessary since the
only production use of that method is in
colexecutils.AppendOnlyBufferedBatch.AppendTuples, and there we're
appending values from an input batch into the append-only batch. We also
have linters in place that prohibit the usage of Vec.Append in
production code outside of that single spot, so it's safe to prohibit
the self-referencing Vec.Append.

Release note: None

@yuzefovich yuzefovich requested review from a team and michae2 February 14, 2022 19:25
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@michae2 michae2 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 @michae2 and @yuzefovich)


pkg/col/coldata/bytes.go, line 316 at r1 (raw file):

			panic("AppendSlice when b == src is only supported when srcStartIdx == srcEndIdx")
		}
	}

I'm a little confused by the check for CrdbTestBuild. Is the srcStartIdx == srcEndIdx precondition only necessary when this is called from a test? Because that's how I'm reading this code... but from the commit message it sounds like this precondition is always necessary regardless of whether this is called from a test or not.

Should the check instead be something like this? (I.e. only tests can call self-referencing AppendSlice, and then we check the precondition.)

if b == src && (!buildutil.CrdbTestBuild || srcStartIdx != srcEndIdx) {
  panic("...")
}

Currently, `Vec.Append` works in cases when the destination and the
source vectors are the same; this, however, is not necessary since the
only production use of that method is in
`colexecutils.AppendOnlyBufferedBatch.AppendTuples`, and there we're
appending values from an input batch into the append-only batch. We also
have linters in place that prohibit the usage of `Vec.Append` in
production code outside of that single spot, so it's safe to prohibit
the self-referencing `Vec.Append`.

Release note: None
Copy link
Copy Markdown
Member Author

@yuzefovich yuzefovich 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 @michae2)


pkg/col/coldata/bytes.go, line 316 at r1 (raw file):

Previously, michae2 (Michael Erickson) wrote…

I'm a little confused by the check for CrdbTestBuild. Is the srcStartIdx == srcEndIdx precondition only necessary when this is called from a test? Because that's how I'm reading this code... but from the commit message it sounds like this precondition is always necessary regardless of whether this is called from a test or not.

Should the check instead be something like this? (I.e. only tests can call self-referencing AppendSlice, and then we check the precondition.)

if b == src && (!buildutil.CrdbTestBuild || srcStartIdx != srcEndIdx) {
  panic("...")
}

It should be prohibited in all cases, and I simply wanted to save a conditional in production builds, but given that we already have several conditions in place there and the check is done about once per coldata.BatchSize, it's no big deal, so I made it all-the-time check.

Copy link
Copy Markdown
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm:

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

@yuzefovich
Copy link
Copy Markdown
Member Author

TFTR!

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Feb 14, 2022

Build succeeded:

@craig craig bot merged commit 24d886c into cockroachdb:master Feb 14, 2022
@yuzefovich yuzefovich deleted the cleanup-append branch February 14, 2022 22:30
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