-
Notifications
You must be signed in to change notification settings - Fork 167
feat(experimental): add write resumption strategy #1663
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @Pulkit0110, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the reliability of asynchronous bidirectional streaming operations by introducing a comprehensive write resumption strategy and a generic retry manager. This refactoring centralizes error handling and retry logic, making both read and write operations more resilient to transient failures and network interruptions. The changes ensure that data transfers can seamlessly resume from the last known good state, improving the overall robustness of the system. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a generic retry manager for bidi streams and applies it to read operations, which is a great improvement for resiliency. It also adds a resumption strategy for write operations. The overall structure is well-designed and the new tests are comprehensive. I've found one critical issue that will cause a TypeError at runtime due to a method being called with an unexpected argument. I've also included a couple of medium-severity comments to improve documentation clarity and maintainability in the new strategy classes.
google/cloud/storage/_experimental/asyncio/async_multi_range_downloader.py
Show resolved
Hide resolved
google/cloud/storage/_experimental/asyncio/retry/reads_resumption_strategy.py
Show resolved
Hide resolved
google/cloud/storage/_experimental/asyncio/retry/writes_resumption_strategy.py
Show resolved
Hide resolved
7d63612 to
8c2a143
Compare
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a write resumption strategy for handling bidi write operations, which is a valuable addition for improving error handling in experimental async features. The implementation is well-structured and accompanied by a comprehensive set of unit tests that cover various scenarios, including initial uploads, resumption, and failure recovery. My feedback focuses on enhancing type safety, improving code clarity by addressing a potentially unused flag, and increasing the robustness of the tests by using mocks instead of None.
| self.user_buffer = user_buffer | ||
| self.persisted_size: int = 0 | ||
| self.bytes_sent: int = 0 | ||
| self.write_handle: Union[bytes, Any, None] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type hint for write_handle uses Any, which is too broad and reduces type safety. The docstring on line 34 correctly specifies the type as bytes | BidiWriteHandle | None. To improve clarity and type safety, please use the more specific storage_type.BidiWriteHandle instead of Any.
| self.write_handle: Union[bytes, Any, None] = None | |
| self.write_handle: Union[bytes, storage_type.BidiWriteHandle, None] = None |
| write_state: _WriteState = state["write_state"] | ||
|
|
||
| # Mark that we have generated the first request for this stream attempt | ||
| state["first_request"] = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The state['first_request'] flag is set to False here and in recover_state_on_failure, but its value is never read within the _WriteResumptionStrategy class. This makes its purpose unclear and could be confusing for future maintenance. If this flag is no longer used, it should be removed. If it is used by an external component, its purpose should be documented.
| def test_update_state_from_response_ignores_smaller_persisted_size(self): | ||
| strategy = self._make_one() | ||
| state = { | ||
| "write_state": _WriteState(None, 0, None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initializing _WriteState with None for arguments that expect objects (spec and user_buffer) makes this test brittle. If the implementation of update_state_from_response changes in the future to access attributes of spec or user_buffer, this test will fail with an AttributeError. It's safer to use mock objects to ensure the test is robust against such changes.
| "write_state": _WriteState(None, 0, None), | |
| "write_state": _WriteState(mock.Mock(spec=storage_type.AppendObjectSpec), 0, mock.Mock(spec=io.BytesIO)), |
Adding writes resumption strategy which will be used for error handling of bidi writes operation.