@@ -288,6 +288,29 @@ service Spanner {
288288 body : "*"
289289 };
290290 }
291+
292+ // Batches the supplied mutation groups in a collection of efficient
293+ // transactions. All mutations in a group are committed atomically. However,
294+ // mutations across groups can be committed non-atomically in an unspecified
295+ // order and thus, they must be independent of each other. Partial failure is
296+ // possible, i.e., some groups may have been committed successfully, while
297+ // some may have failed. The results of individual batches are streamed into
298+ // the response as the batches are applied.
299+ //
300+ // BatchWrite requests are not replay protected, meaning that each mutation
301+ // group may be applied more than once. Replays of non-idempotent mutations
302+ // may have undesirable effects. For example, replays of an insert mutation
303+ // may produce an already exists error or if you use generated or commit
304+ // timestamp-based keys, it may result in additional rows being added to the
305+ // mutation's table. We recommend structuring your mutation groups to be
306+ // idempotent to avoid this issue.
307+ rpc BatchWrite (BatchWriteRequest ) returns (stream BatchWriteResponse ) {
308+ option (google.api.http ) = {
309+ post : "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:batchWrite"
310+ body : "*"
311+ };
312+ option (google.api.method_signature ) = "session,mutation_groups" ;
313+ }
291314}
292315
293316// The request for [CreateSession][google.spanner.v1.Spanner.CreateSession].
@@ -1040,3 +1063,41 @@ message RollbackRequest {
10401063 // Required. The transaction to roll back.
10411064 bytes transaction_id = 2 [(google.api.field_behavior ) = REQUIRED ];
10421065}
1066+
1067+ // The request for [BatchWrite][google.spanner.v1.Spanner.BatchWrite].
1068+ message BatchWriteRequest {
1069+ // A group of mutations to be committed together. Related mutations should be
1070+ // placed in a group. For example, two mutations inserting rows with the same
1071+ // primary key prefix in both parent and child tables are related.
1072+ message MutationGroup {
1073+ // Required. The mutations in this group.
1074+ repeated Mutation mutations = 1 [(google.api.field_behavior ) = REQUIRED ];
1075+ }
1076+
1077+ // Required. The session in which the batch request is to be run.
1078+ string session = 1 [
1079+ (google.api.field_behavior ) = REQUIRED ,
1080+ (google.api.resource_reference ) = { type : "spanner.googleapis.com/Session" }
1081+ ];
1082+
1083+ // Common options for this request.
1084+ RequestOptions request_options = 3 ;
1085+
1086+ // Required. The groups of mutations to be applied.
1087+ repeated MutationGroup mutation_groups = 4
1088+ [(google.api.field_behavior ) = REQUIRED ];
1089+ }
1090+
1091+ // The result of applying a batch of mutations.
1092+ message BatchWriteResponse {
1093+ // The mutation groups applied in this batch. The values index into the
1094+ // `mutation_groups` field in the corresponding `BatchWriteRequest`.
1095+ repeated int32 indexes = 1 ;
1096+
1097+ // An `OK` status indicates success. Any other status indicates a failure.
1098+ google.rpc.Status status = 2 ;
1099+
1100+ // The commit timestamp of the transaction that applied this batch.
1101+ // Present if `status` is `OK`, absent otherwise.
1102+ google.protobuf.Timestamp commit_timestamp = 3 ;
1103+ }
0 commit comments