google-cloud-spanner 2.3.0 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +64 -0
- data/CONTRIBUTING.md +1 -1
- data/LOGGING.md +1 -1
- data/OVERVIEW.md +1 -1
- data/lib/google-cloud-spanner.rb +2 -0
- data/lib/google/cloud/spanner/backup.rb +75 -4
- 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 +11 -4
- data/lib/google/cloud/spanner/batch_update.rb +3 -1
- data/lib/google/cloud/spanner/client.rb +315 -83
- data/lib/google/cloud/spanner/commit.rb +4 -0
- data/lib/google/cloud/spanner/data.rb +4 -5
- data/lib/google/cloud/spanner/database.rb +111 -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 +5 -3
- data/lib/google/cloud/spanner/instance.rb +91 -3
- 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/project.rb +65 -5
- data/lib/google/cloud/spanner/results.rb +13 -9
- data/lib/google/cloud/spanner/service.rb +44 -24
- data/lib/google/cloud/spanner/session.rb +38 -15
- data/lib/google/cloud/spanner/snapshot.rb +10 -2
- data/lib/google/cloud/spanner/status.rb +4 -1
- data/lib/google/cloud/spanner/transaction.rb +61 -6
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8347879380e3278cec1dee95179755b0f1ff4ffecea9fae6b04861bd43976d1
|
4
|
+
data.tar.gz: b6c66cb0637a396bfee1e590b6316826f24a5dc45739c57de19c14c0304bc501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a2caf305e7484bd7c17d89973ee3eb536a11b202fa7b85443f33b60ebafc65fb67a57106ca75fda2d448c45614479c44745344af17267f6577b37a5389c2d02
|
7
|
+
data.tar.gz: 3be51dc4c55d948f57c19e2be190cbc27b259793d63b77d366ae9bc8beb7e64c67135127e130b3837305576a41eb5ae370e810ec58ccbb46f627e0816c0359f8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,69 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
### 2.8.0 / 2021-06-17
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
* create instance using processing units/node count ([#11379](https://www.github.com/googleapis/google-cloud-ruby/issues/11379))
|
8
|
+
* create instance using processing units/node count
|
9
|
+
* fix typo
|
10
|
+
* removed node count and processing unit validations
|
11
|
+
* update orignal value on instance save
|
12
|
+
* remove orignal_values to current_valuess
|
13
|
+
|
14
|
+
### 2.7.0 / 2021-06-09
|
15
|
+
|
16
|
+
#### Features
|
17
|
+
|
18
|
+
* add the support of optimizer statistics package ([#7591](https://www.github.com/googleapis/google-cloud-ruby/issues/7591))
|
19
|
+
* feat(spanner): add the support of optimizer statistics package
|
20
|
+
* Fix rubocop issues.
|
21
|
+
* Fix the env issue.
|
22
|
+
* database create time access method ([#11617](https://www.github.com/googleapis/google-cloud-ruby/issues/11617))
|
23
|
+
* added database create time method
|
24
|
+
* remove assert for databse create time
|
25
|
+
* RPC priority request option. ([#11258](https://www.github.com/googleapis/google-cloud-ruby/issues/11258))
|
26
|
+
|
27
|
+
#### Bug Fixes
|
28
|
+
|
29
|
+
* extract binary retry info from error ([#11656](https://www.github.com/googleapis/google-cloud-ruby/issues/11656))
|
30
|
+
* fix: extract binary retry info from error
|
31
|
+
* fix: remove unrelated frozen_string_literal change
|
32
|
+
* fix: remove unnecessary parentheses
|
33
|
+
|
34
|
+
### 2.6.0 / 2021-03-31
|
35
|
+
|
36
|
+
#### Features
|
37
|
+
|
38
|
+
* add cmek backup support - ext of [#8142](https://www.github.com/googleapis/google-cloud-ruby/issues/8142) ([#8168](https://www.github.com/googleapis/google-cloud-ruby/issues/8168))
|
39
|
+
* feat(spanner): add cmek backup support
|
40
|
+
* Add encryption_config to restore database.
|
41
|
+
* doc example for backup create with encryption config
|
42
|
+
* create backup with encryption type
|
43
|
+
* backup restore with encryption type changes
|
44
|
+
* fix typo
|
45
|
+
* add cmek db support
|
46
|
+
|
47
|
+
### 2.5.0 / 2021-03-10
|
48
|
+
|
49
|
+
#### Features
|
50
|
+
|
51
|
+
* Drop support for Ruby 2.4 and add support for Ruby 3.0
|
52
|
+
|
53
|
+
### 2.4.0 / 2021-02-18
|
54
|
+
|
55
|
+
#### Features
|
56
|
+
|
57
|
+
* Point In Time Recovery (PITR) ([#8169](https://www.github.com/googleapis/google-cloud-ruby/issues/8169))
|
58
|
+
* feat(spanner): support pitr-lite
|
59
|
+
* feature(spanner): adds test for throttled
|
60
|
+
* feat(spanner): adds version time to backup
|
61
|
+
* test(spanner): adds unit test for create backup
|
62
|
+
* feat(spanner): exposes version time in backup
|
63
|
+
* chore: fixes rubocop violations
|
64
|
+
* fix: addresses PR comments
|
65
|
+
* test: adds integration tests for pitr backup
|
66
|
+
|
3
67
|
### 2.3.0 / 2021-02-09
|
4
68
|
|
5
69
|
#### Features
|
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).
|
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/OVERVIEW.md
CHANGED
data/lib/google-cloud-spanner.rb
CHANGED
@@ -156,7 +156,9 @@ Google::Cloud.configure.add_config! :spanner do |config|
|
|
156
156
|
default_query_options = Google::Cloud::Config.deferred do
|
157
157
|
query_options = {}
|
158
158
|
optimizer_version = ENV["SPANNER_OPTIMIZER_VERSION"]
|
159
|
+
optimizer_stats_pkg = ENV["SPANNER_OPTIMIZER_STATISTICS_PACKAGE"]
|
159
160
|
query_options[:optimizer_version] = optimizer_version if optimizer_version
|
161
|
+
query_options[:optimizer_statistics_package] = optimizer_stats_pkg if optimizer_stats_pkg
|
160
162
|
query_options = nil if query_options.empty?
|
161
163
|
query_options
|
162
164
|
end
|
@@ -88,6 +88,12 @@ module Google
|
|
88
88
|
@grpc.database.split("/")[5]
|
89
89
|
end
|
90
90
|
|
91
|
+
# Encryption information for a given resource.
|
92
|
+
# @return [Google::Cloud::Spanner::Admin::Database::V1::EncryptionInfo, nil]
|
93
|
+
def encryption_info
|
94
|
+
@grpc.encryption_info
|
95
|
+
end
|
96
|
+
|
91
97
|
##
|
92
98
|
# The full path for the backup. Values are of the form
|
93
99
|
# `projects/<project>/instances/<instance>/backups/<backup_id>`.
|
@@ -155,9 +161,17 @@ module Google
|
|
155
161
|
@grpc.expire_time = Convert.time_to_timestamp time
|
156
162
|
update_mask = Google::Protobuf::FieldMask.new paths: ["expire_time"]
|
157
163
|
@grpc = service.update_backup @grpc, update_mask
|
158
|
-
rescue Google::Cloud::Error =>
|
164
|
+
rescue Google::Cloud::Error => e
|
159
165
|
@grpc.expire_time = expire_time_was
|
160
|
-
raise
|
166
|
+
raise e
|
167
|
+
end
|
168
|
+
|
169
|
+
##
|
170
|
+
# The timestamp when a consistent copy of the database for the backup was
|
171
|
+
# taken. The version time has microseconds granularity.
|
172
|
+
# @return [Time]
|
173
|
+
def version_time
|
174
|
+
Convert.timestamp_to_time @grpc.version_time
|
161
175
|
end
|
162
176
|
|
163
177
|
##
|
@@ -237,6 +251,29 @@ module Google
|
|
237
251
|
# project and have the same instance configuration as the instance
|
238
252
|
# containing the source backup. Optional. Default value is same as a
|
239
253
|
# backup instance.
|
254
|
+
# @param [Hash] encryption_config An encryption configuration describing
|
255
|
+
# the encryption type and key resources in Cloud KMS used to
|
256
|
+
# encrypt/decrypt the database to restore to. If this field is not
|
257
|
+
# specified, the restored database will use the same encryption
|
258
|
+
# configuration as the backup by default. Optional. The following
|
259
|
+
# settings can be provided:
|
260
|
+
#
|
261
|
+
# * `:kms_key_name` (String) The name of KMS key to use which should
|
262
|
+
# be the full path, e.g., `projects/<project>/locations/<location>\
|
263
|
+
# /keyRings/<key_ring>/cryptoKeys/<kms_key_name>`
|
264
|
+
# This field should be set only when encryption type
|
265
|
+
# `:CUSTOMER_MANAGED_ENCRYPTION`.
|
266
|
+
# * `:encryption_type` (Symbol) The encryption type of the backup.
|
267
|
+
# Valid values are:
|
268
|
+
# 1. `:USE_CONFIG_DEFAULT_OR_BACKUP_ENCRYPTION` - This is the default
|
269
|
+
# option when config is not specified.
|
270
|
+
# 2. `:GOOGLE_DEFAULT_ENCRYPTION` - Google default encryption.
|
271
|
+
# 3. `:CUSTOMER_MANAGED_ENCRYPTION` - Use customer managed encryption.
|
272
|
+
# If specified, `:kms_key_name` must contain a valid Cloud KMS key.
|
273
|
+
#
|
274
|
+
# @raise [ArgumentError] if `:CUSTOMER_MANAGED_ENCRYPTION` specified without
|
275
|
+
# customer managed kms key.
|
276
|
+
#
|
240
277
|
# @return [Database] Restored database.
|
241
278
|
#
|
242
279
|
# @example
|
@@ -280,16 +317,50 @@ module Google
|
|
280
317
|
# database = job.database
|
281
318
|
# end
|
282
319
|
#
|
283
|
-
|
320
|
+
# @example Restore database with encryption config
|
321
|
+
# require "google/cloud/spanner"
|
322
|
+
#
|
323
|
+
# spanner = Google::Cloud::Spanner.new
|
324
|
+
#
|
325
|
+
# instance = spanner.instance "my-instance"
|
326
|
+
# backup = instance.backup "my-backup"
|
327
|
+
# kms_key_name = "projects/<project>/locations/<location>/keyRings/<key_ring>/cryptoKeys/<kms_key_name>"
|
328
|
+
# encryption_config = {
|
329
|
+
# kms_key_name: kms_key_name,
|
330
|
+
# encryption_type: :CUSTOMER_MANAGED_ENCRYPTION
|
331
|
+
# }
|
332
|
+
# job = backup.restore(
|
333
|
+
# "my-restored-database",
|
334
|
+
# encryption_config: encryption_config
|
335
|
+
# )
|
336
|
+
#
|
337
|
+
# job.done? #=> false
|
338
|
+
# job.reload! # API call
|
339
|
+
# job.done? #=> true
|
340
|
+
#
|
341
|
+
# if job.error?
|
342
|
+
# status = job.error
|
343
|
+
# else
|
344
|
+
# database = job.database
|
345
|
+
# end
|
346
|
+
#
|
347
|
+
def restore database_id, instance_id: nil, encryption_config: nil
|
284
348
|
ensure_service!
|
285
349
|
|
286
350
|
instance_id ||= self.instance_id
|
287
351
|
|
352
|
+
if encryption_config&.include?(:kms_key_name) &&
|
353
|
+
encryption_config[:encryption_type] != :CUSTOMER_MANAGED_ENCRYPTION
|
354
|
+
raise Google::Cloud::InvalidArgumentError,
|
355
|
+
"kms_key_name only used with CUSTOMER_MANAGED_ENCRYPTION"
|
356
|
+
end
|
357
|
+
|
288
358
|
grpc = service.restore_database \
|
289
359
|
self.instance_id,
|
290
360
|
backup_id,
|
291
361
|
instance_id,
|
292
|
-
database_id
|
362
|
+
database_id,
|
363
|
+
encryption_config: encryption_config
|
293
364
|
Restore::Job.from_grpc grpc, service
|
294
365
|
end
|
295
366
|
|
@@ -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,8 @@ 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
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
177
|
+
# use. Empty to use the database default.
|
176
178
|
# @param [Hash] call_options A hash of values to specify the custom
|
177
179
|
# call options, e.g., timeout, retries, etc. Call options are
|
178
180
|
# optional. The following settings can be provided:
|
@@ -373,9 +375,9 @@ module Google
|
|
373
375
|
|
374
376
|
opts = { call_options: call_options }
|
375
377
|
if partition.execute?
|
376
|
-
execute_partition_query partition, opts
|
378
|
+
execute_partition_query partition, **opts
|
377
379
|
elsif partition.read?
|
378
|
-
execute_partition_read partition, opts
|
380
|
+
execute_partition_read partition, **opts
|
379
381
|
end
|
380
382
|
end
|
381
383
|
|
@@ -473,6 +475,8 @@ module Google
|
|
473
475
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
474
476
|
# Empty to use database default. "latest" to use the latest
|
475
477
|
# available optimizer version.
|
478
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
479
|
+
# use. Empty to use the database default.
|
476
480
|
# @param [Hash] call_options A hash of values to specify the custom
|
477
481
|
# call options, e.g., timeout, retries, etc. Call options are
|
478
482
|
# optional. The following settings can be provided:
|
@@ -598,8 +602,11 @@ module Google
|
|
598
602
|
# batch_snapshot = batch_client.batch_snapshot
|
599
603
|
#
|
600
604
|
# results = batch_snapshot.execute_query \
|
601
|
-
#
|
602
|
-
#
|
605
|
+
# "SELECT * FROM users",
|
606
|
+
# query_options: {
|
607
|
+
# optimizer_version: "1",
|
608
|
+
# optimizer_statistics_package: "auto_20191128_14_47_22UTC"
|
609
|
+
# }
|
603
610
|
#
|
604
611
|
# results.rows.each do |row|
|
605
612
|
# puts "User #{row[:id]} is #{row[:name]}"
|
@@ -42,12 +42,10 @@ module Google
|
|
42
42
|
#
|
43
43
|
# db = spanner.client "my-instance", "my-database"
|
44
44
|
#
|
45
|
-
# db.
|
46
|
-
# results = tx.execute_query "SELECT * FROM users"
|
45
|
+
# results = db.execute_query "SELECT * FROM users"
|
47
46
|
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# end
|
47
|
+
# results.rows.each do |row|
|
48
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
51
49
|
# end
|
52
50
|
#
|
53
51
|
class Client
|
@@ -59,7 +57,7 @@ module Google
|
|
59
57
|
@instance_id = instance_id
|
60
58
|
@database_id = database_id
|
61
59
|
@session_labels = session_labels
|
62
|
-
@pool = Pool.new self, pool_opts
|
60
|
+
@pool = Pool.new self, **pool_opts
|
63
61
|
@query_options = query_options
|
64
62
|
end
|
65
63
|
|
@@ -129,6 +127,7 @@ module Google
|
|
129
127
|
# | `BOOL` | `true`/`false` | |
|
130
128
|
# | `INT64` | `Integer` | |
|
131
129
|
# | `FLOAT64` | `Float` | |
|
130
|
+
# | `NUMERIC` | `BigDecimal` | |
|
132
131
|
# | `STRING` | `String` | |
|
133
132
|
# | `DATE` | `Date` | |
|
134
133
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -154,6 +153,7 @@ module Google
|
|
154
153
|
# * `:BYTES`
|
155
154
|
# * `:DATE`
|
156
155
|
# * `:FLOAT64`
|
156
|
+
# * `:NUMERIC`
|
157
157
|
# * `:INT64`
|
158
158
|
# * `:STRING`
|
159
159
|
# * `:TIMESTAMP`
|
@@ -167,6 +167,9 @@ module Google
|
|
167
167
|
# @param [Hash] single_use Perform the read with a single-use snapshot
|
168
168
|
# (read-only transaction). (See
|
169
169
|
# [TransactionOptions](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#transactionoptions).)
|
170
|
+
# If no value is specified for this parameter, Cloud Spanner will use
|
171
|
+
# a single use read-only transaction with strong timestamp bound as
|
172
|
+
# default.
|
170
173
|
# The snapshot can be created by providing exactly one of the
|
171
174
|
# following options in the hash:
|
172
175
|
#
|
@@ -223,6 +226,16 @@ module Google
|
|
223
226
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
224
227
|
# Empty to use database default. "latest" to use the latest
|
225
228
|
# available optimizer version.
|
229
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
230
|
+
# use. Empty to use the database default.
|
231
|
+
# @param [Hash] request_options Common request options.
|
232
|
+
#
|
233
|
+
# * `:priority` (Symbol) The relative priority for requests.
|
234
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
235
|
+
# and does not guarantee priority or order of execution.
|
236
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
237
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
238
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
226
239
|
# @param [Hash] call_options A hash of values to specify the custom
|
227
240
|
# call options, e.g., timeout, retries, etc. Call options are
|
228
241
|
# optional. The following settings can be provided:
|
@@ -343,7 +356,10 @@ module Google
|
|
343
356
|
# db = spanner.client "my-instance", "my-database"
|
344
357
|
#
|
345
358
|
# results = db.execute_query \
|
346
|
-
# "SELECT * FROM users", query_options: {
|
359
|
+
# "SELECT * FROM users", query_options: {
|
360
|
+
# optimizer_version: "1",
|
361
|
+
# optimizer_statistics_package: "auto_20191128_14_47_22UTC"
|
362
|
+
# }
|
347
363
|
#
|
348
364
|
# results.rows.each do |row|
|
349
365
|
# puts "User #{row[:id]} is #{row[:name]}"
|
@@ -372,8 +388,24 @@ module Google
|
|
372
388
|
# puts "User #{row[:id]} is #{row[:name]}"
|
373
389
|
# end
|
374
390
|
#
|
391
|
+
# @example Using request options.
|
392
|
+
# require "google/cloud/spanner"
|
393
|
+
#
|
394
|
+
# spanner = Google::Cloud::Spanner.new
|
395
|
+
#
|
396
|
+
# db = spanner.client "my-instance", "my-database"
|
397
|
+
#
|
398
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
399
|
+
# results = db.execute_query "SELECT * FROM users",
|
400
|
+
# request_options: request_options
|
401
|
+
#
|
402
|
+
# results.rows.each do |row|
|
403
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
404
|
+
# end
|
405
|
+
#
|
375
406
|
def execute_query sql, params: nil, types: nil, single_use: nil,
|
376
|
-
query_options: nil,
|
407
|
+
query_options: nil, request_options: nil,
|
408
|
+
call_options: nil
|
377
409
|
validate_single_use_args! single_use
|
378
410
|
ensure_service!
|
379
411
|
|
@@ -384,7 +416,8 @@ module Google
|
|
384
416
|
@pool.with_session do |session|
|
385
417
|
results = session.execute_query \
|
386
418
|
sql, params: params, types: types, transaction: single_use_tx,
|
387
|
-
query_options: query_options,
|
419
|
+
query_options: query_options, request_options: request_options,
|
420
|
+
call_options: call_options
|
388
421
|
end
|
389
422
|
results
|
390
423
|
end
|
@@ -408,7 +441,7 @@ module Google
|
|
408
441
|
# once" semantics.
|
409
442
|
#
|
410
443
|
# Where DML statements must be executed using Transaction (see
|
411
|
-
# {Transaction#execute_update}),
|
444
|
+
# {Transaction#execute_update}), Partitioned DML statements are executed
|
412
445
|
# outside of a read/write transaction.
|
413
446
|
#
|
414
447
|
# Not all DML statements can be executed in the Partitioned DML mode and
|
@@ -494,6 +527,7 @@ module Google
|
|
494
527
|
# | `BOOL` | `true`/`false` | |
|
495
528
|
# | `INT64` | `Integer` | |
|
496
529
|
# | `FLOAT64` | `Float` | |
|
530
|
+
# | `NUMERIC` | `BigDecimal` | |
|
497
531
|
# | `STRING` | `String` | |
|
498
532
|
# | `DATE` | `Date` | |
|
499
533
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -520,6 +554,7 @@ module Google
|
|
520
554
|
# * `:BYTES`
|
521
555
|
# * `:DATE`
|
522
556
|
# * `:FLOAT64`
|
557
|
+
# * `:NUMERIC`
|
523
558
|
# * `:INT64`
|
524
559
|
# * `:STRING`
|
525
560
|
# * `:TIMESTAMP`
|
@@ -535,6 +570,16 @@ module Google
|
|
535
570
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
536
571
|
# Empty to use database default. "latest" to use the latest
|
537
572
|
# available optimizer version.
|
573
|
+
# * `:optimizer_statistics_package` (String) Statistics package to
|
574
|
+
# use. Empty to use the database default.
|
575
|
+
# @param [Hash] request_options Common request options.
|
576
|
+
#
|
577
|
+
# * `:priority` (String) The relative priority for requests.
|
578
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
579
|
+
# and does not guarantee priority or order of execution.
|
580
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
581
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
582
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
538
583
|
# @param [Hash] call_options A hash of values to specify the custom
|
539
584
|
# call options, e.g., timeout, retries, etc. Call options are
|
540
585
|
# optional. The following settings can be provided:
|
@@ -577,7 +622,10 @@ module Google
|
|
577
622
|
#
|
578
623
|
# row_count = db.execute_partition_update \
|
579
624
|
# "UPDATE users SET friends = NULL WHERE active = false",
|
580
|
-
# query_options: {
|
625
|
+
# query_options: {
|
626
|
+
# optimizer_version: "1",
|
627
|
+
# optimizer_statistics_package: "auto_20191128_14_47_22UTC"
|
628
|
+
# }
|
581
629
|
#
|
582
630
|
# @example Query using custom timeout and retry policy:
|
583
631
|
# require "google/cloud/spanner"
|
@@ -598,8 +646,20 @@ module Google
|
|
598
646
|
# "UPDATE users SET friends = NULL WHERE active = false",
|
599
647
|
# call_options: call_options
|
600
648
|
#
|
649
|
+
# @example Using request options.
|
650
|
+
# require "google/cloud/spanner"
|
651
|
+
#
|
652
|
+
# spanner = Google::Cloud::Spanner.new
|
653
|
+
# db = spanner.client "my-instance", "my-database"
|
654
|
+
#
|
655
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
656
|
+
# row_count = db.execute_partition_update \
|
657
|
+
# "UPDATE users SET friends = NULL WHERE active = @active",
|
658
|
+
# params: { active: false }, request_options: request_options
|
659
|
+
#
|
601
660
|
def execute_partition_update sql, params: nil, types: nil,
|
602
|
-
query_options: nil,
|
661
|
+
query_options: nil, request_options: nil,
|
662
|
+
call_options: nil
|
603
663
|
ensure_service!
|
604
664
|
|
605
665
|
params, types = Convert.to_input_params_and_types params, types
|
@@ -608,7 +668,8 @@ module Google
|
|
608
668
|
results = session.execute_query \
|
609
669
|
sql, params: params, types: types,
|
610
670
|
transaction: pdml_transaction(session),
|
611
|
-
query_options: query_options,
|
671
|
+
query_options: query_options, request_options: request_options,
|
672
|
+
call_options: call_options
|
612
673
|
end
|
613
674
|
# Stream all PartialResultSet to get ResultSetStats
|
614
675
|
results.rows.to_a
|
@@ -640,6 +701,9 @@ module Google
|
|
640
701
|
# @param [Hash] single_use Perform the read with a single-use snapshot
|
641
702
|
# (read-only transaction). (See
|
642
703
|
# [TransactionOptions](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#transactionoptions).)
|
704
|
+
# If no value is specified for this parameter, Cloud Spanner will use
|
705
|
+
# a single use read-only transaction with strong timestamp bound as
|
706
|
+
# default.
|
643
707
|
# The snapshot can be created by providing exactly one of the
|
644
708
|
# following options in the hash:
|
645
709
|
#
|
@@ -689,6 +753,14 @@ module Google
|
|
689
753
|
# Useful for reading the freshest data available at a nearby
|
690
754
|
# replica, while bounding the possible staleness if the local
|
691
755
|
# replica has fallen behind.
|
756
|
+
# @param [Hash] request_options Common request options.
|
757
|
+
#
|
758
|
+
# * `:priority` (Symbol) The relative priority for requests.
|
759
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
760
|
+
# and does not guarantee priority or order of execution.
|
761
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
762
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
763
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
692
764
|
# @param [Hash] call_options A hash of values to specify the custom
|
693
765
|
# call options, e.g., timeout, retries, etc. Call options are
|
694
766
|
# optional. The following settings can be provided:
|
@@ -753,8 +825,23 @@ module Google
|
|
753
825
|
# puts "User #{row[:id]} is #{row[:name]}"
|
754
826
|
# end
|
755
827
|
#
|
828
|
+
# @example Using request options.
|
829
|
+
# require "google/cloud/spanner"
|
830
|
+
#
|
831
|
+
# spanner = Google::Cloud::Spanner.new
|
832
|
+
#
|
833
|
+
# db = spanner.client "my-instance", "my-database"
|
834
|
+
#
|
835
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
836
|
+
# results = db.read "users", [:id, :name],
|
837
|
+
# request_options: request_options
|
838
|
+
#
|
839
|
+
# results.rows.each do |row|
|
840
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
841
|
+
# end
|
842
|
+
#
|
756
843
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
757
|
-
single_use: nil, call_options: nil
|
844
|
+
single_use: nil, request_options: nil, call_options: nil
|
758
845
|
validate_single_use_args! single_use
|
759
846
|
ensure_service!
|
760
847
|
|
@@ -767,6 +854,7 @@ module Google
|
|
767
854
|
results = session.read \
|
768
855
|
table, columns, keys: keys, index: index, limit: limit,
|
769
856
|
transaction: single_use_tx,
|
857
|
+
request_options: request_options,
|
770
858
|
call_options: call_options
|
771
859
|
end
|
772
860
|
results
|
@@ -801,6 +889,7 @@ module Google
|
|
801
889
|
# | `BOOL` | `true`/`false` | |
|
802
890
|
# | `INT64` | `Integer` | |
|
803
891
|
# | `FLOAT64` | `Float` | |
|
892
|
+
# | `NUMERIC` | `BigDecimal` | |
|
804
893
|
# | `STRING` | `String` | |
|
805
894
|
# | `DATE` | `Date` | |
|
806
895
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -817,6 +906,14 @@ module Google
|
|
817
906
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
818
907
|
# then statistics related to the transaction will be included in
|
819
908
|
# {CommitResponse}. Default value is `false`
|
909
|
+
# @param [Hash] request_options Common request options.
|
910
|
+
#
|
911
|
+
# * `:priority` (String) The relative priority for requests.
|
912
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
913
|
+
# and does not guarantee priority or order of execution.
|
914
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
915
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
916
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
820
917
|
#
|
821
918
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
822
919
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -846,9 +943,21 @@ module Google
|
|
846
943
|
# puts commit_resp.timestamp
|
847
944
|
# puts commit_resp.stats.mutation_count
|
848
945
|
#
|
849
|
-
|
946
|
+
# @example Using request options.
|
947
|
+
# require "google/cloud/spanner"
|
948
|
+
#
|
949
|
+
# spanner = Google::Cloud::Spanner.new
|
950
|
+
#
|
951
|
+
# db = spanner.client "my-instance", "my-database"
|
952
|
+
#
|
953
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
954
|
+
# db.upsert "users", [{ id: 1, name: "Charlie", active: false }],
|
955
|
+
# request_options: request_options
|
956
|
+
#
|
957
|
+
def upsert table, rows, commit_options: nil, request_options: nil
|
850
958
|
@pool.with_session do |session|
|
851
|
-
session.upsert table, rows, commit_options: commit_options
|
959
|
+
session.upsert table, rows, commit_options: commit_options,
|
960
|
+
request_options: request_options
|
852
961
|
end
|
853
962
|
end
|
854
963
|
alias save upsert
|
@@ -881,6 +990,7 @@ module Google
|
|
881
990
|
# | `BOOL` | `true`/`false` | |
|
882
991
|
# | `INT64` | `Integer` | |
|
883
992
|
# | `FLOAT64` | `Float` | |
|
993
|
+
# | `NUMERIC` | `BigDecimal` | |
|
884
994
|
# | `STRING` | `String` | |
|
885
995
|
# | `DATE` | `Date` | |
|
886
996
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -897,6 +1007,14 @@ module Google
|
|
897
1007
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
898
1008
|
# then statistics related to the transaction will be included in
|
899
1009
|
# {CommitResponse}. Default value is `false`
|
1010
|
+
# @param [Hash] request_options Common request options.
|
1011
|
+
#
|
1012
|
+
# * `:priority` (String) The relative priority for requests.
|
1013
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1014
|
+
# and does not guarantee priority or order of execution.
|
1015
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1016
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1017
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
900
1018
|
#
|
901
1019
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
902
1020
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -926,9 +1044,21 @@ module Google
|
|
926
1044
|
# puts commit_resp.timestamp
|
927
1045
|
# puts commit_resp.stats.mutation_count
|
928
1046
|
#
|
929
|
-
|
1047
|
+
# @example Using request options.
|
1048
|
+
# require "google/cloud/spanner"
|
1049
|
+
#
|
1050
|
+
# spanner = Google::Cloud::Spanner.new
|
1051
|
+
#
|
1052
|
+
# db = spanner.client "my-instance", "my-database"
|
1053
|
+
#
|
1054
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
1055
|
+
# db.insert "users", [{ id: 1, name: "Charlie", active: false }],
|
1056
|
+
# request_options: request_options
|
1057
|
+
#
|
1058
|
+
def insert table, rows, commit_options: nil, request_options: nil
|
930
1059
|
@pool.with_session do |session|
|
931
|
-
session.insert table, rows, commit_options: commit_options
|
1060
|
+
session.insert table, rows, commit_options: commit_options,
|
1061
|
+
request_options: request_options
|
932
1062
|
end
|
933
1063
|
end
|
934
1064
|
|
@@ -960,6 +1090,7 @@ module Google
|
|
960
1090
|
# | `BOOL` | `true`/`false` | |
|
961
1091
|
# | `INT64` | `Integer` | |
|
962
1092
|
# | `FLOAT64` | `Float` | |
|
1093
|
+
# | `NUMERIC` | `BigDecimal` | |
|
963
1094
|
# | `STRING` | `String` | |
|
964
1095
|
# | `DATE` | `Date` | |
|
965
1096
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -976,6 +1107,14 @@ module Google
|
|
976
1107
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
977
1108
|
# then statistics related to the transaction will be included in
|
978
1109
|
# {CommitResponse}. Default value is `false`
|
1110
|
+
# @param [Hash] request_options Common request options.
|
1111
|
+
#
|
1112
|
+
# * `:priority` (String) The relative priority for requests.
|
1113
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1114
|
+
# and does not guarantee priority or order of execution.
|
1115
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1116
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1117
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
979
1118
|
#
|
980
1119
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
981
1120
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1005,9 +1144,21 @@ module Google
|
|
1005
1144
|
# puts commit_resp.timestamp
|
1006
1145
|
# puts commit_resp.stats.mutation_count
|
1007
1146
|
#
|
1008
|
-
|
1147
|
+
# @example Using request options.
|
1148
|
+
# require "google/cloud/spanner"
|
1149
|
+
#
|
1150
|
+
# spanner = Google::Cloud::Spanner.new
|
1151
|
+
#
|
1152
|
+
# db = spanner.client "my-instance", "my-database"
|
1153
|
+
#
|
1154
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
1155
|
+
# db.update "users", [{ id: 1, name: "Charlie", active: false }],
|
1156
|
+
# request_options: request_options
|
1157
|
+
#
|
1158
|
+
def update table, rows, commit_options: nil, request_options: nil
|
1009
1159
|
@pool.with_session do |session|
|
1010
|
-
session.update table, rows, commit_options: commit_options
|
1160
|
+
session.update table, rows, commit_options: commit_options,
|
1161
|
+
request_options: request_options
|
1011
1162
|
end
|
1012
1163
|
end
|
1013
1164
|
|
@@ -1041,6 +1192,7 @@ module Google
|
|
1041
1192
|
# | `BOOL` | `true`/`false` | |
|
1042
1193
|
# | `INT64` | `Integer` | |
|
1043
1194
|
# | `FLOAT64` | `Float` | |
|
1195
|
+
# | `NUMERIC` | `BigDecimal` | |
|
1044
1196
|
# | `STRING` | `String` | |
|
1045
1197
|
# | `DATE` | `Date` | |
|
1046
1198
|
# | `TIMESTAMP` | `Time`, `DateTime` | |
|
@@ -1057,6 +1209,14 @@ module Google
|
|
1057
1209
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1058
1210
|
# then statistics related to the transaction will be included in
|
1059
1211
|
# {CommitResponse}. Default value is `false`
|
1212
|
+
# @param [Hash] request_options Common request options.
|
1213
|
+
#
|
1214
|
+
# * `:priority` (String) The relative priority for requests.
|
1215
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1216
|
+
# and does not guarantee priority or order of execution.
|
1217
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1218
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1219
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1060
1220
|
#
|
1061
1221
|
# @return [Time, CommitResponse] The timestamp at which the operation
|
1062
1222
|
# committed. If commit options are set it returns {CommitResponse}.
|
@@ -1086,9 +1246,21 @@ module Google
|
|
1086
1246
|
# puts commit_resp.timestamp
|
1087
1247
|
# puts commit_resp.stats.mutation_count
|
1088
1248
|
#
|
1089
|
-
|
1249
|
+
# @example Using request options.
|
1250
|
+
# require "google/cloud/spanner"
|
1251
|
+
#
|
1252
|
+
# spanner = Google::Cloud::Spanner.new
|
1253
|
+
#
|
1254
|
+
# db = spanner.client "my-instance", "my-database"
|
1255
|
+
#
|
1256
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
1257
|
+
# db.replace "users", [{ id: 1, name: "Charlie", active: false }],
|
1258
|
+
# request_options: request_options
|
1259
|
+
#
|
1260
|
+
def replace table, rows, commit_options: nil, request_options: nil
|
1090
1261
|
@pool.with_session do |session|
|
1091
|
-
session.replace table, rows, commit_options: commit_options
|
1262
|
+
session.replace table, rows, commit_options: commit_options,
|
1263
|
+
request_options: request_options
|
1092
1264
|
end
|
1093
1265
|
end
|
1094
1266
|
|
@@ -1119,7 +1291,14 @@ module Google
|
|
1119
1291
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1120
1292
|
# then statistics related to the transaction will be included in
|
1121
1293
|
# {CommitResponse}. Default value is `false`
|
1122
|
-
#
|
1294
|
+
# @param [Hash] request_options Common request options.
|
1295
|
+
#
|
1296
|
+
# * `:priority` (String) The relative priority for requests.
|
1297
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1298
|
+
# and does not guarantee priority or order of execution.
|
1299
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1300
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1301
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1123
1302
|
# @param [Hash] call_options A hash of values to specify the custom
|
1124
1303
|
# call options, e.g., timeout, retries, etc. Call options are
|
1125
1304
|
# optional. The following settings can be provided:
|
@@ -1159,9 +1338,21 @@ module Google
|
|
1159
1338
|
# puts commit_resp.timestamp
|
1160
1339
|
# puts commit_resp.stats.mutation_count
|
1161
1340
|
#
|
1162
|
-
|
1341
|
+
# @example With request optinos
|
1342
|
+
# require "google/cloud/spanner"
|
1343
|
+
#
|
1344
|
+
# spanner = Google::Cloud::Spanner.new
|
1345
|
+
#
|
1346
|
+
# db = spanner.client "my-instance", "my-database"
|
1347
|
+
#
|
1348
|
+
# request_options = { priority: :PRIORITY_MEDIUM }
|
1349
|
+
# db.delete "users", [1, 2, 3], request_options: request_options
|
1350
|
+
#
|
1351
|
+
def delete table, keys = [], commit_options: nil, request_options: nil,
|
1352
|
+
call_options: nil
|
1163
1353
|
@pool.with_session do |session|
|
1164
1354
|
session.delete table, keys, commit_options: commit_options,
|
1355
|
+
request_options: request_options,
|
1165
1356
|
call_options: call_options
|
1166
1357
|
end
|
1167
1358
|
end
|
@@ -1188,7 +1379,14 @@ module Google
|
|
1188
1379
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1189
1380
|
# then statistics related to the transaction will be included in
|
1190
1381
|
# {CommitResponse}. Default value is `false`
|
1191
|
-
#
|
1382
|
+
# @param [Hash] request_options Common request options.
|
1383
|
+
#
|
1384
|
+
# * `:priority` (String) The relative priority for requests.
|
1385
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1386
|
+
# and does not guarantee priority or order of execution.
|
1387
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1388
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1389
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1192
1390
|
# @param [Hash] call_options A hash of values to specify the custom
|
1193
1391
|
# call options, e.g., timeout, retries, etc. Call options are
|
1194
1392
|
# optional. The following settings can be provided:
|
@@ -1237,19 +1435,33 @@ module Google
|
|
1237
1435
|
# puts commit_resp.timestamp
|
1238
1436
|
# puts commit_resp.stats.mutation_count
|
1239
1437
|
#
|
1240
|
-
|
1438
|
+
# @example With request options
|
1439
|
+
# require "google/cloud/spanner"
|
1440
|
+
#
|
1441
|
+
# spanner = Google::Cloud::Spanner.new
|
1442
|
+
#
|
1443
|
+
# db = spanner.client "my-instance", "my-database"
|
1444
|
+
#
|
1445
|
+
# db.commit request_options: { priority: :PRIORITY_MEDIUM } do |c|
|
1446
|
+
# c.update "users", [{ id: 1, name: "Charlie", active: false }]
|
1447
|
+
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1448
|
+
# end
|
1449
|
+
#
|
1450
|
+
def commit commit_options: nil, request_options: nil,
|
1451
|
+
call_options: nil, &block
|
1241
1452
|
raise ArgumentError, "Must provide a block" unless block_given?
|
1242
1453
|
|
1243
1454
|
@pool.with_session do |session|
|
1244
1455
|
session.commit(
|
1245
|
-
commit_options: commit_options,
|
1456
|
+
commit_options: commit_options, request_options: request_options,
|
1457
|
+
call_options: call_options, &block
|
1246
1458
|
)
|
1247
1459
|
end
|
1248
1460
|
end
|
1249
1461
|
|
1250
1462
|
# rubocop:disable Metrics/AbcSize
|
1251
|
-
# rubocop:disable Metrics/BlockLength
|
1252
1463
|
# rubocop:disable Metrics/MethodLength
|
1464
|
+
# rubocop:disable Metrics/BlockLength
|
1253
1465
|
|
1254
1466
|
##
|
1255
1467
|
# Creates a transaction for reads and writes that execute atomically at
|
@@ -1274,7 +1486,14 @@ module Google
|
|
1274
1486
|
# * `:return_commit_stats` (Boolean) A boolean value. If `true`,
|
1275
1487
|
# then statistics related to the transaction will be included in
|
1276
1488
|
# {CommitResponse}. Default value is `false`
|
1277
|
-
#
|
1489
|
+
# @param [Hash] request_options Common request options.
|
1490
|
+
#
|
1491
|
+
# * `:priority` (String) The relative priority for requests.
|
1492
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
1493
|
+
# and does not guarantee priority or order of execution.
|
1494
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
1495
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
1496
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
1278
1497
|
# @param [Hash] call_options A hash of values to specify the custom
|
1279
1498
|
# call options, e.g., timeout, retries, etc. Call options are
|
1280
1499
|
# optional. The following settings can be provided:
|
@@ -1351,7 +1570,23 @@ module Google
|
|
1351
1570
|
# puts commit_resp.timestamp
|
1352
1571
|
# puts commit_resp.stats.mutation_count
|
1353
1572
|
#
|
1354
|
-
|
1573
|
+
# @example Using request options.
|
1574
|
+
# require "google/cloud/spanner"
|
1575
|
+
#
|
1576
|
+
# spanner = Google::Cloud::Spanner.new
|
1577
|
+
# db = spanner.client "my-instance", "my-database"
|
1578
|
+
#
|
1579
|
+
# db.transaction request_options: { priority: :PRIORITY_MEDIUM } do |tx|
|
1580
|
+
# tx.update "users", [{ id: 1, name: "Charlie", active: false }]
|
1581
|
+
# tx.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
1582
|
+
#
|
1583
|
+
# request_options = { priority: :PRIORITY_LOW }
|
1584
|
+
# results = tx.execute_query "SELECT * FROM users",
|
1585
|
+
# request_options: request_options
|
1586
|
+
# end
|
1587
|
+
#
|
1588
|
+
def transaction deadline: 120, commit_options: nil,
|
1589
|
+
request_options: nil, call_options: nil
|
1355
1590
|
ensure_service!
|
1356
1591
|
unless Thread.current[:transaction_id].nil?
|
1357
1592
|
raise "Nested transactions are not allowed"
|
@@ -1362,45 +1597,44 @@ module Google
|
|
1362
1597
|
start_time = current_time
|
1363
1598
|
|
1364
1599
|
@pool.with_transaction do |tx|
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
end
|
1381
|
-
raise err
|
1600
|
+
Thread.current[:transaction_id] = tx.transaction_id
|
1601
|
+
yield tx
|
1602
|
+
commit_resp = @project.service.commit \
|
1603
|
+
tx.session.path, tx.mutations,
|
1604
|
+
transaction_id: tx.transaction_id,
|
1605
|
+
commit_options: commit_options,
|
1606
|
+
request_options: request_options,
|
1607
|
+
call_options: call_options
|
1608
|
+
resp = CommitResponse.from_grpc commit_resp
|
1609
|
+
commit_options ? resp : resp.timestamp
|
1610
|
+
rescue GRPC::Aborted, Google::Cloud::AbortedError => e
|
1611
|
+
# Re-raise if deadline has passed
|
1612
|
+
if current_time - start_time > deadline
|
1613
|
+
if e.is_a? GRPC::BadStatus
|
1614
|
+
e = Google::Cloud::Error.from_error e
|
1382
1615
|
end
|
1383
|
-
|
1384
|
-
sleep(delay_from_aborted(err) || backoff *= 1.3)
|
1385
|
-
# Create new transaction on the session and retry the block
|
1386
|
-
tx = tx.session.create_transaction
|
1387
|
-
retry
|
1388
|
-
rescue StandardError => err
|
1389
|
-
# Rollback transaction when handling unexpected error
|
1390
|
-
tx.session.rollback tx.transaction_id
|
1391
|
-
# Return nil if raised with rollback.
|
1392
|
-
return nil if err.is_a? Rollback
|
1393
|
-
# Re-raise error.
|
1394
|
-
raise err
|
1395
|
-
ensure
|
1396
|
-
Thread.current[:transaction_id] = nil
|
1616
|
+
raise e
|
1397
1617
|
end
|
1618
|
+
# Sleep the amount from RetryDelay, or incremental backoff
|
1619
|
+
sleep(delay_from_aborted(e) || backoff *= 1.3)
|
1620
|
+
# Create new transaction on the session and retry the block
|
1621
|
+
tx = tx.session.create_transaction
|
1622
|
+
retry
|
1623
|
+
rescue StandardError => e
|
1624
|
+
# Rollback transaction when handling unexpected error
|
1625
|
+
tx.session.rollback tx.transaction_id
|
1626
|
+
# Return nil if raised with rollback.
|
1627
|
+
return nil if e.is_a? Rollback
|
1628
|
+
# Re-raise error.
|
1629
|
+
raise e
|
1630
|
+
ensure
|
1631
|
+
Thread.current[:transaction_id] = nil
|
1398
1632
|
end
|
1399
1633
|
end
|
1400
1634
|
|
1401
1635
|
# rubocop:enable Metrics/AbcSize
|
1402
|
-
# rubocop:enable Metrics/BlockLength
|
1403
1636
|
# rubocop:enable Metrics/MethodLength
|
1637
|
+
# rubocop:enable Metrics/BlockLength
|
1404
1638
|
|
1405
1639
|
##
|
1406
1640
|
# Creates a snapshot read-only transaction for reads that execute
|
@@ -1481,18 +1715,16 @@ module Google
|
|
1481
1715
|
end
|
1482
1716
|
|
1483
1717
|
@pool.with_session do |session|
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
Thread.current[:transaction_id] = nil
|
1495
|
-
end
|
1718
|
+
snp_grpc = @project.service.create_snapshot \
|
1719
|
+
session.path, strong: strong,
|
1720
|
+
timestamp: (timestamp || read_timestamp),
|
1721
|
+
staleness: (staleness || exact_staleness),
|
1722
|
+
call_options: call_options
|
1723
|
+
Thread.current[:transaction_id] = snp_grpc.id
|
1724
|
+
snp = Snapshot.from_grpc snp_grpc, session
|
1725
|
+
yield snp if block_given?
|
1726
|
+
ensure
|
1727
|
+
Thread.current[:transaction_id] = nil
|
1496
1728
|
end
|
1497
1729
|
nil
|
1498
1730
|
end
|
@@ -1514,12 +1746,13 @@ module Google
|
|
1514
1746
|
# Hash values must contain the type value. If a Hash is used the
|
1515
1747
|
# fields will be created using the same order as the Hash keys.
|
1516
1748
|
#
|
1517
|
-
# Supported type values
|
1749
|
+
# Supported type values include:
|
1518
1750
|
#
|
1519
1751
|
# * `:BOOL`
|
1520
1752
|
# * `:BYTES`
|
1521
1753
|
# * `:DATE`
|
1522
1754
|
# * `:FLOAT64`
|
1755
|
+
# * `:NUMERIC`
|
1523
1756
|
# * `:INT64`
|
1524
1757
|
# * `:STRING`
|
1525
1758
|
# * `:TIMESTAMP`
|
@@ -1691,7 +1924,7 @@ module Google
|
|
1691
1924
|
def batch_create_new_sessions total
|
1692
1925
|
sessions = []
|
1693
1926
|
remaining = total
|
1694
|
-
while remaining
|
1927
|
+
while remaining.positive?
|
1695
1928
|
sessions += batch_create_sessions remaining
|
1696
1929
|
remaining = total - sessions.count
|
1697
1930
|
end
|
@@ -1795,7 +2028,7 @@ module Google
|
|
1795
2028
|
|
1796
2029
|
def validate_deadline deadline
|
1797
2030
|
return 120 unless deadline.is_a? Numeric
|
1798
|
-
return 120 if deadline
|
2031
|
+
return 120 if deadline.negative?
|
1799
2032
|
deadline
|
1800
2033
|
end
|
1801
2034
|
|
@@ -1810,13 +2043,12 @@ module Google
|
|
1810
2043
|
# GRPC::Aborted
|
1811
2044
|
def delay_from_aborted err
|
1812
2045
|
return nil if err.nil?
|
1813
|
-
if err.respond_to?(:metadata) && err.metadata["
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
nanos = err.metadata["retryDelay"]["nanos"].to_i
|
2046
|
+
if err.respond_to?(:metadata) && err.metadata["google.rpc.retryinfo-bin"]
|
2047
|
+
retry_info = Google::Rpc::RetryInfo.decode err.metadata["google.rpc.retryinfo-bin"]
|
2048
|
+
seconds = retry_info["retry_delay"].seconds
|
2049
|
+
nanos = retry_info["retry_delay"].nanos
|
1818
2050
|
return seconds if nanos.zero?
|
1819
|
-
return seconds + (nanos /
|
2051
|
+
return seconds + (nanos / 1_000_000_000.0)
|
1820
2052
|
end
|
1821
2053
|
# No metadata? Try the inner error
|
1822
2054
|
delay_from_aborted err.cause
|