test(spanner): add integration tests for Batch DML#5723
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements robust error handling for Batch DML operations in Spanner, specifically addressing cases where service-level errors are returned within successful gRPC responses. It introduces a CheckServiceError trait to normalize these responses and updates the execute_with_retry! macro to handle transaction state resets correctly during failures. Additionally, the PR includes comprehensive integration tests for various Batch DML scenarios and refactors response processing for better readability. Feedback was provided regarding the use of unwrap() in production code, which violates the project's style guide.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5723 +/- ##
==========================================
+ Coverage 97.88% 97.89% +0.01%
==========================================
Files 226 226
Lines 55691 55985 +294
==========================================
+ Hits 54512 54806 +294
Misses 1179 1179 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Removes the `unwrap()` call in `execute_with_retry` and also refactors the method to use a guard to ensure the transaction state remains valid.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request enhances the Spanner client's handling of Batch DML and lazy transaction starts. It introduces a LazyTransactionStartGuard to manage state transitions during inline begins and a CheckServiceError trait to identify service-level errors within successful RPC responses. The execute_with_retry! macro was refactored to utilize these components, ensuring more reliable transaction recovery and retries, particularly for aborted errors. Comprehensive integration tests for various Batch DML failure and continuation scenarios were also added. Reviewer feedback suggests further simplifying the macro logic by adopting more idiomatic Rust patterns, such as using Option combinators and the ? operator to handle result propagation and error extraction more concisely.
BeginTransactionhandling for Batch DML on the Emulator, as the Emulator can returnAbortedeven forBeginTransaction(this happens when there already is an active transaction on the Emulator)ExecuteBatchDmlResponseif the response returned a non-zero status code. This indicates that an error occurred for one of the statements in the batch (but not for the first statement).