Skip to content

Commit 8fa381b

Browse files
Google APIscopybara-github
authored andcommitted
feat: add option for returning Spanner commit stats
PiperOrigin-RevId: 353145174
1 parent 9504e6c commit 8fa381b

3 files changed

Lines changed: 45 additions & 12 deletions

File tree

google/spanner/v1/spanner.proto

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import "google/api/annotations.proto";
2020
import "google/api/client.proto";
2121
import "google/api/field_behavior.proto";
2222
import "google/api/resource.proto";
23+
import "google/protobuf/duration.proto";
2324
import "google/protobuf/empty.proto";
2425
import "google/protobuf/struct.proto";
2526
import "google/protobuf/timestamp.proto";
@@ -219,6 +220,12 @@ service Spanner {
219220
// transactions. However, it can also happen for a variety of other
220221
// reasons. If `Commit` returns `ABORTED`, the caller should re-attempt
221222
// the transaction from the beginning, re-using the same session.
223+
//
224+
// On very rare occasions, `Commit` might return `UNKNOWN`. This can happen,
225+
// for example, if the client job experiences a 1+ hour networking failure.
226+
// At that point, Cloud Spanner has lost track of the transaction outcome and
227+
// we recommend that you perform another read from the database to see the
228+
// state of things as they are now.
222229
rpc Commit(CommitRequest) returns (CommitResponse) {
223230
option (google.api.http) = {
224231
post: "/v1/{session=projects/*/instances/*/databases/*/sessions/*}:commit"
@@ -331,9 +338,8 @@ message Session {
331338
pattern: "projects/{project}/instances/{instance}/databases/{database}/sessions/{session}"
332339
};
333340

334-
// The name of the session. This is always system-assigned; values provided
335-
// when creating a session are ignored.
336-
string name = 1;
341+
// Output only. The name of the session. This is always system-assigned.
342+
string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
337343

338344
// The labels for the session.
339345
//
@@ -347,11 +353,11 @@ message Session {
347353
map<string, string> labels = 2;
348354

349355
// Output only. The timestamp when the session is created.
350-
google.protobuf.Timestamp create_time = 3;
356+
google.protobuf.Timestamp create_time = 3 [(google.api.field_behavior) = OUTPUT_ONLY];
351357

352358
// Output only. The approximate timestamp when the session is last used. It is
353359
// typically earlier than the actual last use time.
354-
google.protobuf.Timestamp approximate_last_use_time = 4;
360+
google.protobuf.Timestamp approximate_last_use_time = 4 [(google.api.field_behavior) = OUTPUT_ONLY];
355361
}
356362

357363
// The request for [GetSession][google.spanner.v1.Spanner.GetSession].
@@ -438,6 +444,9 @@ message ExecuteSqlRequest {
438444
// SPANNER_SYS.SUPPORTED_OPTIMIZER_VERSIONS. Executing a SQL statement
439445
// with an invalid optimizer version will fail with a syntax error
440446
// (`INVALID_ARGUMENT`) status.
447+
// See
448+
// https://cloud.google.com/spanner/docs/query-optimizer/manage-query-optimizer
449+
// for more information on managing the query optimizer.
441450
//
442451
// The `optimizer_version` statement hint has precedence over this setting.
443452
string optimizer_version = 1;
@@ -483,8 +492,9 @@ message ExecuteSqlRequest {
483492
// Parameter names and values that bind to placeholders in the SQL string.
484493
//
485494
// A parameter placeholder consists of the `@` character followed by the
486-
// parameter name (for example, `@firstName`). Parameter names can contain
487-
// letters, numbers, and underscores.
495+
// parameter name (for example, `@firstName`). Parameter names must conform
496+
// to the naming requirements of identifiers as specified at
497+
// https://cloud.google.com/spanner/docs/lexical#identifiers.
488498
//
489499
// Parameters can appear anywhere that a literal value is expected. The same
490500
// parameter name can be used more than once, for example:
@@ -884,12 +894,34 @@ message CommitRequest {
884894
// mutations are applied atomically, in the order they appear in
885895
// this list.
886896
repeated Mutation mutations = 4;
897+
898+
// If `true`, then statistics related to the transaction will be included in
899+
// the [CommitResponse][google.spanner.v1.CommitResponse.commit_stats]. Default value is
900+
// `false`.
901+
bool return_commit_stats = 5;
887902
}
888903

889904
// The response for [Commit][google.spanner.v1.Spanner.Commit].
890905
message CommitResponse {
906+
// Additional statistics about a commit.
907+
message CommitStats {
908+
// The total number of mutations for the transaction. Knowing the
909+
// `mutation_count` value can help you maximize the number of mutations
910+
// in a transaction and minimize the number of API round trips. You can
911+
// also monitor this value to prevent transactions from exceeding the system
912+
// [limit](http://cloud.google.com/spanner/quotas#limits_for_creating_reading_updating_and_deleting_data).
913+
// If the number of mutations exceeds the limit, the server returns
914+
// [INVALID_ARGUMENT](http://cloud.google.com/spanner/docs/reference/rest/v1/Code#ENUM_VALUES.INVALID_ARGUMENT).
915+
int64 mutation_count = 1;
916+
}
917+
891918
// The Cloud Spanner timestamp at which the transaction committed.
892919
google.protobuf.Timestamp commit_timestamp = 1;
920+
921+
// The statistics about this Commit. Not returned by default.
922+
// For more information, see
923+
// [CommitRequest.return_commit_stats][google.spanner.v1.CommitRequest.return_commit_stats].
924+
CommitStats commit_stats = 2;
893925
}
894926

895927
// The request for [Rollback][google.spanner.v1.Spanner.Rollback].

google/spanner/v1/transaction.proto

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ option ruby_package = "Google::Cloud::Spanner::V1";
3131
// # Transactions
3232
//
3333
//
34-
// Each session can have at most one active transaction at a time. After the
35-
// active transaction is completed, the session can immediately be
36-
// re-used for the next transaction. It is not necessary to create a
37-
// new session for each transaction.
34+
// Each session can have at most one active transaction at a time (note that
35+
// standalone reads and queries use a transaction internally and do count
36+
// towards the one transaction limit). After the active transaction is
37+
// completed, the session can immediately be re-used for the next transaction.
38+
// It is not necessary to create a new session for each transaction.
3839
//
3940
// # Transaction Modes
4041
//

google/spanner/v1/type.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ message StructType {
5050
// SQL queries, it is the column alias (e.g., `"Word"` in the
5151
// query `"SELECT 'hello' AS Word"`), or the column name (e.g.,
5252
// `"ColName"` in the query `"SELECT ColName FROM Table"`). Some
53-
// columns might have an empty name (e.g., !"SELECT
53+
// columns might have an empty name (e.g., `"SELECT
5454
// UPPER(ColName)"`). Note that a query result can contain
5555
// multiple fields with the same name.
5656
string name = 1;

0 commit comments

Comments
 (0)