Skip to content

Commit d1cb679

Browse files
dpebotJustinBeckwith
authored andcommitted
Update protos and comments (#334)
1 parent 08453a5 commit d1cb679

13 files changed

Lines changed: 367 additions & 69 deletions

File tree

handwritten/spanner/protos/google/spanner/admin/database/v1/spanner_database_admin.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

handwritten/spanner/protos/google/spanner/admin/instance/v1/spanner_instance_admin.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

handwritten/spanner/protos/google/spanner/v1/keys.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

handwritten/spanner/protos/google/spanner/v1/mutation.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

handwritten/spanner/protos/google/spanner/v1/query_plan.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

handwritten/spanner/protos/google/spanner/v1/result_set.proto

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -45,8 +45,13 @@ message ResultSet {
4545
// [here][google.spanner.v1.TypeCode].
4646
repeated google.protobuf.ListValue rows = 2;
4747

48-
// Query plan and execution statistics for the query that produced this
49-
// result set. These can be requested by setting
48+
// Query plan and execution statistics for the SQL statement that
49+
// produced this result set. These can be requested by setting
50+
// [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode].
51+
// DML statements always produce stats containing the number of rows
52+
// modified, unless executed using the
53+
// [ExecuteSqlRequest.QueryMode.PLAN][google.spanner.v1.ExecuteSqlRequest.QueryMode.PLAN] [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode].
54+
// Other fields may or may not be populated, based on the
5055
// [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode].
5156
ResultSetStats stats = 3;
5257
}
@@ -146,10 +151,12 @@ message PartialResultSet {
146151
// same session invalidates the token.
147152
bytes resume_token = 4;
148153

149-
// Query plan and execution statistics for the query that produced this
154+
// Query plan and execution statistics for the statement that produced this
150155
// streaming result set. These can be requested by setting
151156
// [ExecuteSqlRequest.query_mode][google.spanner.v1.ExecuteSqlRequest.query_mode] and are sent
152157
// only once with the last response in the stream.
158+
// This field will also be present in the last response for DML
159+
// statements.
153160
ResultSetStats stats = 5;
154161
}
155162

@@ -185,4 +192,14 @@ message ResultSetStats {
185192
// "cpu_time": "1.19 secs"
186193
// }
187194
google.protobuf.Struct query_stats = 2;
195+
196+
// The number of rows modified by the DML statement.
197+
oneof row_count {
198+
// Standard DML returns an exact count of rows that were modified.
199+
int64 row_count_exact = 3;
200+
201+
// Partitioned DML does not offer exactly-once semantics, so it
202+
// returns a lower bound of the rows modified.
203+
int64 row_count_lower_bound = 4;
204+
}
188205
}

handwritten/spanner/protos/google/spanner/v1/spanner.proto

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -88,12 +88,12 @@ service Spanner {
8888
};
8989
}
9090

