-
Notifications
You must be signed in to change notification settings - Fork 168
feat(experimental): integrate writes strategy and appendable object writer #1695
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?
feat(experimental): integrate writes strategy and appendable object writer #1695
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 improves the robustness of asynchronous object operations in Google Cloud Storage by implementing a sophisticated retry and resumption system for bidirectional streaming. It introduces dedicated strategies to manage the state of ongoing read and write operations, automatically re-establishing streams and continuing data transfer from the last known good state in the event of transient network issues or server-side redirects. This ensures that applications using these experimental APIs can handle intermittent failures gracefully, leading to more reliable data transfers. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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 significant and well-designed refactoring to integrate retry strategies for bidirectional reads and writes, enhancing the robustness of experimental asyncio features. The abstraction of retry logic into a _BidiStreamRetryManager and specific _WriteResumptionStrategy and _ReadResumptionStrategy classes is a solid architectural choice. The accompanying unit and conformance tests are comprehensive and provide good coverage for the new functionality. My review comments focus on improving error handling by replacing broad except Exception blocks with more specific ones and avoiding print() statements in library code.
| except Exception: | ||
| return 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.
| except Exception: | ||
| # Could not parse the error, ignore | ||
| pass |
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.
| except Exception as e: | ||
| print(f"--- Error parsing status_details_bin: {e}") | ||
| return 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.
Printing to stdout is generally discouraged in a library as it can pollute the application's output. It would be better to use the logging module to log this error. Also, catching a broad Exception can hide other issues. It would be better to catch a more specific exception, such as google.protobuf.message.DecodeError.
| except Exception as e: | ||
| print(f"--- Error unpacking redirect in _on_open_error: {e}") |
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.
| except Exception as e: | ||
| print(f"--- Error unpacking redirect in _on_open_error: {e}") |
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.
| except Exception: | ||
| # Could not parse the error, ignore | ||
| pass |
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.
c3ba20d to
36a02d7
Compare
36a02d7 to
5d39296
Compare
| BidiWriteObjectRedirectedError | ||
| ), | ||
| ): | ||
| logger.info(f"Retryable write exception encountered: {exc}") |
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.
make it warning
| if detail.type_url == _BIDI_WRITE_REDIRECTED_TYPE_URL: | ||
| return True | ||
| except Exception: | ||
| logger.error("Error unpacking redirect details from gRPC error.") |
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.
add Exception details in log
| self.flush_interval = writer_options.get( | ||
| "FLUSH_INTERVAL_BYTES", _DEFAULT_FLUSH_INTERVAL_BYTES | ||
| ) | ||
| # TODO: add test case for this. |
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.
remove this unwanted TODO.
| return routing_token, read_handle | ||
|
|
||
|
|
||
| def _extract_bidi_writes_redirect_proto(exc: Exception): |
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.
this method is almost same as _handle_redirect method. Please merge both of them. Also please refer to this comment
| self.persisted_size = response.persisted_size | ||
| return self.persisted_size | ||
|
|
||
| def _on_open_error(self, exc): |
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.
Please use the same method which is defined in MRD 's _on_open_error -
by moving it to _retry/helpers.py
Please refer to this comment
| try: | ||
| await self.write_obj_stream.close() | ||
| except Exception: # ignore cleanup errors | ||
| pass |
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.
log warning
| total_bytes = len(data) | ||
| if total_bytes == 0: | ||
| # TODO: add warning. | ||
| if not data: |
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.
log.debug("Empty bytes sent")
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _is_write_retryable(exc): |
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.
Please merge this and _is_read_retryable and move comment code to _helpers.py
| write_state.persisted_size = self.persisted_size | ||
| write_state.bytes_sent = self.persisted_size |
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.
If both are self.persisted_size , then why do we need 2 variables ?
| requests = strategy.generate_requests(state) | ||
|
|
||
| num_requests = len(requests) |
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.
observed regression in appends might be because of this, generating all at sending one by one.
instead try making generate_requests an true generator (ie have yield instead of return)
Integrate all the components required for bidi writes retries