Skip to content

Commit f1d31f9

Browse files
feat(spanner): add cache updates API (#8307)
Co-authored-by: alkatrivedi <58396306+alkatrivedi@users.noreply.github.com>
1 parent 86086a6 commit f1d31f9

17 files changed

Lines changed: 8767 additions & 7705 deletions

handwritten/spanner/.OwlBot.yaml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
1-
# Copyright 2021 Google LLC
1+
# Copyright 2025 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.
55
# You may obtain a copy of the License at
66
#
7-
# http://www.apache.org/licenses/LICENSE-2.0
7+
# http://www.apache.org/licenses/LICENSE-2.0
88
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under the License is distributed on an "AS IS" BASIS,
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
16-
deep-remove-regex:
17-
- /owl-bot-staging
18-
1915
deep-copy-regex:
20-
- source: /google/spanner/(v.*)/.*-nodejs
21-
dest: /owl-bot-staging/spanner/$1
22-
- source: /google/spanner/(admin/database/v.*)/.*-nodejs
23-
dest: /owl-bot-staging/spanner/$1
24-
- source: /google/spanner/(admin/instance/v.*)/.*-nodejs
25-
dest: /owl-bot-staging/spanner/$1
26-
- source: /google/spanner/(executor/v.*)/.*-nodejs
27-
dest: /owl-bot-staging/spanner/$1
28-
29-
begin-after-commit-hash: 46f25fb1121747b994ff5818963fda84b5e6bfd3
16+
- source: /google/spanner/executor/google-spanner-executor-nodejs
17+
dest: /owl-bot-staging/google-spanner-executor
3018

19+
api-name: executor

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ syntax = "proto3";
1616

1717
package google.spanner.v1;
1818

19+
import "google/api/field_behavior.proto";
1920
import "google/protobuf/timestamp.proto";
21+
import "google/spanner/v1/location.proto";
2022
import "google/spanner/v1/transaction.proto";
2123

2224
option csharp_namespace = "Google.Cloud.Spanner.V1";
@@ -61,4 +63,18 @@ message CommitResponse {
6163
// timestamp at which all reads in the transaction ran. This timestamp is
6264
// never returned.
6365
google.protobuf.Timestamp snapshot_timestamp = 5;
66+
67+
// Optional. A cache update expresses a set of changes the client should
68+
// incorporate into its location cache. The client should discard the changes
69+
// if they are older than the data it already has. This data can be obtained
70+
// in response to requests that included a `RoutingHint` field, but may also
71+
// be obtained by explicit location-fetching RPCs which may be added in the
72+
// future.
73+
CacheUpdate cache_update = 6 [(google.api.field_behavior) = OPTIONAL];
74+
75+
// The isolation level used for the read-write transaction.
76+
TransactionOptions.IsolationLevel isolation_level = 7;
77+
78+
// The read lock mode used for the read-write transaction.
79+
TransactionOptions.ReadWrite.ReadLockMode read_lock_mode = 8;
6480
}

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

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,23 @@ service Spanner {
331331
};
332332
option (google.api.method_signature) = "session,mutation_groups";
333333
}
334+
335+
// Retrieves a cache update for a given database.
336+
//
337+
// This RPC can be used to warm up the client cache by fetching key recipes
338+
// and server information for a given database. It is recommended to call
339+
// this RPC at the beginning of the client's lifecycle, prior to any other
340+
// data plane operations.
341+
//
342+
// The cache update is returned as a stream because the response can be too
343+
// large to fit into a single `CacheUpdate` message.
344+
rpc FetchCacheUpdate(FetchCacheUpdateRequest) returns (stream CacheUpdate) {
345+
option (google.api.http) = {
346+
post: "/v1/{database=projects/*/instances/*/databases/*}:cacheUpdate"
347+
body: "*"
348+
};
349+
option (google.api.method_signature) = "database";
350+
}
334351
}
335352

