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

filetable: fix NPE when an empty file is downloaded from userfile #63467

Merged
merged 1 commit into from
Apr 19, 2021

Conversation

adityamaru
Copy link
Contributor

Fixes: #62605

Release note: None

@adityamaru adityamaru requested a review from pbardea April 12, 2021 10:30
@adityamaru adityamaru requested a review from a team as a code owner April 12, 2021 10:30
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@stevendanna stevendanna 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 @adityamaru and @pbardea)

a discussion (no related file):
Looks reasonable to me. It might be nice to write a few words in the commit message about why we aren't using the size field in the metadata table.



pkg/cli/userfiletable_test.go, line 175 at r1 (raw file):

		})

		t.Run("get", func(t *testing.T) {

tc.name+"_get" might make for clearer output


pkg/cli/userfiletable_test.go, line 181 at r1 (raw file):

			cliOutput, err := c.RunWithCaptureArgs(cmd)
			require.NoError(t, err)
			if strings.Contains(cliOutput, "ERROR: no files matched requested path or path pattern") {

Would it be worth it to be less strict here? Given the line below, I imagine anything starting with ERROR would be unexpected.

It's a little unfortunate that RunWithCaptureArgs swallows the error produced by what I hope would be the non-zero exit of the command.

Copy link
Contributor

@miretskiy miretskiy 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 @adityamaru and @pbardea)


pkg/storage/cloudimpl/filetable/file_table_read_writer.go, line 701 at r1 (raw file):

		fileID = vals[0].([]byte)
		if vals[1] != nil {
			sz = vals[1].(int64)

perhaps we should use tree.MustBeX methods instead of direct cases?

Copy link
Contributor

@pbardea pbardea 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 @adityamaru and @stevendanna)


pkg/cli/userfiletable_test.go, line 175 at r1 (raw file):

Previously, stevendanna (Steven Danna) wrote…

tc.name+"_get" might make for clearer output

As a bonus, it looks like these other test cases would be good candidates for subtests of the tc.name one above, which would help avoid the awkward tc.name+subTestName formulation for all of these subtests.

This change ensures that a file with a metadata entry but no payload
does not throw an exception when attempting to compute the size of the
file (which will be zero).

Fixes: cockroachdb#62605

Release note: None
Copy link
Contributor Author

@adityamaru adityamaru 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 @miretskiy and @stevendanna)

a discussion (no related file):

Previously, stevendanna (Steven Danna) wrote…

Looks reasonable to me. It might be nice to write a few words in the commit message about why we aren't using the size field in the metadata table.

I wanted to minimize the diff so that we can consider a backport for this, but apart from that I don't really see a reason we can't consult the file size we write in the metadata row. I guess there is an argument that this is the most accurate source of truth, but if the former were to go out of sync we probably have another bug.



pkg/cli/userfiletable_test.go, line 175 at r1 (raw file):

Previously, pbardea (Paul Bardea) wrote…

As a bonus, it looks like these other test cases would be good candidates for subtests of the tc.name one above, which would help avoid the awkward tc.name+subTestName formulation for all of these subtests.

Done.


pkg/cli/userfiletable_test.go, line 181 at r1 (raw file):

Previously, stevendanna (Steven Danna) wrote…

Would it be worth it to be less strict here? Given the line below, I imagine anything starting with ERROR would be unexpected.

It's a little unfortunate that RunWithCaptureArgs swallows the error produced by what I hope would be the non-zero exit of the command.

Done.


pkg/storage/cloudimpl/filetable/file_table_read_writer.go, line 701 at r1 (raw file):

Previously, miretskiy (Yevgeniy Miretskiy) wrote…

perhaps we should use tree.MustBeX methods instead of direct cases?

The internal executor above can use these methods because the results of the iterator are Datums, but for a SQLConnExecutor the results are driver.Value which I believe can't be converted to datums easily.

Copy link
Collaborator

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r1, 1 of 1 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @miretskiy and @stevendanna)

@adityamaru
Copy link
Contributor Author

TFTR!
bors r=stevendanna

@craig
Copy link
Contributor

craig bot commented Apr 19, 2021

Build succeeded:

@craig craig bot merged commit b8553b7 into cockroachdb:master Apr 19, 2021
@adityamaru adityamaru deleted the userfile-size-npe branch April 20, 2021 18:14
@rafiss rafiss added this to the 21.1 milestone Apr 22, 2021
@rafiss
Copy link
Collaborator

rafiss commented May 27, 2021

@adityamaru friendly ping on this: does this still need to be backported?

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.

userfile: interface cast exception if the file has a metadata entry but no payload
6 participants