Skip to content

Commit b2b631f

Browse files
feat: add RPC Priority request options
PiperOrigin-RevId: 364449524 Source-Author: Google APIs <[email protected]> Source-Date: Mon Mar 22 17:39:37 2021 -0700 Source-Repo: googleapis/googleapis Source-Sha: 6598bb829c9e9a534be674649ffd1b4671a821f9 Source-Link: googleapis/googleapis@6598bb8
1 parent 02c5251 commit b2b631f

File tree

5 files changed

+126
-9
lines changed

5 files changed

+126
-9
lines changed

google/cloud/spanner_v1/proto/spanner.proto

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,42 @@ message DeleteSessionRequest {
425425
];
426426
}
427427

428+
// Common request options for various APIs.
429+
message RequestOptions {
430+
// The relative priority for requests. Note that priority is not applicable
431+
// for [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction].
432+
//
433+
// The priority acts as a hint to the Cloud Spanner scheduler and does not
434+
// guarantee priority or order of execution. For example:
435+
//
436+
// * Some parts of a write operation always execute at `PRIORITY_HIGH`,
437+
// regardless of the specified priority. This may cause you to see an
438+
// increase in high priority workload even when executing a low priority
439+
// request. This can also potentially cause a priority inversion where a
440+
// lower priority request will be fulfilled ahead of a higher priority
441+
// request.
442+
// * If a transaction contains multiple operations with different priorities,
443+
// Cloud Spanner does not guarantee to process the higher priority
444+
// operations first. There may be other constraints to satisfy, such as
445+
// order of operations.
446+
enum Priority {
447+
// `PRIORITY_UNSPECIFIED` is equivalent to `PRIORITY_HIGH`.
448+
PRIORITY_UNSPECIFIED = 0;
449+
450+
// This specifies that the request is low priority.
451+
PRIORITY_LOW = 1;
452+
453+
// This specifies that the request is medium priority.
454+
PRIORITY_MEDIUM = 2;
455+
456+
// This specifies that the request is high priority.
457+
PRIORITY_HIGH = 3;
458+
}
459+
460+
// Priority for the request.
461+
Priority priority = 1;
462+
}
463+
428464
// The request for [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql] and
429465
// [ExecuteStreamingSql][google.spanner.v1.Spanner.ExecuteStreamingSql].
430466
message ExecuteSqlRequest {
@@ -576,6 +612,9 @@ message ExecuteSqlRequest {
576612

577613
// Query optimizer configuration to use for the given query.
578614
QueryOptions query_options = 10;
615+
616+
// Common options for this request.
617+
RequestOptions request_options = 11;
579618
}
580619

581620
// The request for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml].
@@ -642,6 +681,9 @@ message ExecuteBatchDmlRequest {
642681
// sequence number, the transaction may be aborted. Replays of previously
643682
// handled requests will yield the same response as the first execution.
644683
int64 seqno = 4 [(google.api.field_behavior) = REQUIRED];
684+
685+
// Common options for this request.
686+
RequestOptions request_options = 5;
645687
}
646688

647689
// The response for [ExecuteBatchDml][google.spanner.v1.Spanner.ExecuteBatchDml]. Contains a list
@@ -876,6 +918,9 @@ message ReadRequest {
876918
// match for the values of fields common to this message and the
877919
// PartitionReadRequest message used to create this partition_token.
878920
bytes partition_token = 10;
921+
922+
// Common options for this request.
923+
RequestOptions request_options = 11;
879924
}
880925

881926
// The request for [BeginTransaction][google.spanner.v1.Spanner.BeginTransaction].
@@ -890,6 +935,13 @@ message BeginTransactionRequest {
890935

891936
// Required. Options for the new transaction.
892937
TransactionOptions options = 2 [(google.api.field_behavior) = REQUIRED];
938+
939+
// Common options for this request.
940+
// Priority is ignored for this request. Setting the priority in this
941+
// request_options struct will not do anything. To set the priority for a
942+
// transaction, set it on the reads and writes that are part of this
943+
// transaction instead.
944+
RequestOptions request_options = 3;
893945
}
894946

895947
// The request for [Commit][google.spanner.v1.Spanner.Commit].
@@ -928,6 +980,9 @@ message CommitRequest {
928980
// the [CommitResponse][google.spanner.v1.CommitResponse.commit_stats]. Default value is
929981
// `false`.
930982
bool return_commit_stats = 5;
983+
984+
// Common options for this request.
985+
RequestOptions request_options = 6;
931986
}
932987

933988
// The response for [Commit][google.spanner.v1.Spanner.Commit].

google/cloud/spanner_v1/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
PartitionReadRequest,
5151
PartitionResponse,
5252
ReadRequest,
53+
RequestOptions,
5354
RollbackRequest,
5455
Session,
5556
)
@@ -93,6 +94,7 @@
9394
"PartitionReadRequest",
9495
"PartitionResponse",
9596
"ReadRequest",
97+
"RequestOptions",
9698
"RollbackRequest",
9799
"Session",
98100
"Transaction",