336353
// The request for [CreateSession][google.spanner.v1.Spanner.CreateSession].
@@ -827,7 +844,7 @@ message ExecuteSqlRequest {
827844
// be assumed until a subsequent `Commit` call completes successfully.
828845
bool last_statement = 17 [(google.api.field_behavior) = OPTIONAL];
829846

830-
// Optional. If present, it makes the Spanner requests location-aware.
847+
// Optional. Makes the Spanner requests location-aware if present.
831848
//
832849
// It gives the server hints that can be used to route the request
833850
// to an appropriate server, potentially significantly decreasing latency and
@@ -1268,7 +1285,7 @@ message ReadRequest {
12681285
// transactions.
12691286
LockHint lock_hint = 17 [(google.api.field_behavior) = OPTIONAL];
12701287

1271-
// Optional. If present, it makes the Spanner requests location-aware.
1288+
// Optional. Makes the Spanner requests location-aware if present.
12721289
//
12731290
// It gives the server hints that can be used to route the request
12741291
// to an appropriate server, potentially significantly decreasing latency and
@@ -1301,6 +1318,14 @@ message BeginTransactionRequest {
13011318
// randomly select one of the mutations from the mutation set and send it as a
13021319
// part of this request.
13031320
Mutation mutation_key = 4 [(google.api.field_behavior) = OPTIONAL];
1321+
1322+
// Optional. Makes the Spanner requests location-aware if present.
1323+
//
1324+
// It gives the server hints that can be used to route the request
1325+
// to an appropriate server, potentially significantly decreasing latency and
1326+
// improving throughput. To achieve improved performance, most fields must be
1327+
// filled in with accurate values.
1328+
RoutingHint routing_hint = 5 [(google.api.field_behavior) = OPTIONAL];
13041329
}
13051330

13061331
// The request for [Commit][google.spanner.v1.Spanner.Commit].
@@ -1355,6 +1380,14 @@ message CommitRequest {
13551380
// results in a `FailedPrecondition` error.
13561381
MultiplexedSessionPrecommitToken precommit_token = 9
13571382
[(google.api.field_behavior) = OPTIONAL];
1383+
1384+
// Optional. Makes the Spanner requests location-aware if present.
1385+
//
1386+
// It gives the server hints that can be used to route the request
1387+
// to an appropriate server, potentially significantly decreasing latency and
1388+
// improving throughput. To achieve improved performance, most fields must be
1389+
// filled in with accurate values.
1390+
RoutingHint routing_hint = 10 [(google.api.field_behavior) = OPTIONAL];
13581391
}
13591392

13601393
// The request for [Rollback][google.spanner.v1.Spanner.Rollback].
@@ -1417,3 +1450,23 @@ message BatchWriteResponse {
14171450
// condition not being satisfied after evaluation.
14181451
google.protobuf.Timestamp commit_timestamp = 3;
14191452
}
1453+
1454+
// The request for
1455+
// [FetchCacheUpdate][google.spanner.v1.Spanner.FetchCacheUpdate].
1456+
message FetchCacheUpdateRequest {
1457+
// Required. The database for which to retrieve the cache update.
1458+
string database = 1 [
1459+
(google.api.field_behavior) = REQUIRED,
1460+
(google.api.resource_reference) = {
1461+
type: "spanner.googleapis.com/Database"
1462+
}
1463+
];
1464+
1465+
// Optional. The maximum number of key recipes to return in the response.
1466+
// If not set, a default limit of 100 will be used.
1467+
int32 max_recipe_count = 2 [(google.api.field_behavior) = OPTIONAL];
1468+
1469+
// Optional. The maximum number of ranges to return in the response.
1470+
// If not set, a default limit of 10000 will be used.
1471+
int32 max_range_count = 3 [(google.api.field_behavior) = OPTIONAL];
1472+
}

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

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package google.spanner.v1;
1919
import "google/api/field_behavior.proto";
2020
import "google/protobuf/duration.proto";
2121
import "google/protobuf/timestamp.proto";
22+
import "google/spanner/v1/location.proto";
2223

2324
option csharp_namespace = "Google.Cloud.Spanner.V1";
2425
option go_package = "cloud.google.com/go/spanner/apiv1/spannerpb;spannerpb";
@@ -39,35 +40,46 @@ message TransactionOptions {
3940
// Default value.
4041
//
4142
// * If isolation level is
43+
// [SERIALIZABLE][google.spanner.v1.TransactionOptions.IsolationLevel.SERIALIZABLE],
44+
// locking semantics default to `PESSIMISTIC`.
45+
// * If isolation level is
4246
// [REPEATABLE_READ][google.spanner.v1.TransactionOptions.IsolationLevel.REPEATABLE_READ],
43-
// then it is an error to specify `read_lock_mode`. Locking semantics
44-
// default to `OPTIMISTIC`. No validation checks are done for reads,
45-
// except to validate that the data that was served at the snapshot time
46-
// is unchanged at commit time in the following cases:
47-
// 1. reads done as part of queries that use `SELECT FOR UPDATE`
48-
// 2. reads done as part of statements with a `LOCK_SCANNED_RANGES`
49-
// hint
50-
// 3. reads done as part of DML statements
51-
// * At all other isolation levels, if `read_lock_mode` is the default
52-
// value, then pessimistic read locks are used.
47+
// locking semantics default to `OPTIMISTIC`.
48+
// * See
49+
// [Concurrency
50+
// control](https://cloud.google.com/spanner/docs/concurrency-control)
51+
// for more details.
5352
READ_LOCK_MODE_UNSPECIFIED = 0;
5453

5554
// Pessimistic lock mode.
5655
//
57-
// Read locks are acquired immediately on read.
58-
// Semantics described only applies to
56+
// Lock acquisition behavior depends on the isolation level in use. In
5957
// [SERIALIZABLE][google.spanner.v1.TransactionOptions.IsolationLevel.SERIALIZABLE]
60-
// isolation.
58+
// isolation, reads and writes acquire necessary locks during transaction
59+
// statement execution. In
60+
// [REPEATABLE_READ][google.spanner.v1.TransactionOptions.IsolationLevel.REPEATABLE_READ]
61+
// isolation, reads that explicitly request to be locked and writes
62+
// acquire locks.
63+
// See
64+
// [Concurrency
65+
// control](https://cloud.google.com/spanner/docs/concurrency-control) for
66+
// details on the types of locks acquired at each transaction step.
6167
PESSIMISTIC = 1;
6268

6369
// Optimistic lock mode.
6470
//
65-
// Locks for reads within the transaction are not acquired on read.
66-
// Instead the locks are acquired on a commit to validate that
67-
// read/queried data has not changed since the transaction started.
68-
// Semantics described only applies to
71+
// Lock acquisition behavior depends on the isolation level in use. In
72+
// both
6973
// [SERIALIZABLE][google.spanner.v1.TransactionOptions.IsolationLevel.SERIALIZABLE]
70-
// isolation.
74+
// and
75+
// [REPEATABLE_READ][google.spanner.v1.TransactionOptions.IsolationLevel.REPEATABLE_READ]
76+
// isolation, reads and writes do not acquire locks during transaction
77+
// statement execution.
78+
// See
79+
// [Concurrency
80+
// control](https://cloud.google.com/spanner/docs/concurrency-control) for
81+
// details on how the guarantees of each isolation level are provided at
82+
// commit time.
7183
OPTIMISTIC = 2;
7284
}
7385

@@ -264,6 +276,14 @@ message Transaction {
264276
// attempt should be passed to the [Commit][google.spanner.v1.Spanner.Commit]
265277
// request for this transaction.
266278
MultiplexedSessionPrecommitToken precommit_token = 3;
279+
280+
// Optional. A cache update expresses a set of changes the client should
281+
// incorporate into its location cache. The client should discard the changes
282+
// if they are older than the data it already has. This data can be obtained
283+
// in response to requests that included a `RoutingHint` field, but may also
284+
// be obtained by explicit location-fetching RPCs which may be added in the
285+
// future.
286+
CacheUpdate cache_update = 5 [(google.api.field_behavior) = OPTIONAL];
267287
}
268288

269289
// This message is used to select the transaction in which a

0 commit comments

Comments
 (0)