feat(spanner): add BatchWrite transaction#5502
feat(spanner): add BatchWrite transaction#5502olavloite wants to merge 5 commits intogoogleapis:mainfrom
Conversation
Adds the foundations for batch write transactions. The public API will be added in a follow-up pull request.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5502 +/- ##
========================================
Coverage 97.77% 97.77%
========================================
Files 221 222 +1
Lines 51107 51291 +184
========================================
+ Hits 49971 50152 +181
- Misses 1136 1139 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Adds support for BatchWrite transactions. BatchWrite can be used to write large numbers of mutations to Spanner. A BatchWrite transaction is not guaranteed to be atomic. However, each MutationGroup in a BatchWrite transaction is guaranteed to be atomic. This change adds a method that returns a stream of responses and delegates all error handling to the application. A follow-up pull request will add a managed execution method that handles errors automatically.
f757e38 to
e79d1e7
Compare
dbolduc
left a comment
There was a problem hiding this comment.
Mostly curious about why we aren't using the type from the model.
| /// This method sends the mutation groups to Spanner and returns the responses as a stream. | ||
| /// Each response includes a status code that indicates whether the mutation groups that | ||
| /// it references were applied successfully. | ||
| /// The method does not handle any errors, including retryable errors like Aborted. |
There was a problem hiding this comment.
super nit: add a newline before this paragraph?
| /// The method does not handle any errors, including retryable errors like Aborted. | |
| /// | |
| /// The method does not handle any errors, including retryable errors like Aborted. |
| // limitations under the License. | ||
|
|
||
| use crate::key::KeySet; | ||
| use crate::model::batch_write_request::MutationGroup as ProtoMutationGroup; |
There was a problem hiding this comment.
why do we write our own type instead of exposing the generated type?
There was a problem hiding this comment.
Using the generated MutationGroup struct would also mean that customers would need to use the generated Mutation struct (or manually convert hand-written Mutation instances to the generated version before setting them on MutationGroup). And we certainly want to use a hand-written Mutation struct, as it allows us to encapsulate the way that Spanner expects the various data types to be encoded on the wire. A hand-written Mutation can be constructed like this:
let mutation = Mutation::new_insert_builder("Users")
.set("UserId").to(&1)
.set("UserName").to(&"Alice")
.build();Our ToValue trait then takes care or encoding these values the way that Spanner expects them.
| /// A group of mutations that are applied atomically in a [crate::BatchWriteTransaction]. | ||
| #[derive(Clone, Debug, PartialEq)] | ||
| pub struct MutationGroup { | ||
| pub mutations: Vec<Mutation>, | ||
| } |
There was a problem hiding this comment.
FYI: #5566
It is a breaking change to add any fields to this in the future. Are you sure it will not grow?
(if we are keeping the type)
There was a problem hiding this comment.
Added #[non_exhaustive]
Adds support for BatchWrite transactions. BatchWrite can be used to write
large numbers of mutations to Spanner. A BatchWrite transaction is not
guaranteed to be atomic. However, each MutationGroup in a BatchWrite
transaction is guaranteed to be atomic.
This change adds a method that returns a stream of responses and delegates
all error handling to the application. A follow-up pull request will add a
managed execution method that handles errors automatically.
Depends on #5499