google/cloud/spanner_v1/types/spanner.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"ListSessionsRequest",
4040
"ListSessionsResponse",
4141
"DeleteSessionRequest",
42+
"RequestOptions",
4243
"ExecuteSqlRequest",
4344
"ExecuteBatchDmlRequest",
4445
"ExecuteBatchDmlResponse",
@@ -240,6 +241,41 @@ class DeleteSessionRequest(proto.Message):
240241
name = proto.Field(proto.STRING, number=1)
241242

242243

244+
class RequestOptions(proto.Message):
245+
r"""Common request options for various APIs.
246+
247+
Attributes:
248+
priority (google.cloud.spanner_v1.types.RequestOptions.Priority):
249+
Priority for the request.
250+
"""
251+
252+
class Priority(proto.Enum):
253+
r"""The relative priority for requests. Note that priority is not
254+
applicable for
255+
[BeginTransaction][google.spanner.v1.Spanner.BeginTransaction].
256+
257+
The priority acts as a hint to the Cloud Spanner scheduler and does
258+
not guarantee priority or order of execution. For example:
259+
260+
- Some parts of a write operation always execute at
261+
``PRIORITY_HIGH``, regardless of the specified priority. This may
262+
cause you to see an increase in high priority workload even when
263+
executing a low priority request. This can also potentially cause
264+
a priority inversion where a lower priority request will be
265+
fulfilled ahead of a higher priority request.
266+
- If a transaction contains multiple operations with different
267+
priorities, Cloud Spanner does not guarantee to process the
268+
higher priority operations first. There may be other constraints
269+
to satisfy, such as order of operations.
270+
"""
271+
PRIORITY_UNSPECIFIED = 0
272+
PRIORITY_LOW = 1
273+
PRIORITY_MEDIUM = 2
274+
PRIORITY_HIGH = 3
275+
276+
priority = proto.Field(proto.ENUM, number=1, enum=Priority,)
277+
278+
243279
class ExecuteSqlRequest(proto.Message):
244280
r"""The request for [ExecuteSql][google.spanner.v1.Spanner.ExecuteSql]
245281
and
@@ -335,6 +371,8 @@ class ExecuteSqlRequest(proto.Message):
335371
query_options (google.cloud.spanner_v1.types.ExecuteSqlRequest.QueryOptions):
336372
Query optimizer configuration to use for the
337373
given query.
374+
request_options (google.cloud.spanner_v1.types.RequestOptions):
375+
Common options for this request.
338376
"""
339377

340378
class QueryMode(proto.Enum):
@@ -428,6 +466,8 @@ class QueryOptions(proto.Message):
428466

429467
query_options = proto.Field(proto.MESSAGE, number=10, message=QueryOptions,)
430468

469+
request_options = proto.Field(proto.MESSAGE, number=11, message="RequestOptions",)
470+
431471

432472
class ExecuteBatchDmlRequest(proto.Message):
433473
r"""The request for
@@ -466,6 +506,8 @@ class ExecuteBatchDmlRequest(proto.Message):
466506
sequence number, the transaction may be aborted.
467507
Replays of previously handled requests will
468508
yield the same response as the first execution.
509+
request_options (google.cloud.spanner_v1.types.RequestOptions):
510+
Common options for this request.
469511
"""
470512

471513
class Statement(proto.Message):
@@ -523,6 +565,8 @@ class Statement(proto.Message):
523565

524566
seqno = proto.Field(proto.INT64, number=4)
525567

568+
request_options = proto.Field(proto.MESSAGE, number=5, message="RequestOptions",)
569+
526570

527571
class ExecuteBatchDmlResponse(proto.Message):
528572
r"""The response for
@@ -867,6 +911,8 @@ class ReadRequest(proto.Message):
867911
must be an exact match for the values of fields common to
868912
this message and the PartitionReadRequest message used to
869913
create this partition_token.
914+
request_options (google.cloud.spanner_v1.types.RequestOptions):
915+
Common options for this request.
870916
"""
871917

872918
session = proto.Field(proto.STRING, number=1)
@@ -889,6 +935,8 @@ class ReadRequest(proto.Message):
889935

890936
partition_token = proto.Field(proto.BYTES, number=10)
891937

938+
request_options = proto.Field(proto.MESSAGE, number=11, message="RequestOptions",)
939+
892940

893941
class BeginTransactionRequest(proto.Message):
894942
r"""The request for
@@ -900,6 +948,12 @@ class BeginTransactionRequest(proto.Message):
900948
transaction runs.
901949
options (google.cloud.spanner_v1.types.TransactionOptions):
902950
Required. Options for the new transaction.
951+
request_options (google.cloud.spanner_v1.types.RequestOptions):
952+
Common options for this request. Priority is ignored for
953+
this request. Setting the priority in this request_options
954+
struct will not do anything. To set the priority for a
955+
transaction, set it on the reads and writes that are part of
956+
this transaction instead.
903957
"""
904958

