google-cloud-spanner 2.0.0 → 2.1.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 +6 -0
- data/lib/google/cloud/spanner/batch_snapshot.rb +114 -15
- data/lib/google/cloud/spanner/client.rb +181 -22
- data/lib/google/cloud/spanner/results.rb +9 -6
- data/lib/google/cloud/spanner/service.rb +205 -104
- data/lib/google/cloud/spanner/session.rb +177 -22
- data/lib/google/cloud/spanner/snapshot.rb +58 -4
- data/lib/google/cloud/spanner/transaction.rb +114 -8
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7eb1575c3244eb459d8379345e2dea6f19c925bbeb526ff969aa07a34428c94
|
4
|
+
data.tar.gz: 9c8c0b2d99074ec99ff38125ccbf89713f0d7c5441445650b96b5a969b09629a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba900cc5a539d55baead3d8825472b05b40ab19adc3062dfb93c7cf1713805b9619c2cbd7b115f3e2e61f79371e4c53eb8a225f8cd1f7a3dc1c30f72e1590cc7
|
7
|
+
data.tar.gz: 1639fd79b6bd30af238b2d002852bec94e4f29aa581594758169180e15e6b335f86c5a6cac1fa9a13a7fef02edc105ea46eb4867a02c59bf0a069c142d8799e2
|
data/CHANGELOG.md
CHANGED
@@ -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
|
@@ -222,6 +222,19 @@ module Google
|
|
222
222
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
223
223
|
# Empty to use database default. "latest" to use the latest
|
224
224
|
# available optimizer version.
|
225
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
226
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
227
|
+
# optional. The following settings can be provided:
|
228
|
+
#
|
229
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
230
|
+
# that overrides the default setting.
|
231
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
232
|
+
# setting of retry policy with the following keys:
|
233
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
234
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
235
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
236
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
237
|
+
# trigger a retry.
|
225
238
|
#
|
226
239
|
# @return [Google::Cloud::Spanner::Results] The results of the query
|
227
240
|
# execution.
|
@@ -335,8 +348,31 @@ module Google
|
|
335
348
|
# puts "User #{row[:id]} is #{row[:name]}"
|
336
349
|
# end
|
337
350
|
#
|
351
|
+
# @example Query using custom timeout and retry policy:
|
352
|
+
# require "google/cloud/spanner"
|
353
|
+
#
|
354
|
+
# spanner = Google::Cloud::Spanner.new
|
355
|
+
#
|
356
|
+
# db = spanner.client "my-instance", "my-database"
|
357
|
+
#
|
358
|
+
# timeout = 30.0
|
359
|
+
# retry_policy = {
|
360
|
+
# initial_delay: 0.25,
|
361
|
+
# max_delay: 32.0,
|
362
|
+
# multiplier: 1.3,
|
363
|
+
# retry_codes: ["UNAVAILABLE"]
|
364
|
+
# }
|
365
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
366
|
+
#
|
367
|
+
# results = db.execute_query \
|
368
|
+
# "SELECT * FROM users", call_options: call_options
|
369
|
+
#
|
370
|
+
# results.rows.each do |row|
|
371
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
372
|
+
# end
|
373
|
+
#
|
338
374
|
def execute_query sql, params: nil, types: nil, single_use: nil,
|
339
|
-
query_options: nil
|
375
|
+
query_options: nil, call_options: nil
|
340
376
|
validate_single_use_args! single_use
|
341
377
|
ensure_service!
|
342
378
|
|
@@ -347,7 +383,7 @@ module Google
|
|
347
383
|
@pool.with_session do |session|
|
348
384
|
results = session.execute_query \
|
349
385
|
sql, params: params, types: types, transaction: single_use_tx,
|
350
|
-
query_options: query_options
|
386
|
+
query_options: query_options, call_options: call_options
|
351
387
|
end
|
352
388
|
results
|
353
389
|
end
|
@@ -474,14 +510,6 @@ module Google
|
|
474
510
|
# value in `params`. In these cases, the `types` hash can be used to
|
475
511
|
# specify the exact SQL type for some or all of the SQL query
|
476
512
|
# parameters.
|
477
|
-
# @param [Hash] query_options A hash of values to specify the custom
|
478
|
-
# query options for executing SQL query. Query options are optional.
|
479
|
-
# The following settings can be provided:
|
480
|
-
#
|
481
|
-
# * `:optimizer_version` (String) The version of optimizer to use.
|
482
|
-
# Empty to use database default. "latest" to use the latest
|
483
|
-
# available optimizer version.
|
484
|
-
#
|
485
513
|
#
|
486
514
|
# The keys of the hash should be query string parameter placeholders,
|
487
515
|
# minus the "@". The values of the hash should be Cloud Spanner type
|
@@ -499,6 +527,26 @@ module Google
|
|
499
527
|
# `[:INT64]`.
|
500
528
|
# * {Fields} - Nested Structs are specified by providing a Fields
|
501
529
|
# object.
|
530
|
+
# @param [Hash] query_options A hash of values to specify the custom
|
531
|
+
# query options for executing SQL query. Query options are optional.
|
532
|
+
# The following settings can be provided:
|
533
|
+
#
|
534
|
+
# * `:optimizer_version` (String) The version of optimizer to use.
|
535
|
+
# Empty to use database default. "latest" to use the latest
|
536
|
+
# available optimizer version.
|
537
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
538
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
539
|
+
# optional. The following settings can be provided:
|
540
|
+
#
|
541
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
542
|
+
# that overrides the default setting.
|
543
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
544
|
+
# setting of retry policy with the following keys:
|
545
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
546
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
547
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
548
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
549
|
+
# trigger a retry.
|
502
550
|
# @return [Integer] The lower bound number of rows that were modified.
|
503
551
|
#
|
504
552
|
# @example
|
@@ -529,8 +577,28 @@ module Google
|
|
529
577
|
# row_count = db.execute_partition_update \
|
530
578
|
# "UPDATE users SET friends = NULL WHERE active = false",
|
531
579
|
# query_options: { optimizer_version: "1" }
|
580
|
+
#
|
581
|
+
# @example Query using custom timeout and retry policy:
|
582
|
+
# require "google/cloud/spanner"
|
583
|
+
#
|
584
|
+
# spanner = Google::Cloud::Spanner.new
|
585
|
+
# db = spanner.client "my-instance", "my-database"
|
586
|
+
#
|
587
|
+
# timeout = 30.0
|
588
|
+
# retry_policy = {
|
589
|
+
# initial_delay: 0.25,
|
590
|
+
# max_delay: 32.0,
|
591
|
+
# multiplier: 1.3,
|
592
|
+
# retry_codes: ["UNAVAILABLE"]
|
593
|
+
# }
|
594
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
595
|
+
#
|
596
|
+
# row_count = db.execute_partition_update \
|
597
|
+
# "UPDATE users SET friends = NULL WHERE active = false",
|
598
|
+
# call_options: call_options
|
599
|
+
#
|
532
600
|
def execute_partition_update sql, params: nil, types: nil,
|
533
|
-
query_options: nil
|
601
|
+
query_options: nil, call_options: nil
|
534
602
|
ensure_service!
|
535
603
|
|
536
604
|
params, types = Convert.to_input_params_and_types params, types
|
@@ -539,7 +607,7 @@ module Google
|
|
539
607
|
results = session.execute_query \
|
540
608
|
sql, params: params, types: types,
|
541
609
|
transaction: pdml_transaction(session),
|
542
|
-
query_options: query_options
|
610
|
+
query_options: query_options, call_options: call_options
|
543
611
|
end
|
544
612
|
# Stream all PartialResultSet to get ResultSetStats
|
545
613
|
results.rows.to_a
|
@@ -620,6 +688,19 @@ module Google
|
|
620
688
|
# Useful for reading the freshest data available at a nearby
|
621
689
|
# replica, while bounding the possible staleness if the local
|
622
690
|
# replica has fallen behind.
|
691
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
692
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
693
|
+
# optional. The following settings can be provided:
|
694
|
+
#
|
695
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
696
|
+
# that overrides the default setting.
|
697
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
698
|
+
# setting of retry policy with the following keys:
|
699
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
700
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
701
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
702
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
703
|
+
# trigger a retry.
|
623
704
|
#
|
624
705
|
# @return [Google::Cloud::Spanner::Results] The results of the read.
|
625
706
|
#
|
@@ -649,8 +730,30 @@ module Google
|
|
649
730
|
# puts "User #{row[:id]} is #{row[:name]}"
|
650
731
|
# end
|
651
732
|
#
|
733
|
+
# @example Read using custom timeout and retry.
|
734
|
+
# require "google/cloud/spanner"
|
735
|
+
#
|
736
|
+
# spanner = Google::Cloud::Spanner.new
|
737
|
+
#
|
738
|
+
# db = spanner.client "my-instance", "my-database"
|
739
|
+
#
|
740
|
+
# timeout = 30.0
|
741
|
+
# retry_policy = {
|
742
|
+
# initial_delay: 0.25,
|
743
|
+
# max_delay: 32.0,
|
744
|
+
# multiplier: 1.3,
|
745
|
+
# retry_codes: ["UNAVAILABLE"]
|
746
|
+
# }
|
747
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
748
|
+
#
|
749
|
+
# results = db.read "users", [:id, :name], call_options: call_options
|
750
|
+
#
|
751
|
+
# results.rows.each do |row|
|
752
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
753
|
+
# end
|
754
|
+
#
|
652
755
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
653
|
-
single_use: nil
|
756
|
+
single_use: nil, call_options: nil
|
654
757
|
validate_single_use_args! single_use
|
655
758
|
ensure_service!
|
656
759
|
|
@@ -662,7 +765,8 @@ module Google
|
|
662
765
|
@pool.with_session do |session|
|
663
766
|
results = session.read \
|
664
767
|
table, columns, keys: keys, index: index, limit: limit,
|
665
|
-
transaction: single_use_tx
|
768
|
+
transaction: single_use_tx,
|
769
|
+
call_options: call_options
|
666
770
|
end
|
667
771
|
results
|
668
772
|
end
|
@@ -911,6 +1015,19 @@ module Google
|
|
911
1015
|
# @param [Object, Array<Object>] keys A single, or list of keys or key
|
912
1016
|
# ranges to match returned data to. Values should have exactly as many
|
913
1017
|
# elements as there are columns in the primary key.
|
1018
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1019
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1020
|
+
# optional. The following settings can be provided:
|
1021
|
+
#
|
1022
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1023
|
+
# that overrides the default setting.
|
1024
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1025
|
+
# setting of retry policy with the following keys:
|
1026
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1027
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1028
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1029
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1030
|
+
# trigger a retry.
|
914
1031
|
#
|
915
1032
|
# @return [Time] The timestamp at which the operation committed.
|
916
1033
|
#
|
@@ -923,9 +1040,9 @@ module Google
|
|
923
1040
|
#
|
924
1041
|
# db.delete "users", [1, 2, 3]
|
925
1042
|
#
|
926
|
-
def delete table, keys = []
|
1043
|
+
def delete table, keys = [], call_options: nil
|
927
1044
|
@pool.with_session do |session|
|
928
|
-
session.delete table, keys
|
1045
|
+
session.delete table, keys, call_options: call_options
|
929
1046
|
end
|
930
1047
|
end
|
931
1048
|
|
@@ -944,6 +1061,20 @@ module Google
|
|
944
1061
|
# this method may be appropriate for latency sensitive and/or high
|
945
1062
|
# throughput blind changes.
|
946
1063
|
#
|
1064
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1065
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1066
|
+
# optional. The following settings can be provided:
|
1067
|
+
#
|
1068
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1069
|
+
# that overrides the default setting.
|
1070
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1071
|
+
# setting of retry policy with the following keys:
|
1072
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1073
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1074
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1075
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1076
|
+
# trigger a retry.
|
1077
|
+
#
|
947
1078
|
# @yield [commit] The block for mutating the data.
|
948
1079
|
# @yieldparam [Google::Cloud::Spanner::Commit] commit The Commit object.
|
949
1080
|
#
|
@@ -961,11 +1092,11 @@ module Google
|
|
961
1092
|
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
962
1093
|
# end
|
963
1094
|
#
|
964
|
-
def commit &block
|
1095
|
+
def commit call_options: nil, &block
|
965
1096
|
raise ArgumentError, "Must provide a block" unless block_given?
|
966
1097
|
|
967
1098
|
@pool.with_session do |session|
|
968
|
-
session.commit(&block)
|
1099
|
+
session.commit(call_options: call_options, &block)
|
969
1100
|
end
|
970
1101
|
end
|
971
1102
|
|
@@ -988,6 +1119,19 @@ module Google
|
|
988
1119
|
#
|
989
1120
|
# @param [Numeric] deadline The total amount of time in seconds the
|
990
1121
|
# transaction has to succeed. The default is `120`.
|
1122
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1123
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1124
|
+
# optional. The following settings can be provided:
|
1125
|
+
#
|
1126
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1127
|
+
# that overrides the default setting.
|
1128
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1129
|
+
# setting of retry policy with the following keys:
|
1130
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1131
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1132
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1133
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1134
|
+
# trigger a retry.
|
991
1135
|
#
|
992
1136
|
# @yield [transaction] The block for reading and writing data.
|
993
1137
|
# @yieldparam [Google::Cloud::Spanner::Transaction] transaction The
|
@@ -1029,7 +1173,7 @@ module Google
|
|
1029
1173
|
# end
|
1030
1174
|
# end
|
1031
1175
|
#
|
1032
|
-
def transaction deadline: 120
|
1176
|
+
def transaction deadline: 120, call_options: nil
|
1033
1177
|
ensure_service!
|
1034
1178
|
unless Thread.current[:transaction_id].nil?
|
1035
1179
|
raise "Nested transactions are not allowed"
|
@@ -1044,7 +1188,8 @@ module Google
|
|
1044
1188
|
Thread.current[:transaction_id] = tx.transaction_id
|
1045
1189
|
yield tx
|
1046
1190
|
commit_resp = @project.service.commit \
|
1047
|
-
tx.session.path, tx.mutations,
|
1191
|
+
tx.session.path, tx.mutations,
|
1192
|
+
transaction_id: tx.transaction_id, call_options: call_options
|
1048
1193
|
return Convert.timestamp_to_time commit_resp.commit_timestamp
|
1049
1194
|
rescue GRPC::Aborted, Google::Cloud::AbortedError => err
|
1050
1195
|
# Re-raise if deadline has passed
|
@@ -1109,6 +1254,19 @@ module Google
|
|
1109
1254
|
# timestamp negotiation overhead of single-use `staleness`. (See
|
1110
1255
|
# [TransactionOptions](https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1#transactionoptions).)
|
1111
1256
|
# @param [Numeric] exact_staleness Same as `staleness`.
|
1257
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
1258
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
1259
|
+
# optional. The following settings can be provided:
|
1260
|
+
#
|
1261
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
1262
|
+
# that overrides the default setting.
|
1263
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
1264
|
+
# setting of retry policy with the following keys:
|
1265
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
1266
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
1267
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
1268
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
1269
|
+
# trigger a retry.
|
1112
1270
|
#
|
1113
1271
|
# @yield [snapshot] The block for reading and writing data.
|
1114
1272
|
# @yieldparam [Google::Cloud::Spanner::Snapshot] snapshot The Snapshot
|
@@ -1129,7 +1287,7 @@ module Google
|
|
1129
1287
|
# end
|
1130
1288
|
#
|
1131
1289
|
def snapshot strong: nil, timestamp: nil, read_timestamp: nil,
|
1132
|
-
staleness: nil, exact_staleness: nil
|
1290
|
+
staleness: nil, exact_staleness: nil, call_options: nil
|
1133
1291
|
validate_snapshot_args! strong: strong, timestamp: timestamp,
|
1134
1292
|
read_timestamp: read_timestamp,
|
1135
1293
|
staleness: staleness,
|
@@ -1145,7 +1303,8 @@ module Google
|
|
1145
1303
|
snp_grpc = @project.service.create_snapshot \
|
1146
1304
|
session.path, strong: strong,
|
1147
1305
|
timestamp: (timestamp || read_timestamp),
|
1148
|
-
staleness: (staleness || exact_staleness)
|
1306
|
+
staleness: (staleness || exact_staleness),
|
1307
|
+
call_options: call_options
|
1149
1308
|
Thread.current[:transaction_id] = snp_grpc.id
|
1150
1309
|
snp = Snapshot.from_grpc snp_grpc, session
|
1151
1310
|
yield snp if block_given?
|