google-cloud-spanner 2.0.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +49 -0
- data/CONTRIBUTING.md +2 -2
- data/LOGGING.md +1 -1
- data/lib/google-cloud-spanner.rb +1 -0
- data/lib/google/cloud/spanner.rb +7 -5
- data/lib/google/cloud/spanner/backup.rb +10 -2
- data/lib/google/cloud/spanner/backup/job.rb +8 -8
- data/lib/google/cloud/spanner/backup/job/list.rb +2 -2
- data/lib/google/cloud/spanner/backup/list.rb +2 -2
- data/lib/google/cloud/spanner/batch_snapshot.rb +114 -15
- data/lib/google/cloud/spanner/batch_update.rb +3 -1
- data/lib/google/cloud/spanner/client.rb +413 -78
- data/lib/google/cloud/spanner/commit_response.rb +87 -0
- data/lib/google/cloud/spanner/commit_response/commit_stats.rb +51 -0
- data/lib/google/cloud/spanner/convert.rb +9 -0
- data/lib/google/cloud/spanner/data.rb +4 -5
- data/lib/google/cloud/spanner/database.rb +25 -3
- data/lib/google/cloud/spanner/database/backup_info.rb +12 -3
- data/lib/google/cloud/spanner/database/job/list.rb +2 -2
- data/lib/google/cloud/spanner/database/list.rb +4 -4
- data/lib/google/cloud/spanner/fields.rb +3 -2
- data/lib/google/cloud/spanner/instance/config/list.rb +4 -4
- data/lib/google/cloud/spanner/instance/list.rb +4 -4
- data/lib/google/cloud/spanner/partition.rb +4 -2
- data/lib/google/cloud/spanner/policy.rb +3 -2
- data/lib/google/cloud/spanner/pool.rb +10 -10
- data/lib/google/cloud/spanner/results.rb +105 -26
- data/lib/google/cloud/spanner/service.rb +218 -107
- data/lib/google/cloud/spanner/session.rb +361 -30
- data/lib/google/cloud/spanner/snapshot.rb +58 -4
- data/lib/google/cloud/spanner/status.rb +4 -1
- data/lib/google/cloud/spanner/transaction.rb +114 -8
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9768d839e58d7697a3ec4d57f924c6dd251bf59b1bb531ca2fbcf14da1b6120d
|
4
|
+
data.tar.gz: 2fd33ab3bfddeaed840fd815d057e3ddb81bf3a4b746b88f20dcc72ecca46e44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba9f01ea9fc094a4ece357bacddc46cf235704f242eea88393de8ea5b1e5ae56b1f5260ad26e999ad53047d4a4c7f6d855612ea6de139e80ae7d60ec6b305fdf
|
7
|
+
data.tar.gz: fb498abaae70d4b8c56736b8267f87ae3637ddfe6b3aad675ad35c2faa1d4681a3a91be98ce6604454b185557a11aaf5a8294b0e007a849ff08ff19cad3088ae
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,54 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 2.5.0 / 2021-03-10
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* Drop support for Ruby 2.4 and add support for Ruby 3.0
|
8
|
+
|
9
|
+
### 2.4.0 / 2021-02-18
|
10
|
+
|
11
|
+
#### Features
|
12
|
+
|
13
|
+
* Point In Time Recovery (PITR) ([#8169](https://www.github.com/googleapis/google-cloud-ruby/issues/8169))
|
14
|
+
* feat(spanner): support pitr-lite
|
15
|
+
* feature(spanner): adds test for throttled
|
16
|
+
* feat(spanner): adds version time to backup
|
17
|
+
* test(spanner): adds unit test for create backup
|
18
|
+
* feat(spanner): exposes version time in backup
|
19
|
+
* chore: fixes rubocop violations
|
20
|
+
* fix: addresses PR comments
|
21
|
+
* test: adds integration tests for pitr backup
|
22
|
+
|
23
|
+
### 2.3.0 / 2021-02-09
|
24
|
+
|
25
|
+
#### Features
|
26
|
+
|
27
|
+
* CommitStats in CommitResponse ([#8058](https://www.github.com/googleapis/google-cloud-ruby/issues/8058))
|
28
|
+
* optionalize `credentials` when using cloud spanner emulator host ([#8416](https://www.github.com/googleapis/google-cloud-ruby/issues/8416))
|
29
|
+
* Optionalize `credentials` when using Cloud Spanner Emulator
|
30
|
+
* Remove unnecessary credentials stub for emulator_host in Google::Cloud::Spanner.new
|
31
|
+
* Add test of explicit project_id in Google::Cloud::Spanner.new
|
32
|
+
* Update document for `emulator_host` without credentials
|
33
|
+
* Tidy code according to rubocop settings
|
34
|
+
|
35
|
+
### 2.2.0 / 2020-09-15
|
36
|
+
|
37
|
+
#### Features
|
38
|
+
|
39
|
+
* quota_project can be set via library configuration
|
40
|
+
* Support numeric type.
|
41
|
+
|
42
|
+
#### Bug Fixes
|
43
|
+
|
44
|
+
* retry or resume eos and rst_stream errors
|
45
|
+
|
46
|
+
### 2.1.0 / 2020-08-05
|
47
|
+
|
48
|
+
#### Features
|
49
|
+
|
50
|
+
* Support custom setting of timeout and retry
|
51
|
+
|
3
52
|
### 2.0.0 / 2020-07-23
|
4
53
|
|
5
54
|
This is a major update that removes the "low-level" client interface code, and
|
data/CONTRIBUTING.md
CHANGED
@@ -24,7 +24,7 @@ be able to accept your pull requests.
|
|
24
24
|
In order to use the google-cloud-spanner console and run the project's tests,
|
25
25
|
there is a small amount of setup:
|
26
26
|
|
27
|
-
1. Install Ruby. google-cloud-spanner requires Ruby 2.
|
27
|
+
1. Install Ruby. google-cloud-spanner requires Ruby 2.5+. You may choose to
|
28
28
|
manage your Ruby and gem installations with [RVM](https://rvm.io/),
|
29
29
|
[rbenv](https://github.com/rbenv/rbenv), or
|
30
30
|
[chruby](https://github.com/postmodern/chruby).
|
@@ -45,7 +45,7 @@ there is a small amount of setup:
|
|
45
45
|
|
46
46
|
```sh
|
47
47
|
$ cd google-cloud-spanner/
|
48
|
-
$ bundle
|
48
|
+
$ bundle install
|
49
49
|
```
|
50
50
|
|
51
51
|
## Console
|
data/LOGGING.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
To enable logging for this library, set the logger for the underlying
|
4
4
|
[gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
|
5
5
|
that you set may be a Ruby stdlib
|
6
|
-
[`Logger`](https://ruby-doc.org/stdlib
|
6
|
+
[`Logger`](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html) as
|
7
7
|
shown below, or a
|
8
8
|
[`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
|
9
9
|
that will write logs to [Stackdriver
|
data/lib/google-cloud-spanner.rb
CHANGED
@@ -174,6 +174,7 @@ Google::Cloud.configure.add_config! :spanner do |config|
|
|
174
174
|
allow_nil: true
|
175
175
|
config.add_alias! :keyfile, :credentials
|
176
176
|
config.add_field! :scope, default_scopes, match: [String, Array]
|
177
|
+
config.add_field! :quota_project, nil, match: String
|
177
178
|
config.add_field! :timeout, nil, match: Integer
|
178
179
|
config.add_field! :endpoint, "spanner.googleapis.com", match: String
|
179
180
|
config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
|
data/lib/google/cloud/spanner.rb
CHANGED
@@ -49,6 +49,8 @@ module Google
|
|
49
49
|
# @param [String, Hash, Google::Auth::Credentials] credentials The path to
|
50
50
|
# the keyfile as a String, the contents of the keyfile as a Hash, or a
|
51
51
|
# Google::Auth::Credentials object. (See {Spanner::Credentials})
|
52
|
+
# If `emulator_host` is present, this becomes optional and the value is
|
53
|
+
# internally overriden with `:this_channel_is_insecure`.
|
52
54
|
# @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
|
53
55
|
# the set of resources and operations that the connection can access.
|
54
56
|
# See [Using OAuth 2.0 to Access Google
|
@@ -60,7 +62,7 @@ module Google
|
|
60
62
|
# * `https://www.googleapis.com/auth/spanner.data`
|
61
63
|
# @param [Integer] timeout Default timeout to use in requests. Optional.
|
62
64
|
# @param [String] endpoint Override of the endpoint host name. Optional.
|
63
|
-
# If the param is nil, uses the default endpoint.
|
65
|
+
# If the param is nil, uses `emulator_host` or the default endpoint.
|
64
66
|
# @param [String] project Alias for the `project_id` argument. Deprecated.
|
65
67
|
# @param [String] keyfile Alias for the `credentials` argument.
|
66
68
|
# Deprecated.
|
@@ -91,19 +93,19 @@ module Google
|
|
91
93
|
def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
|
92
94
|
endpoint: nil, project: nil, keyfile: nil,
|
93
95
|
emulator_host: nil, lib_name: nil, lib_version: nil
|
94
|
-
project_id ||=
|
96
|
+
project_id ||= project || default_project_id
|
95
97
|
scope ||= configure.scope
|
96
98
|
timeout ||= configure.timeout
|
97
|
-
endpoint ||= configure.endpoint
|
98
|
-
credentials ||= (keyfile || default_credentials(scope: scope))
|
99
99
|
emulator_host ||= configure.emulator_host
|
100
|
+
endpoint ||= emulator_host || configure.endpoint
|
101
|
+
credentials ||= keyfile
|
100
102
|
lib_name ||= configure.lib_name
|
101
103
|
lib_version ||= configure.lib_version
|
102
104
|
|
103
105
|
if emulator_host
|
104
106
|
credentials = :this_channel_is_insecure
|
105
|
-
endpoint = emulator_host
|
106
107
|
else
|
108
|
+
credentials ||= default_credentials scope: scope
|
107
109
|
unless credentials.is_a? Google::Auth::Credentials
|
108
110
|
credentials = Spanner::Credentials.new credentials, scope: scope
|
109
111
|
end
|
@@ -155,9 +155,17 @@ module Google
|
|
155
155
|
@grpc.expire_time = Convert.time_to_timestamp time
|
156
156
|
update_mask = Google::Protobuf::FieldMask.new paths: ["expire_time"]
|
157
157
|
@grpc = service.update_backup @grpc, update_mask
|
158
|
-
rescue Google::Cloud::Error =>
|
158
|
+
rescue Google::Cloud::Error => e
|
159
159
|
@grpc.expire_time = expire_time_was
|
160
|
-
raise
|
160
|
+
raise e
|
161
|
+
end
|
162
|
+
|
163
|
+
##
|
164
|
+
# The timestamp when a consistent copy of the database for the backup was
|
165
|
+
# taken. The version time has microseconds granularity.
|
166
|
+
# @return [Time]
|
167
|
+
def version_time
|
168
|
+
Convert.timestamp_to_time @grpc.version_time
|
161
169
|
end
|
162
170
|
|
163
171
|
##
|
@@ -39,7 +39,7 @@ module Google
|
|
39
39
|
#
|
40
40
|
# database = spanner.database "my-instance", "my-database"
|
41
41
|
# expire_time = Time.now + 36000
|
42
|
-
# job = database.create_backup "my-backup", expire_time
|
42
|
+
# job = database.create_backup "my-backup", expire_time
|
43
43
|
#
|
44
44
|
# job.done? #=> false
|
45
45
|
# job.reload! # API call
|
@@ -80,7 +80,7 @@ module Google
|
|
80
80
|
#
|
81
81
|
# database = spanner.database "my-instance", "my-database"
|
82
82
|
# expire_time = Time.now + 36000
|
83
|
-
# job = database.create_backup "my-backup", expire_time
|
83
|
+
# job = database.create_backup "my-backup", expire_time
|
84
84
|
#
|
85
85
|
# job.done? #=> false
|
86
86
|
# job.reload!
|
@@ -105,7 +105,7 @@ module Google
|
|
105
105
|
#
|
106
106
|
# database = spanner.database "my-instance", "my-database"
|
107
107
|
# expire_time = Time.now + 36000
|
108
|
-
# job = database.create_backup "my-backup", expire_time
|
108
|
+
# job = database.create_backup "my-backup", expire_time
|
109
109
|
#
|
110
110
|
# job.done? #=> false
|
111
111
|
#
|
@@ -125,7 +125,7 @@ module Google
|
|
125
125
|
#
|
126
126
|
# database = spanner.database "my-instance", "my-database"
|
127
127
|
# expire_time = Time.now + 36000
|
128
|
-
# job = database.create_backup "my-backup", expire_time
|
128
|
+
# job = database.create_backup "my-backup", expire_time
|
129
129
|
#
|
130
130
|
# job.error? #=> false
|
131
131
|
#
|
@@ -147,7 +147,7 @@ module Google
|
|
147
147
|
#
|
148
148
|
# database = spanner.database "my-instance", "my-database"
|
149
149
|
# expire_time = Time.now + 36000
|
150
|
-
# job = database.create_backup "my-backup", expire_time
|
150
|
+
# job = database.create_backup "my-backup", expire_time
|
151
151
|
#
|
152
152
|
# job.error? # true
|
153
153
|
#
|
@@ -172,7 +172,7 @@ module Google
|
|
172
172
|
#
|
173
173
|
# database = spanner.database "my-instance", "my-database"
|
174
174
|
# expire_time = Time.now + 36000
|
175
|
-
# job = database.create_backup "my-backup", expire_time
|
175
|
+
# job = database.create_backup "my-backup", expire_time
|
176
176
|
#
|
177
177
|
# job.done? #=> false
|
178
178
|
# job.reload! # API call
|
@@ -195,7 +195,7 @@ module Google
|
|
195
195
|
#
|
196
196
|
# database = spanner.database "my-instance", "my-database"
|
197
197
|
# expire_time = Time.now + 36000
|
198
|
-
# job = database.create_backup "my-backup", expire_time
|
198
|
+
# job = database.create_backup "my-backup", expire_time
|
199
199
|
#
|
200
200
|
# job.done? #=> false
|
201
201
|
# job.wait_until_done!
|
@@ -215,7 +215,7 @@ module Google
|
|
215
215
|
#
|
216
216
|
# database = spanner.database "my-instance", "my-database"
|
217
217
|
# expire_time = Time.now + 36000
|
218
|
-
# job = database.create_backup "my-backup", expire_time
|
218
|
+
# job = database.create_backup "my-backup", expire_time
|
219
219
|
#
|
220
220
|
# job.done? #=> false
|
221
221
|
# job.cancel
|
@@ -130,12 +130,12 @@ module Google
|
|
130
130
|
# job.backup.backup_id
|
131
131
|
# end
|
132
132
|
#
|
133
|
-
def all
|
133
|
+
def all &block
|
134
134
|
return enum_for :all unless block_given?
|
135
135
|
|
136
136
|
results = self
|
137
137
|
loop do
|
138
|
-
results.each
|
138
|
+
results.each(&block)
|
139
139
|
break unless next?
|
140
140
|
grpc.next_page
|
141
141
|
results = self.class.from_grpc grpc, service
|
@@ -128,12 +128,12 @@ module Google
|
|
128
128
|
# backup.backup_id
|
129
129
|
# end
|
130
130
|
#
|
131
|
-
def all
|
131
|
+
def all &block
|
132
132
|
return enum_for :all unless block_given?
|
133
133
|
|
134
134
|
results = self
|
135
135
|
loop do
|
136
|
-
results.each
|
136
|
+
results.each(&block)
|
137
137
|
break unless next?
|
138
138
|
grpc.next_page
|
139
139
|
results = self.class.from_grpc grpc, service
|
@@ -173,6 +173,19 @@ module Google
|
|
173
173
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
174
174
|
# Empty to use database default. "latest" to use the latest
|
175
175
|
# available optimizer version.
|
176
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
177
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
178
|
+
# optional. The following settings can be provided:
|
179
|
+
#
|
180
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
181
|
+
# that overrides the default setting.
|
182
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
183
|
+
# setting of retry policy with the following keys:
|
184
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
185
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
186
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
187
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
188
|
+
# trigger a retry.
|
176
189
|
#
|
177
190
|
# @return [Array<Google::Cloud::Spanner::Partition>] The partitions
|
178
191
|
# created by the query partition.
|
@@ -196,7 +209,7 @@ module Google
|
|
196
209
|
#
|
197
210
|
def partition_query sql, params: nil, types: nil,
|
198
211
|
partition_size_bytes: nil, max_partitions: nil,
|
199
|
-
query_options: nil
|
212
|
+
query_options: nil, call_options: nil
|
200
213
|
ensure_session!
|
201
214
|
|
202
215
|
params, types = Convert.to_input_params_and_types params, types
|
@@ -204,7 +217,8 @@ module Google
|
|
204
217
|
results = session.partition_query \
|
205
218
|
sql, tx_selector, params: params, types: types,
|
206
219
|
partition_size_bytes: partition_size_bytes,
|
207
|
-
max_partitions: max_partitions
|
220
|
+
max_partitions: max_partitions,
|
221
|
+
call_options: call_options
|
208
222
|
results.partitions.map do |grpc|
|
209
223
|
# Convert partition protos to execute sql request protos
|
210
224
|
execute_sql_grpc = V1::ExecuteSqlRequest.new(
|
@@ -248,6 +262,19 @@ module Google
|
|
248
262
|
# partitions to return. For example, this may be set to the number of
|
249
263
|
# workers available. This is only a hint and may provide different
|
250
264
|
# results based on the request.
|
265
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
266
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
267
|
+
# optional. The following settings can be provided:
|
268
|
+
#
|
269
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
270
|
+
# that overrides the default setting.
|
271
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
272
|
+
# setting of retry policy with the following keys:
|
273
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
274
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
275
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
276
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
277
|
+
# trigger a retry.
|
251
278
|
#
|
252
279
|
# @return [Array<Google::Cloud::Spanner::Partition>] The partitions
|
253
280
|
# created by the read partition.
|
@@ -268,7 +295,8 @@ module Google
|
|
268
295
|
# batch_snapshot.close
|
269
296
|
#
|
270
297
|
def partition_read table, columns, keys: nil, index: nil,
|
271
|
-
partition_size_bytes: nil, max_partitions: nil
|
298
|
+
partition_size_bytes: nil, max_partitions: nil,
|
299
|
+
call_options: nil
|
272
300
|
ensure_session!
|
273
301
|
|
274
302
|
columns = Array(columns).map(&:to_s)
|
@@ -278,7 +306,8 @@ module Google
|
|
278
306
|
table, columns, tx_selector,
|
279
307
|
keys: keys, index: index,
|
280
308
|
partition_size_bytes: partition_size_bytes,
|
281
|
-
max_partitions: max_partitions
|
309
|
+
max_partitions: max_partitions,
|
310
|
+
call_options: call_options
|
282
311
|
|
283
312
|
results.partitions.map do |grpc|
|
284
313
|
# Convert partition protos to read request protos
|
@@ -304,6 +333,19 @@ module Google
|
|
304
333
|
#
|
305
334
|
# @param [Google::Cloud::Spanner::Partition] partition The partition to
|
306
335
|
# be executed.
|
336
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
337
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
338
|
+
# optional. The following settings can be provided:
|
339
|
+
#
|
340
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
341
|
+
# that overrides the default setting.
|
342
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
343
|
+
# setting of retry policy with the following keys:
|
344
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
345
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
346
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
347
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
348
|
+
# trigger a retry.
|
307
349
|
#
|
308
350
|
# @example
|
309
351
|
# require "google/cloud/spanner"
|
@@ -320,7 +362,7 @@ module Google
|
|
320
362
|
#
|
321
363
|
# batch_snapshot.close
|
322
364
|
#
|
323
|
-
def execute_partition partition
|
365
|
+
def execute_partition partition, call_options: nil
|
324
366
|
ensure_session!
|
325
367
|
|
326
368
|
partition = Partition.load partition unless partition.is_a? Partition
|
@@ -329,10 +371,11 @@ module Google
|
|
329
371
|
# TODO: raise if session.path != partition.session
|
330
372
|
# TODO: raise if grpc.transaction != partition.transaction
|
331
373
|
|
374
|
+
opts = { call_options: call_options }
|
332
375
|
if partition.execute?
|
333
|
-
execute_partition_query partition
|
376
|
+
execute_partition_query partition, **opts
|
334
377
|
elsif partition.read?
|
335
|
-
execute_partition_read partition
|
378
|
+
execute_partition_read partition, **opts
|
336
379
|
end
|
337
380
|
end
|
338
381
|
|
@@ -430,6 +473,19 @@ module Google
|
|
430
473
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
431
474
|
# Empty to use database default. "latest" to use the latest
|
432
475
|
# available optimizer version.
|
476
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
477
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
478
|
+
# optional. The following settings can be provided:
|
479
|
+
#
|
480
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
481
|
+
# that overrides the default setting.
|
482
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
483
|
+
# setting of retry policy with the following keys:
|
484
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
485
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
486
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
487
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
488
|
+
# trigger a retry.
|
433
489
|
#
|
434
490
|
# @return [Google::Cloud::Spanner::Results] The results of the query
|
435
491
|
# execution.
|
@@ -549,14 +605,40 @@ module Google
|
|
549
605
|
# puts "User #{row[:id]} is #{row[:name]}"
|
550
606
|
# end
|
551
607
|
#
|
552
|
-
|
608
|
+
# @example Query using custom timeout and retry policy:
|
609
|
+
# require "google/cloud/spanner"
|
610
|
+
#
|
611
|
+
# spanner = Google::Cloud::Spanner.new
|
612
|
+
# batch_client = spanner.batch_client "my-instance", "my-database"
|
613
|
+
# batch_snapshot = batch_client.batch_snapshot
|
614
|
+
#
|
615
|
+
# timeout = 30.0
|
616
|
+
# retry_policy = {
|
617
|
+
# initial_delay: 0.25,
|
618
|
+
# max_delay: 32.0,
|
619
|
+
# multiplier: 1.3,
|
620
|
+
# retry_codes: ["UNAVAILABLE"]
|
621
|
+
# }
|
622
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
623
|
+
#
|
624
|
+
# results = batch_snapshot.execute_query \
|
625
|
+
# "SELECT * FROM users",
|
626
|
+
# call_options: call_options
|
627
|
+
#
|
628
|
+
# results.rows.each do |row|
|
629
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
630
|
+
# end
|
631
|
+
#
|
632
|
+
def execute_query sql, params: nil, types: nil, query_options: nil,
|
633
|
+
call_options: nil
|
553
634
|
ensure_session!
|
554
635
|
|
555
636
|
params, types = Convert.to_input_params_and_types params, types
|
556
637
|
|
557
638
|
session.execute_query sql, params: params, types: types,
|
558
639
|
transaction: tx_selector,
|
559
|
-
query_options: query_options
|
640
|
+
query_options: query_options,
|
641
|
+
call_options: call_options
|
560
642
|
end
|
561
643
|
alias execute execute_query
|
562
644
|
alias query execute_query
|
@@ -578,6 +660,19 @@ module Google
|
|
578
660
|
# Optional.
|
579
661
|
# @param [Integer] limit If greater than zero, no more than this number
|
580
662
|
# of rows will be returned. The default is no limit.
|
663
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
664
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
665
|
+
# optional. The following settings can be provided:
|
666
|
+
#
|
667
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
668
|
+
# that overrides the default setting.
|
669
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
670
|
+
# setting of retry policy with the following keys:
|
671
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
672
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
673
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
674
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
675
|
+
# trigger a retry.
|
581
676
|
#
|
582
677
|
# @return [Google::Cloud::Spanner::Results] The results of the read
|
583
678
|
# operation.
|
@@ -595,14 +690,16 @@ module Google
|
|
595
690
|
# puts "User #{row[:id]} is #{row[:name]}"
|
596
691
|
# end
|
597
692
|
#
|
598
|
-
def read table, columns, keys: nil, index: nil, limit: nil
|
693
|
+
def read table, columns, keys: nil, index: nil, limit: nil,
|
694
|
+
call_options: nil
|
599
695
|
ensure_session!
|
600
696
|
|
601
697
|
columns = Array(columns).map(&:to_s)
|
602
698
|
keys = Convert.to_key_set keys
|
603
699
|
|
604
700
|
session.read table, columns, keys: keys, index: index, limit: limit,
|
605
|
-
transaction: tx_selector
|
701
|
+
transaction: tx_selector,
|
702
|
+
call_options: call_options
|
606
703
|
end
|
607
704
|
|
608
705
|
##
|
@@ -690,7 +787,7 @@ module Google
|
|
690
787
|
raise "Must have active connection to service" unless session
|
691
788
|
end
|
692
789
|
|
693
|
-
def execute_partition_query partition
|
790
|
+
def execute_partition_query partition, call_options: nil
|
694
791
|
query_options = partition.execute.query_options
|
695
792
|
query_options = query_options.to_h unless query_options.nil?
|
696
793
|
session.execute_query \
|
@@ -699,16 +796,18 @@ module Google
|
|
699
796
|
types: partition.execute.param_types.to_h,
|
700
797
|
transaction: partition.execute.transaction,
|
701
798
|
partition_token: partition.execute.partition_token,
|
702
|
-
query_options: query_options
|
799
|
+
query_options: query_options,
|
800
|
+
call_options: call_options
|
703
801
|
end
|
704
802
|
|
705
|
-
def execute_partition_read partition
|
803
|
+
def execute_partition_read partition, call_options: nil
|
706
804
|
session.read partition.read.table,
|
707
805
|
partition.read.columns.to_a,
|
708
806
|
keys: partition.read.key_set,
|
709
807
|
index: partition.read.index,
|
710
808
|
transaction: partition.read.transaction,
|
711
|
-
partition_token: partition.read.partition_token
|
809
|
+
partition_token: partition.read.partition_token,
|
810
|
+
call_options: call_options
|
712
811
|
end
|
713
812
|
end
|
714
813
|
end
|