Skip to content

Commit 7bc58cf

Browse files
yoshi-automationcallmehiphop
authored andcommitted
feat: support batch create sessions (#685)
1 parent f300fad commit 7bc58cf

File tree

9 files changed

+222
-52
lines changed

9 files changed

+222
-52
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,10 @@ Apache Version 2.0
133133

134134
See [LICENSE](https://github.com/googleapis/nodejs-spanner/blob/master/LICENSE)
135135

136-
[client-docs]: https://googleapis.dev/nodejs/spanner/latest#reference
136+
[client-docs]: https://googleapis.dev/nodejs/spanner/latest
137137
[product-docs]: https://cloud.google.com/spanner/docs/
138138
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
139139
[projects]: https://console.cloud.google.com/project
140140
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
141141
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=spanner.googleapis.com
142142
[auth]: https://cloud.google.com/docs/authentication/getting-started
143-
144-
<a name="reference"></a>

protos/google/spanner/v1/spanner.proto

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC.
1+
// Copyright 2019 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.
@@ -66,6 +66,18 @@ service Spanner {
6666
};
6767
}
6868

69+
// Creates multiple new sessions.
70+
//
71+
// This API can be used to initialize a session cache on the clients.
72+
// See https://goo.gl/TgSFN2 for best practices on session cache management.
73+
rpc BatchCreateSessions(BatchCreateSessionsRequest)
74+
returns (BatchCreateSessionsResponse) {
75+
option (google.api.http) = {
76+
post: "/v1/{database=projects/*/instances/*/databases/*}/sessions:batchCreate"
77+
body: "*"
78+
};
79+
}
80+
6981
// Gets a session. Returns `NOT_FOUND` if the session does not exist.
7082
// This is mainly useful for determining whether a session is still
7183
// alive.
@@ -129,8 +141,9 @@ service Spanner {
129141
//
130142
// Statements are executed in order, sequentially.
131143
// [ExecuteBatchDmlResponse][Spanner.ExecuteBatchDmlResponse] will contain a
132-
// [ResultSet][google.spanner.v1.ResultSet] for each DML statement that has successfully executed. If a
133-
// statement fails, its error status will be returned as part of the
144+
// [ResultSet][google.spanner.v1.ResultSet] for each DML statement that has
145+
// successfully executed. If a statement fails, its error status will be
146+
// returned as part of the
134147
// [ExecuteBatchDmlResponse][Spanner.ExecuteBatchDmlResponse]. Execution will
135148
// stop at the first failed statement; the remaining statements will not run.
136149
//
@@ -142,7 +155,8 @@ service Spanner {
142155
// See more details in
143156
// [ExecuteBatchDmlRequest][Spanner.ExecuteBatchDmlRequest] and
144157
// [ExecuteBatchDmlResponse][Spanner.ExecuteBatchDmlResponse].
145-
rpc ExecuteBatchDml(ExecuteBatchDmlRequest) returns (ExecuteBatchDmlResponse) {
158+
rpc ExecuteBatchDml(ExecuteBatchDmlRequest)
159+
returns (ExecuteBatchDmlResponse) {
146160
option (google.api.http) = {
147161
post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:executeBatchDml"
148162
body: "*"
@@ -275,6 +289,31 @@ message CreateSessionRequest {
275289
Session session = 2;
276290
}
277291

292+
// The request for
293+
// [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions].
294+
message BatchCreateSessionsRequest {
295+
// Required. The database in which the new sessions are created.
296+
string database = 1;
297+
298+
// Parameters to be applied to each created session.
299+
Session session_template = 2;
300+
301+
// Required. The number of sessions to be created in this batch call.
302+
// The API may return fewer than the requested number of sessions. If a
303+
// specific number of sessions are desired, the client can make additional
304+
// calls to BatchCreateSessions (adjusting
305+
// [session_count][google.spanner.v1.BatchCreateSessionsRequest.session_count]
306+
// as necessary).
307+
int32 session_count = 3;
308+
}
309+
310+
// The response for
311+
// [BatchCreateSessions][google.spanner.v1.Spanner.BatchCreateSessions].
312+
message BatchCreateSessionsResponse {
313+
// The freshly created sessions.
314+
repeated Session session = 1;
315+
}
316+
278317
// A session in the Cloud Spanner API.
279318
message Session {
280319
// The name of the session. This is always system-assigned; values provided
@@ -371,9 +410,6 @@ message ExecuteSqlRequest {
371410
// Required. The session in which the SQL query should be performed.
372411
string session = 1;
373412

374-
// The transaction to use. If none is provided, the default is a
375-
// temporary read-only transaction with strong concurrency.
376-
//
377413
// The transaction to use.
378414
//
379415
// For queries, if none is provided, the default is a temporary read-only
@@ -476,7 +512,9 @@ message ExecuteBatchDmlRequest {
476512

477513
// It is not always possible for Cloud Spanner to infer the right SQL type
478514
// from a JSON value. For example, values of type `BYTES` and values
479-
// of type `STRING` both appear in [params][google.spanner.v1.ExecuteBatchDmlRequest.Statement.params] as JSON strings.
515+
// of type `STRING` both appear in
516+
// [params][google.spanner.v1.ExecuteBatchDmlRequest.Statement.params] as
517+
// JSON strings.
480518
//
481519
// In these cases, `param_types` can be used to specify the exact
482520
// SQL type for some or all of the SQL statement parameters. See the
@@ -508,11 +546,13 @@ message ExecuteBatchDmlRequest {
508546
int64 seqno = 4;
509547
}
510548

511-
// The response for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. Contains a list
512-
// of [ResultSet][google.spanner.v1.ResultSet], one for each DML statement that has successfully executed.
513-
// If a statement fails, the error is returned as part of the response payload.
514-
// Clients can determine whether all DML statements have run successfully, or if
515-
// a statement failed, using one of the following approaches:
549+
// The response for
550+
// [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. Contains a list
551+
// of [ResultSet][google.spanner.v1.ResultSet], one for each DML statement that
552+
// has successfully executed. If a statement fails, the error is returned as
553+
// part of the response payload. Clients can determine whether all DML
554+
// statements have run successfully, or if a statement failed, using one of the
555+
// following approaches:
516556
//
517557
// 1. Check if 'status' field is OkStatus.
518558
// 2. Check if result_sets_size() equals the number of statements in
@@ -529,9 +569,11 @@ message ExecuteBatchDmlRequest {
529569
// result_set_size() client can determine that the 3rd statement has failed.
530570
message ExecuteBatchDmlResponse {
531571
// ResultSets, one for each statement in the request that ran successfully, in
532-
// the same order as the statements in the request. Each [ResultSet][google.spanner.v1.ResultSet] will
533-
// not contain any rows. The [ResultSetStats][google.spanner.v1.ResultSetStats] in each [ResultSet][google.spanner.v1.ResultSet] will
534-
// contain the number of rows modified by the statement.
572+
// the same order as the statements in the request. Each
573+
// [ResultSet][google.spanner.v1.ResultSet] will not contain any rows. The
574+
// [ResultSetStats][google.spanner.v1.ResultSetStats] in each
575+
// [ResultSet][google.spanner.v1.ResultSet] will contain the number of rows
576+
// modified by the statement.
535577
//
536578
// Only the first ResultSet in the response contains a valid
537579
// [ResultSetMetadata][google.spanner.v1.ResultSetMetadata].

src/v1/doc/google/iam/v1/doc_options.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
*
2121
* @property {number} requestedPolicyVersion
2222
* Optional. The policy format version to be returned.
23-
* Acceptable values are 0 and 1.
24-
* If the value is 0, or the field is omitted, policy format version 1 will be
25-
* returned.
23+
*
24+
* Valid values are 0, 1, and 3. Requests specifying an invalid value will be
25+
* rejected.
26+
*
27+
* Requests for policies with any conditional bindings must specify version 3.
28+
* Policies without any conditional bindings may specify any valid value or
29+
* leave the field unset.
2630
*
2731
* @typedef GetPolicyOptions
2832
* @memberof google.iam.v1

src/v1/doc/google/iam/v1/doc_policy.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@
6363
* [IAM developer's guide](https://cloud.google.com/iam/docs).
6464
*
6565
* @property {number} version
66-
* Deprecated.
66+
* Specifies the format of the policy.
67+
*
68+
* Valid values are 0, 1, and 3. Requests specifying an invalid value will be
69+
* rejected.
70+
*
71+
* Policies with any conditional bindings must specify version 3. Policies
72+
* without any conditional bindings may specify any valid value or leave the
73+
* field unset.
6774
*
6875
* @property {Object[]} bindings
6976
* Associates a list of `members` to a `role`.

src/v1/doc/google/protobuf/doc_timestamp.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@
8989
* 01:30 UTC on January 15, 2017.
9090
*
9191
* In JavaScript, one can convert a Date object to this format using the
92-
* standard [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
92+
* standard
93+
* [toISOString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString)
9394
* method. In Python, a standard `datetime.datetime` object can be converted
94-
* to this format using [`strftime`](https://docs.python.org/2/library/time.html#time.strftime)
95-
* with the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one
96-
* can use the Joda Time's [`ISODateTimeFormat.dateTime()`](https://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D) to obtain a formatter capable of generating timestamps in this format.
95+
* to this format using
96+
* [`strftime`](https://docs.python.org/2/library/time.html#time.strftime) with
97+
* the time format spec '%Y-%m-%dT%H:%M:%S.%fZ'. Likewise, in Java, one can use
98+
* the Joda Time's [`ISODateTimeFormat.dateTime()`](https://www.joda.org/joda-time/apidocs/org/joda/time/format/ISODateTimeFormat.html#dateTime%2D%2D) to obtain a formatter capable of generating timestamps in this format.
9799
*
98100
* @property {number} seconds
99101
* Represents seconds of UTC time since Unix epoch

src/v1/doc/google/spanner/v1/doc_spanner.js

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,51 @@ const CreateSessionRequest = {
3434
// This is for documentation. Actual contents will be loaded by gRPC.
3535
};
3636

37+
/**
38+
* The request for
39+
* BatchCreateSessions.
40+
*
41+
* @property {string} database
42+
* Required. The database in which the new sessions are created.
43+
*
44+
* @property {Object} sessionTemplate
45+
* Parameters to be applied to each created session.
46+
*
47+
* This object should have the same structure as [Session]{@link google.spanner.v1.Session}
48+
*
49+
* @property {number} sessionCount
50+
* Required. The number of sessions to be created in this batch call.
51+
* The API may return fewer than the requested number of sessions. If a
52+
* specific number of sessions are desired, the client can make additional
53+
* calls to BatchCreateSessions (adjusting
54+
* session_count
55+
* as necessary).
56+
*
57+
* @typedef BatchCreateSessionsRequest
58+
* @memberof google.spanner.v1
59+
* @see [google.spanner.v1.BatchCreateSessionsRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/spanner/v1/spanner.proto}
60+
*/
61+
const BatchCreateSessionsRequest = {
62+
// This is for documentation. Actual contents will be loaded by gRPC.
63+
};
64+
65+
/**
66+
* The response for
67+
* BatchCreateSessions.
68+
*
69+
* @property {Object[]} session
70+
* The freshly created sessions.
71+
*
72+
* This object should have the same structure as [Session]{@link google.spanner.v1.Session}
73+
*
74+
* @typedef BatchCreateSessionsResponse
75+
* @memberof google.spanner.v1
76+
* @see [google.spanner.v1.BatchCreateSessionsResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/spanner/v1/spanner.proto}
77+
*/
78+
const BatchCreateSessionsResponse = {
79+
// This is for documentation. Actual contents will be loaded by gRPC.
80+
};
81+
3782
/**
3883
* A session in the Cloud Spanner API.
3984
*
@@ -164,9 +209,6 @@ const DeleteSessionRequest = {
164209
* Required. The session in which the SQL query should be performed.
165210
*
166211
* @property {Object} transaction
167-
* The transaction to use. If none is provided, the default is a
168-
* temporary read-only transaction with strong concurrency.
169-
*
170212
* The transaction to use.
171213
*
172214
* For queries, if none is provided, the default is a temporary read-only
@@ -345,7 +387,9 @@ const ExecuteBatchDmlRequest = {
345387
* @property {Object.<string, Object>} paramTypes
346388
* It is not always possible for Cloud Spanner to infer the right SQL type
347389
* from a JSON value. For example, values of type `BYTES` and values
348-
* of type `STRING` both appear in params as JSON strings.
390+
* of type `STRING` both appear in
391+
* params as
392+
* JSON strings.
349393
*
350394
* In these cases, `param_types` can be used to specify the exact
351395
* SQL type for some or all of the SQL statement parameters. See the
@@ -362,11 +406,13 @@ const ExecuteBatchDmlRequest = {
362406
};
363407

364408
/**
365-
* The response for ExecuteBatchDml. Contains a list
366-
* of ResultSet, one for each DML statement that has successfully executed.
367-
* If a statement fails, the error is returned as part of the response payload.
368-
* Clients can determine whether all DML statements have run successfully, or if
369-
* a statement failed, using one of the following approaches:
409+
* The response for
410+
* ExecuteBatchDml. Contains a list
411+
* of ResultSet, one for each DML statement that
412+
* has successfully executed. If a statement fails, the error is returned as
413+
* part of the response payload. Clients can determine whether all DML
414+
* statements have run successfully, or if a statement failed, using one of the
415+
* following approaches:
370416
*
371417
* 1. Check if 'status' field is OkStatus.
372418
* 2. Check if result_sets_size() equals the number of statements in
@@ -384,9 +430,11 @@ const ExecuteBatchDmlRequest = {
384430
*
385431
* @property {Object[]} resultSets
386432
* ResultSets, one for each statement in the request that ran successfully, in
387-
* the same order as the statements in the request. Each ResultSet will
388-
* not contain any rows. The ResultSetStats in each ResultSet will
389-
* contain the number of rows modified by the statement.
433+
* the same order as the statements in the request. Each
434+
* ResultSet will not contain any rows. The
435+
* ResultSetStats in each
436+
* ResultSet will contain the number of rows
437+
* modified by the statement.
390438
*
391439
* Only the first ResultSet in the response contains a valid
392440
* ResultSetMetadata.

0 commit comments

Comments
 (0)