905959
session = proto.Field(proto.STRING, number=1)
@@ -908,6 +962,8 @@ class BeginTransactionRequest(proto.Message):
908962
proto.MESSAGE, number=2, message=gs_transaction.TransactionOptions,
909963
)
910964

965+
request_options = proto.Field(proto.MESSAGE, number=3, message="RequestOptions",)
966+
911967

912968
class CommitRequest(proto.Message):
913969
r"""The request for [Commit][google.spanner.v1.Spanner.Commit].
@@ -938,6 +994,8 @@ class CommitRequest(proto.Message):
938994
be included in the
939995
[CommitResponse][google.spanner.v1.CommitResponse.commit_stats].
940996
Default value is ``false``.
997+
request_options (google.cloud.spanner_v1.types.RequestOptions):
998+
Common options for this request.
941999
"""
9421000

9431001
session = proto.Field(proto.STRING, number=1)
@@ -955,6 +1013,8 @@ class CommitRequest(proto.Message):
9551013

9561014
return_commit_stats = proto.Field(proto.BOOL, number=5)
9571015

1016+
request_options = proto.Field(proto.MESSAGE, number=6, message="RequestOptions",)
1017+
9581018

9591019
class CommitResponse(proto.Message):
9601020
r"""The response for [Commit][google.spanner.v1.Spanner.Commit].

scripts/fixup_spanner_v1_keywords.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ class spannerCallTransformer(cst.CSTTransformer):
4242
CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata')
4343
METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
4444
'batch_create_sessions': ('database', 'session_count', 'session_template', ),
45-
'begin_transaction': ('session', 'options', ),
46-
'commit': ('session', 'transaction_id', 'single_use_transaction', 'mutations', 'return_commit_stats', ),
45+
'begin_transaction': ('session', 'options', 'request_options', ),
46+
'commit': ('session', 'transaction_id', 'single_use_transaction', 'mutations', 'return_commit_stats', 'request_options', ),
4747
'create_session': ('database', 'session', ),
4848
'delete_session': ('name', ),
49-
'execute_batch_dml': ('session', 'transaction', 'statements', 'seqno', ),
50-
'execute_sql': ('session', 'sql', 'transaction', 'params', 'param_types', 'resume_token', 'query_mode', 'partition_token', 'seqno', 'query_options', ),
51-
'execute_streaming_sql': ('session', 'sql', 'transaction', 'params', 'param_types', 'resume_token', 'query_mode', 'partition_token', 'seqno', 'query_options', ),
49+
'execute_batch_dml': ('session', 'transaction', 'statements', 'seqno', 'request_options', ),
50+
'execute_sql': ('session', 'sql', 'transaction', 'params', 'param_types', 'resume_token', 'query_mode', 'partition_token', 'seqno', 'query_options', 'request_options', ),
51+
'execute_streaming_sql': ('session', 'sql', 'transaction', 'params', 'param_types', 'resume_token', 'query_mode', 'partition_token', 'seqno', 'query_options', 'request_options', ),
5252
'get_session': ('name', ),
5353
'list_sessions': ('database', 'page_size', 'page_token', 'filter', ),
5454
'partition_query': ('session', 'sql', 'transaction', 'params', 'param_types', 'partition_options', ),
5555
'partition_read': ('session', 'table', 'key_set', 'transaction', 'index', 'columns', 'partition_options', ),
56-
'read': ('session', 'table', 'columns', 'key_set', 'transaction', 'index', 'limit', 'resume_token', 'partition_token', ),
56+
'read': ('session', 'table', 'columns', 'key_set', 'transaction', 'index', 'limit', 'resume_token', 'partition_token', 'request_options', ),
5757
'rollback': ('session', 'transaction_id', ),
58-
'streaming_read': ('session', 'table', 'columns', 'key_set', 'transaction', 'index', 'limit', 'resume_token', 'partition_token', ),
58+
'streaming_read': ('session', 'table', 'columns', 'key_set', 'transaction', 'index', 'limit', 'resume_token', 'partition_token', 'request_options', ),
5959

6060
}
6161

synth.metadata

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"git": {
1212
"name": "googleapis",
1313
"remote": "https://github.com/googleapis/googleapis.git",
14-
"sha": "149a3a84c29c9b8189576c7442ccb6dcf6a8f95b",
15-
"internalRef": "364411656"
14+
"sha": "6598bb829c9e9a534be674649ffd1b4671a821f9",
15+
"internalRef": "364449524"
1616
}
1717
},
1818
{

0 commit comments

Comments
 (0)