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

feat(storage): Implement io.WriterTo in Reader #9659

Merged
merged 5 commits into from
Mar 28, 2024

Conversation

tritone
Copy link
Contributor

@tritone tritone commented Mar 28, 2024

This allows the gRPC Reader to write directly into the application write buffer, saving a data copy.

Users can get the benefit of this directly by explicitly calling Reader.WriteTo, but they can also benefit implicitly if they are calling io.Copy.

A bunch of checksum logic had to be moved from the parent Reader into the transport Readers to make this work, since we need to update the checksum for every message read in WriteTo.

@tritone tritone requested review from a team as code owners March 28, 2024 07:35
@tritone tritone force-pushed the writerto-review branch 2 times, most recently from 6252744 to 1d1700d Compare March 28, 2024 07:48
@tritone tritone added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 28, 2024
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 28, 2024
@tritone tritone changed the title feat(storage) Implement io.WriterTo in Reader feat(storage): Implement io.WriterTo in Reader Mar 28, 2024
Copy link

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

This allows the gRPC Reader to write directly into the application
write buffer, saving a data copy.

Users can get the benefit of this directly by explicitly calling
Reader.WriteTo, but they can also benefit implicitly if they are
calling io.Copy.

A bunch of checksum logic had to be moved from the parent Reader
into the transport Readers to make this work, since we need to
update the checksum for every message read in WriteTo.
Copy link
Member

@codyoss codyoss left a comment

Choose a reason for hiding this comment

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

Just a couple of nits or else LGTM

wantCRC uint32
checkCRC bool
)
if checksums := msg.GetObjectChecksums(); checksums != nil && checksums.Crc32C != nil && params.offset == 0 && params.length < 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I don't have the full context here, but do you really want params.length to be negative here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is so that we only check the checksums on the entire object read, in which case params.length would be negative to indicate no limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Brenna is correct.

if err := r.runCRCCheck(); err != nil {
return 0, err
}
return 0, io.EOF
Copy link
Member

Choose a reason for hiding this comment

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

I noticed this above in the read too, but I wonder if these should be storage specific errors so users have more context? Or maybe wrapping happens at a higher layer. fmt.Errof("storage: something something: %w", io.EOF). Then your checks would need to be changed to errors.Is(err, io.EOF), but I think that change should happen regardless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think there is still more we can do to have more coherently wrapped errors. it's been on the back burner.

storage/grpc_client.go Outdated Show resolved Hide resolved
return 0, io.EOF
}

// No stream to read from, either never initialized or Close was called.
Copy link
Member

Choose a reason for hiding this comment

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

Is this handled in an above layer or is this documented as such on the public way this methods is called into?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's handled in an above layer; the stream is always initialized in NewRangeReader. Really the only way you can trigger this is as an end user is by calling Close and then trying to read more.

storage/http_client.go Outdated Show resolved Hide resolved
storage/retry_conformance_test.go Show resolved Hide resolved
storage/grpc_client.go Outdated Show resolved Hide resolved
Copy link
Contributor

@BrennaEpp BrennaEpp left a comment

Choose a reason for hiding this comment

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

Thanks Chris!

@tritone tritone added the automerge Merge the pull request once unit tests and other checks pass. label Mar 28, 2024
@tritone tritone merged commit 8264a96 into googleapis:main Mar 28, 2024
9 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Mar 28, 2024
@tritone tritone deleted the writerto-review branch March 28, 2024 20:13
gcf-merge-on-green bot pushed a commit that referenced this pull request Mar 29, 2024
🤖 I have created a release *beep* *boop*
---


## [1.40.0](https://github.com/googleapis/google-cloud-go/compare/storage/v1.39.1...storage/v1.40.0) (2024-03-29)


### Features

* **storage:** Implement io.WriterTo in Reader ([#9659](https://github.com/googleapis/google-cloud-go/issues/9659)) ([8264a96](https://github.com/googleapis/google-cloud-go/commit/8264a962d1c21d52e8fca50af064c5535c3708d3))
* **storage:** New storage control client ([#9631](https://github.com/googleapis/google-cloud-go/issues/9631)) ([1f4d279](https://github.com/googleapis/google-cloud-go/commit/1f4d27957743878976d6b4549cc02a5bb894d330))


### Bug Fixes

* **storage:** Retry errors from last recv on uploads ([#9616](https://github.com/googleapis/google-cloud-go/issues/9616)) ([b6574aa](https://github.com/googleapis/google-cloud-go/commit/b6574aa42ebad0532c2749b6ece879b932f95cb9))
* **storage:** Update protobuf dep to v1.33.0 ([30b038d](https://github.com/googleapis/google-cloud-go/commit/30b038d8cac0b8cd5dd4761c87f3f298760dd33a))


### Performance Improvements

* **storage:** Remove protobuf's copy of data on unmarshalling ([#9526](https://github.com/googleapis/google-cloud-go/issues/9526)) ([81281c0](https://github.com/googleapis/google-cloud-go/commit/81281c04e503fd83301baf88cc352c77f5d476ca))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
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