Skip to content

Commit 64fd42c

Browse files
Google APIscopybara-github
authored andcommitted
feat: add BatchWrite API
PiperOrigin-RevId: 567412157
1 parent 5a6b67a commit 64fd42c

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

google/spanner/v1/spanner.proto

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

google/spanner/v1/spanner_grpc_service_config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
{
1010
"service": "google.spanner.v1.Spanner",
1111
"method": "StreamingRead"
12+
},
13+
{
14+
"service": "google.spanner.v1.Spanner",
15+
"method": "BatchWrite"
1216
}
1317
],
1418
"timeout": "3600s"

0 commit comments

Comments
 (0)