91-
// Executes an SQL query, returning all rows in a single reply. This
91+
// Executes an SQL statement, returning all results in a single reply. This
9292
// method cannot be used to return a result set larger than 10 MiB;
9393
// if the query yields more data than that, the query fails with
9494
// a `FAILED_PRECONDITION` error.
9595
//
96-
// Queries inside read-write transactions might return `ABORTED`. If
96+
// Operations inside read-write transactions might return `ABORTED`. If
9797
// this occurs, the application should restart the transaction from
9898
// the beginning. See [Transaction][google.spanner.v1.Transaction] for more details.
9999
//
@@ -197,8 +197,11 @@ service Spanner {
197197
// of the query result to read. The same session and read-only transaction
198198
// must be used by the PartitionQueryRequest used to create the
199199
// partition tokens and the ExecuteSqlRequests that use the partition tokens.
200+
//
200201
// Partition tokens become invalid when the session used to create them
201-
// is deleted or begins a new transaction.
202+
// is deleted, is idle for too long, begins a new transaction, or becomes too
203+
// old. When any of these happen, it is not possible to resume the query, and
204+
// the whole operation must be restarted from the beginning.
202205
rpc PartitionQuery(PartitionQueryRequest) returns (PartitionResponse) {
203206
option (google.api.http) = {
204207
post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionQuery"
@@ -211,9 +214,14 @@ service Spanner {
211214
// by [StreamingRead][google.spanner.v1.Spanner.StreamingRead] to specify a subset of the read
212215
// result to read. The same session and read-only transaction must be used by
213216
// the PartitionReadRequest used to create the partition tokens and the
214-
// ReadRequests that use the partition tokens.
217+
// ReadRequests that use the partition tokens. There are no ordering
218+
// guarantees on rows returned among the returned partition tokens, or even
219+
// within each individual StreamingRead call issued with a partition_token.
220+
//
215221
// Partition tokens become invalid when the session used to create them
216-
// is deleted or begins a new transaction.
222+
// is deleted, is idle for too long, begins a new transaction, or becomes too
223+
// old. When any of these happen, it is not possible to resume the read, and
224+
// the whole operation must be restarted from the beginning.
217225
rpc PartitionRead(PartitionReadRequest) returns (PartitionResponse) {
218226
option (google.api.http) = {
219227
post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionRead"
@@ -309,18 +317,17 @@ message DeleteSessionRequest {
309317
// The request for [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and
310318
// [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql].
311319
message ExecuteSqlRequest {
312-
// Mode in which the query must be processed.
320+
// Mode in which the statement must be processed.
313321
enum QueryMode {
314-
// The default mode where only the query result, without any information
315-
// about the query plan is returned.
322+
// The default mode. Only the statement results are returned.
316323
NORMAL = 0;
317324

318-
// This mode returns only the query plan, without any result rows or
325+
// This mode returns only the query plan, without any results or
319326
// execution statistics information.
320327
PLAN = 1;
321328

322329
// This mode returns both the query plan and the execution statistics along
323-
// with the result rows.
330+
// with the results.
324331
PROFILE = 2;
325332
}
326333

@@ -329,12 +336,23 @@ message ExecuteSqlRequest {
329336

330337
// The transaction to use. If none is provided, the default is a
331338
// temporary read-only transaction with strong concurrency.
339+
//
340+
// The transaction to use.
341+
//
342+
// For queries, if none is provided, the default is a temporary read-only
343+
// transaction with strong concurrency.
344+
//
345+
// Standard DML statements require a ReadWrite transaction. Single-use
346+
// transactions are not supported (to avoid replay). The caller must
347+
// either supply an existing transaction ID or begin a new transaction.
348+
//
349+
// Partitioned DML requires an existing PartitionedDml transaction ID.
332350
TransactionSelector transaction = 2;
333351

334-
// Required. The SQL query string.
352+
// Required. The SQL string.
335353
string sql = 3;
336354

337-
// The SQL query string can contain parameter placeholders. A parameter
355+
// The SQL string can contain parameter placeholders. A parameter
338356
// placeholder consists of `'@'` followed by the parameter
339357
// name. Parameter names consist of any combination of letters,
340358
// numbers, and underscores.
@@ -343,7 +361,7 @@ message ExecuteSqlRequest {
343361
// parameter name can be used more than once, for example:
344362
// `"WHERE id > @msg_id AND id < @msg_id + 100"`
345363
//
346-
// It is an error to execute an SQL query with unbound parameters.
364+
// It is an error to execute an SQL statement with unbound parameters.
347365
//
348366
// Parameter values are specified using `params`, which is a JSON
349367
// object whose keys are parameter names, and whose values are the
@@ -355,15 +373,15 @@ message ExecuteSqlRequest {
355373
// of type `STRING` both appear in [params][google.spanner.v1.ExecuteSqlRequest.params] as JSON strings.
356374
//
357375
// In these cases, `param_types` can be used to specify the exact
358-
// SQL type for some or all of the SQL query parameters. See the
376+
// SQL type for some or all of the SQL statement parameters. See the
359377
// definition of [Type][google.spanner.v1.Type] for more information
360378
// about SQL types.
361379
map<string, Type> param_types = 5;
362380

363-
// If this request is resuming a previously interrupted SQL query
381+
// If this request is resuming a previously interrupted SQL statement
364382
// execution, `resume_token` should be copied from the last
365383
// [PartialResultSet][google.spanner.v1.PartialResultSet] yielded before the interruption. Doing this
366-
// enables the new SQL query execution to resume where the last one left
384+
// enables the new SQL statement execution to resume where the last one left
367385
// off. The rest of the request parameters must exactly match the
368386
// request that yielded this token.
369387
bytes resume_token = 6;
@@ -378,6 +396,18 @@ message ExecuteSqlRequest {
378396
// match for the values of fields common to this message and the
379397
// PartitionQueryRequest message used to create this partition_token.
380398
bytes partition_token = 8;
399+
400+
// A per-transaction sequence number used to identify this request. This
401+
// makes each request idempotent such that if the request is received multiple
402+
// times, at most one will succeed.
403+
//
404+
// The sequence number must be monotonically increasing within the
405+
// transaction. If a request arrives for the first time with an out-of-order
406+
// sequence number, the transaction may be aborted. Replays of previously
407+
// handled requests will yield the same response as the first execution.
408+
//
409+
// Required for DML statements. Ignored for queries.
410+
int64 seqno = 9;
381411
}
382412

383413
// Options for a PartitionQueryRequest and
@@ -417,6 +447,10 @@ message PartitionQueryRequest {
417447
// union operator conceptually divides one or more tables into multiple
418448
// splits, remotely evaluates a subquery independently on each split, and
419449
// then unions all results.
450+
//
451+
// This must not contain DML commands, such as INSERT, UPDATE, or
452+
// DELETE. Use [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql] with a
453+
// PartitionedDml transaction for large, partition-friendly DML operations.
420454
string sql = 3;
421455

422456
// The SQL query string can contain parameter placeholders. A parameter

handwritten/spanner/protos/google/spanner/v1/transaction.proto

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ option php_namespace = "Google\\Cloud\\Spanner\\V1";
3838
//
3939
// # Transaction Modes
4040
//
41-
// Cloud Spanner supports two transaction modes:
41+
// Cloud Spanner supports three transaction modes:
4242
//
4343
// 1. Locking read-write. This type of transaction is the only way
4444
// to write data into Cloud Spanner. These transactions rely on
@@ -52,6 +52,13 @@ option php_namespace = "Google\\Cloud\\Spanner\\V1";
5252
// read at timestamps in the past. Snapshot read-only
5353
// transactions do not need to be committed.
5454
//
55+
// 3. Partitioned DML. This type of transaction is used to execute
56+
// a single Partitioned DML statement. Partitioned DML partitions
57+
// the key space and runs the DML statement over each partition
58+
// in parallel using separate, internal transactions that commit
59+
// independently. Partitioned DML transactions do not need to be
60+
// committed.
61+
//
5562
// For transactions that only read, snapshot read-only transactions
5663
// provide simpler semantics and are almost always faster. In
5764
// particular, read-only transactions do not take locks, so they do
@@ -78,11 +85,8 @@ option php_namespace = "Google\\Cloud\\Spanner\\V1";
7885
// inactivity at the client may cause Cloud Spanner to release a
7986
// transaction's locks and abort it.
8087
//
81-
// Reads performed within a transaction acquire locks on the data
82-
// being read. Writes can only be done at commit time, after all reads
83-
// have been completed.
8488
// Conceptually, a read-write transaction consists of zero or more
85-
// reads or SQL queries followed by
89+
// reads or SQL statements followed by
8690
// [Commit][google.spanner.v1.Spanner.Commit]. At any time before
8791
// [Commit][google.spanner.v1.Spanner.Commit], the client can send a
8892
// [Rollback][google.spanner.v1.Spanner.Rollback] request to abort the
@@ -245,13 +249,74 @@ option php_namespace = "Google\\Cloud\\Spanner\\V1";
245249
// restriction also applies to in-progress reads and/or SQL queries whose
246250
// timestamp become too old while executing. Reads and SQL queries with
247251
// too-old read timestamps fail with the error `FAILED_PRECONDITION`.
252+
//
253+
// ## Partitioned DML Transactions
254+
//
255+
// Partitioned DML transactions are used to execute DML statements with a
256+
// different execution strategy that provides different, and often better,
257+
// scalability properties for large, table-wide operations than DML in a
258+
// ReadWrite transaction. Smaller scoped statements, such as an OLTP workload,
259+
// should prefer using ReadWrite transactions.
260+
//
261+
// Partitioned DML partitions the keyspace and runs the DML statement on each
262+
// partition in separate, internal transactions. These transactions commit
263+
// automatically when complete, and run independently from one another.
264+
//
265+
// To reduce lock contention, this execution strategy only acquires read locks
266+
// on rows that match the WHERE clause of the statement. Additionally, the
267+
// smaller per-partition transactions hold locks for less time.
268+
//
269+
// That said, Partitioned DML is not a drop-in replacement for standard DML used
270+
// in ReadWrite transactions.
271+
//
272+
// - The DML statement must be fully-partitionable. Specifically, the statement
273+
// must be expressible as the union of many statements which each access only
274+
// a single row of the table.
275+
//
276+
// - The statement is not applied atomically to all rows of the table. Rather,
277+
// the statement is applied atomically to partitions of the table, in
278+
// independent transactions. Secondary index rows are updated atomically
279+
// with the base table rows.
280+
//
281+
// - Partitioned DML does not guarantee exactly-once execution semantics
282+
// against a partition. The statement will be applied at least once to each
283+
// partition. It is strongly recommended that the DML statement should be
284+
// idempotent to avoid unexpected results. For instance, it is potentially
285+
// dangerous to run a statement such as
286+
// `UPDATE table SET column = column + 1` as it could be run multiple times
287+
// against some rows.
288+
//
289+
// - The partitions are committed automatically - there is no support for
290+
// Commit or Rollback. If the call returns an error, or if the client issuing
291+
// the ExecuteSql call dies, it is possible that some rows had the statement
292+
// executed on them successfully. It is also possible that statement was
293+
// never executed against other rows.
294+
//
295+
// - Partitioned DML transactions may only contain the execution of a single
296+
// DML statement via ExecuteSql or ExecuteStreamingSql.
297+
//
298+
// - If any error is encountered during the execution of the partitioned DML
299+
// operation (for instance, a UNIQUE INDEX violation, division by zero, or a
300+
// value that cannot be stored due to schema constraints), then the
301+
// operation is stopped at that point and an error is returned. It is
302+
// possible that at this point, some partitions have been committed (or even
303+
// committed multiple times), and other partitions have not been run at all.
304+
//
305+
// Given the above, Partitioned DML is good fit for large, database-wide,
306+
// operations that are idempotent, such as deleting old rows from a very large
307+
// table.
248308
message TransactionOptions {
249309
// Message type to initiate a read-write transaction. Currently this
250310
// transaction type has no options.
251311
message ReadWrite {
252312

253313
}
254314

315+
// Message type to initiate a Partitioned DML transaction.
316+
message PartitionedDml {
317+
318+
}
319+
255320
// Message type to initiate a read-only transaction.
256321
message ReadOnly {
257322
// How to choose the timestamp for the read-only transaction.
@@ -329,6 +394,13 @@ message TransactionOptions {
329394
// on the `session` resource.
330395
ReadWrite read_write = 1;
331396

397+
// Partitioned DML transaction.
398+
//
399+
// Authorization to begin a Partitioned DML transaction requires
400+
// `spanner.databases.beginPartitionedDmlTransaction` permission
401+
// on the `session` resource.
402+
PartitionedDml partitioned_dml = 3;
403+
332404
// Transaction will not write.
333405
//
334406
// Authorization to begin a read-only transaction requires

handwritten/spanner/protos/google/spanner/v1/type.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google Inc.
1+
// Copyright 2018 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)