google-cloud-spanner 1.16.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHENTICATION.md +1 -1
- data/CHANGELOG.md +54 -0
- data/CONTRIBUTING.md +5 -5
- data/TROUBLESHOOTING.md +0 -6
- data/lib/google-cloud-spanner.rb +11 -13
- data/lib/google/cloud/spanner.rb +6 -8
- data/lib/google/cloud/spanner/admin/database/credentials.rb +2 -2
- data/lib/google/cloud/spanner/admin/instance/credentials.rb +2 -2
- data/lib/google/cloud/spanner/backup.rb +1 -1
- data/lib/google/cloud/spanner/backup/job.rb +2 -2
- data/lib/google/cloud/spanner/backup/job/list.rb +2 -2
- data/lib/google/cloud/spanner/backup/list.rb +1 -2
- data/lib/google/cloud/spanner/backup/restore/job.rb +2 -2
- data/lib/google/cloud/spanner/batch_client.rb +2 -2
- data/lib/google/cloud/spanner/batch_snapshot.rb +120 -23
- data/lib/google/cloud/spanner/batch_update.rb +1 -1
- data/lib/google/cloud/spanner/client.rb +189 -30
- data/lib/google/cloud/spanner/commit.rb +14 -14
- data/lib/google/cloud/spanner/convert.rb +16 -7
- data/lib/google/cloud/spanner/credentials.rb +2 -2
- data/lib/google/cloud/spanner/data.rb +2 -2
- data/lib/google/cloud/spanner/database.rb +22 -22
- data/lib/google/cloud/spanner/database/backup_info.rb +1 -1
- data/lib/google/cloud/spanner/database/job.rb +3 -3
- data/lib/google/cloud/spanner/database/job/list.rb +2 -2
- data/lib/google/cloud/spanner/database/list.rb +1 -1
- data/lib/google/cloud/spanner/database/restore_info.rb +1 -1
- data/lib/google/cloud/spanner/fields.rb +8 -8
- data/lib/google/cloud/spanner/instance.rb +5 -12
- data/lib/google/cloud/spanner/instance/config.rb +1 -1
- data/lib/google/cloud/spanner/instance/config/list.rb +1 -1
- data/lib/google/cloud/spanner/instance/job.rb +2 -2
- data/lib/google/cloud/spanner/instance/list.rb +1 -1
- data/lib/google/cloud/spanner/partition.rb +4 -4
- data/lib/google/cloud/spanner/policy.rb +2 -2
- data/lib/google/cloud/spanner/results.rb +103 -24
- data/lib/google/cloud/spanner/service.rb +363 -350
- data/lib/google/cloud/spanner/session.rb +186 -31
- data/lib/google/cloud/spanner/snapshot.rb +60 -6
- data/lib/google/cloud/spanner/transaction.rb +116 -10
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +20 -109
- data/lib/google/cloud/spanner/admin/database.rb +0 -149
- data/lib/google/cloud/spanner/admin/database/v1.rb +0 -147
- data/lib/google/cloud/spanner/admin/database/v1/credentials.rb +0 -46
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +0 -1513
- data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +0 -111
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/iam_policy.rb +0 -64
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/options.rb +0 -33
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +0 -151
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/longrunning/operations.rb +0 -51
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/backup.rb +0 -325
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +0 -368
- data/lib/google/cloud/spanner/admin/database/v1/doc/google/type/expr.rb +0 -45
- data/lib/google/cloud/spanner/admin/instance.rb +0 -164
- data/lib/google/cloud/spanner/admin/instance/v1.rb +0 -162
- data/lib/google/cloud/spanner/admin/instance/v1/credentials.rb +0 -46
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/iam_policy.rb +0 -64
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/options.rb +0 -33
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +0 -151
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/longrunning/operations.rb +0 -51
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +0 -222
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +0 -334
- data/lib/google/cloud/spanner/admin/instance/v1/doc/google/type/expr.rb +0 -45
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +0 -975
- data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +0 -76
- data/lib/google/cloud/spanner/v1.rb +0 -16
- data/lib/google/cloud/spanner/v1/credentials.rb +0 -42
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/any.rb +0 -131
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +0 -91
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/empty.rb +0 -29
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +0 -74
- data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +0 -113
- data/lib/google/cloud/spanner/v1/doc/google/rpc/status.rb +0 -39
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +0 -150
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +0 -95
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +0 -121
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +0 -190
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +0 -570
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +0 -432
- data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/type.rb +0 -112
- data/lib/google/cloud/spanner/v1/spanner_client.rb +0 -1485
- data/lib/google/cloud/spanner/v1/spanner_client_config.json +0 -121
- data/lib/google/spanner/admin/database/v1/backup_pb.rb +0 -98
- data/lib/google/spanner/admin/database/v1/common_pb.rb +0 -28
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +0 -141
- data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +0 -169
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +0 -125
- data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +0 -181
- data/lib/google/spanner/v1/keys_pb.rb +0 -34
- data/lib/google/spanner/v1/mutation_pb.rb +0 -39
- data/lib/google/spanner/v1/query_plan_pb.rb +0 -48
- data/lib/google/spanner/v1/result_set_pb.rb +0 -48
- data/lib/google/spanner/v1/spanner_pb.rb +0 -179
- data/lib/google/spanner/v1/spanner_services_pb.rb +0 -179
- data/lib/google/spanner/v1/transaction_pb.rb +0 -56
- data/lib/google/spanner/v1/type_pb.rb +0 -44
@@ -42,7 +42,7 @@ module Google
|
|
42
42
|
#
|
43
43
|
class Session
|
44
44
|
##
|
45
|
-
# @private The Google::Spanner::V1::Session object
|
45
|
+
# @private The `Google::Cloud::Spanner::V1::Session` object
|
46
46
|
attr_accessor :grpc
|
47
47
|
|
48
48
|
##
|
@@ -150,7 +150,7 @@ module Google
|
|
150
150
|
# specified using a {Fields} object.
|
151
151
|
#
|
152
152
|
# Types are optional.
|
153
|
-
# @param [Google::Spanner::V1::TransactionSelector] transaction The
|
153
|
+
# @param [Google::Cloud::Spanner::V1::TransactionSelector] transaction The
|
154
154
|
# transaction selector value to send. Only used for single-use
|
155
155
|
# transactions.
|
156
156
|
# @param [Integer] seqno A per-transaction sequence number used to
|
@@ -162,6 +162,19 @@ module Google
|
|
162
162
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
163
163
|
# Empty to use database default. "latest" to use the latest
|
164
164
|
# available optimizer version.
|
165
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
166
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
167
|
+
# optional. The following settings can be provided:
|
168
|
+
#
|
169
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
170
|
+
# that overrides the default setting.
|
171
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
172
|
+
# setting of retry policy with the following keys:
|
173
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
174
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
175
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
176
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
177
|
+
# trigger a retry.
|
165
178
|
#
|
166
179
|
# @return [Google::Cloud::Spanner::Results] The results of the query
|
167
180
|
# execution.
|
@@ -275,8 +288,32 @@ module Google
|
|
275
288
|
# puts "User #{row[:id]} is #{row[:name]}"
|
276
289
|
# end
|
277
290
|
#
|
291
|
+
# @example Query using custom timeout and retry policy:
|
292
|
+
# require "google/cloud/spanner"
|
293
|
+
#
|
294
|
+
# spanner = Google::Cloud::Spanner.new
|
295
|
+
#
|
296
|
+
# db = spanner.client "my-instance", "my-database"
|
297
|
+
#
|
298
|
+
# timeout = 30.0
|
299
|
+
# retry_policy = {
|
300
|
+
# initial_delay: 0.25,
|
301
|
+
# max_delay: 32.0,
|
302
|
+
# multiplier: 1.3,
|
303
|
+
# retry_codes: ["UNAVAILABLE"]
|
304
|
+
# }
|
305
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
306
|
+
#
|
307
|
+
# results = db.execute_query \
|
308
|
+
# "SELECT * FROM users", call_options: call_options
|
309
|
+
#
|
310
|
+
# results.rows.each do |row|
|
311
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
312
|
+
# end
|
313
|
+
#
|
278
314
|
def execute_query sql, params: nil, types: nil, transaction: nil,
|
279
|
-
partition_token: nil, seqno: nil, query_options: nil
|
315
|
+
partition_token: nil, seqno: nil, query_options: nil,
|
316
|
+
call_options: nil
|
280
317
|
ensure_service!
|
281
318
|
if query_options.nil?
|
282
319
|
query_options = @query_options
|
@@ -289,7 +326,8 @@ module Google
|
|
289
326
|
transaction: transaction,
|
290
327
|
partition_token: partition_token,
|
291
328
|
seqno: seqno,
|
292
|
-
query_options: query_options
|
329
|
+
query_options: query_options,
|
330
|
+
call_options: call_options
|
293
331
|
@last_updated_at = Time.now
|
294
332
|
results
|
295
333
|
end
|
@@ -297,11 +335,25 @@ module Google
|
|
297
335
|
##
|
298
336
|
# Executes DML statements in a batch.
|
299
337
|
#
|
300
|
-
# @param [Google::Spanner::V1::TransactionSelector] transaction The
|
338
|
+
# @param [Google::Cloud::Spanner::V1::TransactionSelector] transaction The
|
301
339
|
# transaction selector value to send. Only used for single-use
|
302
340
|
# transactions.
|
303
341
|
# @param [Integer] seqno A per-transaction sequence number used to
|
304
342
|
# identify this request.
|
343
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
344
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
345
|
+
# optional. The following settings can be provided:
|
346
|
+
#
|
347
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
348
|
+
# that overrides the default setting.
|
349
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
350
|
+
# setting of retry policy with the following keys:
|
351
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
352
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
353
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
354
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
355
|
+
# trigger a retry.
|
356
|
+
#
|
305
357
|
# @yield [batch_update] a batch update object
|
306
358
|
# @yieldparam [Google::Cloud::Spanner::BatchUpdate] batch_update a batch
|
307
359
|
# update object accepting DML statements and optional parameters and
|
@@ -316,7 +368,7 @@ module Google
|
|
316
368
|
# @return [Array<Integer>] A list with the exact number of rows that
|
317
369
|
# were modified for each DML statement.
|
318
370
|
#
|
319
|
-
def batch_update transaction, seqno
|
371
|
+
def batch_update transaction, seqno, call_options: nil
|
320
372
|
ensure_service!
|
321
373
|
|
322
374
|
raise ArgumentError, "block is required" unless block_given?
|
@@ -325,7 +377,8 @@ module Google
|
|
325
377
|
yield batch
|
326
378
|
|
327
379
|
results = service.execute_batch_dml path, transaction,
|
328
|
-
batch.statements, seqno
|
380
|
+
batch.statements, seqno,
|
381
|
+
call_options: call_options
|
329
382
|
@last_updated_at = Time.now
|
330
383
|
results
|
331
384
|
end
|
@@ -346,9 +399,22 @@ module Google
|
|
346
399
|
# Optional.
|
347
400
|
# @param [Integer] limit If greater than zero, no more than this number
|
348
401
|
# of rows will be returned. The default is no limit.
|
349
|
-
# @param [Google::Spanner::V1::TransactionSelector] transaction The
|
402
|
+
# @param [Google::Cloud::Spanner::V1::TransactionSelector] transaction The
|
350
403
|
# transaction selector value to send. Only used for single-use
|
351
404
|
# transactions.
|
405
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
406
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
407
|
+
# optional. The following settings can be provided:
|
408
|
+
#
|
409
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
410
|
+
# that overrides the default setting.
|
411
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
412
|
+
# setting of retry policy with the following keys:
|
413
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
414
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
415
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
416
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
417
|
+
# trigger a retry.
|
352
418
|
#
|
353
419
|
# @return [Google::Cloud::Spanner::Results] The results of the read
|
354
420
|
# operation.
|
@@ -367,25 +433,28 @@ module Google
|
|
367
433
|
# end
|
368
434
|
#
|
369
435
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
370
|
-
transaction: nil, partition_token: nil
|
436
|
+
transaction: nil, partition_token: nil, call_options: nil
|
371
437
|
ensure_service!
|
372
438
|
|
373
439
|
results = Results.read service, path, table, columns,
|
374
440
|
keys: keys, index: index, limit: limit,
|
375
441
|
transaction: transaction,
|
376
|
-
partition_token: partition_token
|
442
|
+
partition_token: partition_token,
|
443
|
+
call_options: call_options
|
377
444
|
@last_updated_at = Time.now
|
378
445
|
results
|
379
446
|
end
|
380
447
|
|
381
448
|
def partition_query sql, transaction, params: nil, types: nil,
|
382
|
-
partition_size_bytes: nil, max_partitions: nil
|
449
|
+
partition_size_bytes: nil, max_partitions: nil,
|
450
|
+
call_options: nil
|
383
451
|
ensure_service!
|
384
452
|
|
385
453
|
results = service.partition_query \
|
386
454
|
path, sql, transaction, params: params, types: types,
|
387
455
|
partition_size_bytes: partition_size_bytes,
|
388
|
-
max_partitions: max_partitions
|
456
|
+
max_partitions: max_partitions,
|
457
|
+
call_options: call_options
|
389
458
|
|
390
459
|
@last_updated_at = Time.now
|
391
460
|
|
@@ -394,14 +463,15 @@ module Google
|
|
394
463
|
|
395
464
|
def partition_read table, columns, transaction, keys: nil,
|
396
465
|
index: nil, partition_size_bytes: nil,
|
397
|
-
max_partitions: nil
|
466
|
+
max_partitions: nil, call_options: nil
|
398
467
|
ensure_service!
|
399
468
|
|
400
469
|
results = service.partition_read \
|
401
470
|
path, table, columns, transaction,
|
402
471
|
keys: keys, index: index,
|
403
472
|
partition_size_bytes: partition_size_bytes,
|
404
|
-
max_partitions: max_partitions
|
473
|
+
max_partitions: max_partitions,
|
474
|
+
call_options: call_options
|
405
475
|
|
406
476
|
@last_updated_at = Time.now
|
407
477
|
|
@@ -414,6 +484,20 @@ module Google
|
|
414
484
|
# @param [String] transaction_id The identifier of previously-started
|
415
485
|
# transaction to be used instead of starting a new transaction.
|
416
486
|
# Optional.
|
487
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
488
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
489
|
+
# optional. The following settings can be provided:
|
490
|
+
#
|
491
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
492
|
+
# that overrides the default setting.
|
493
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
494
|
+
# setting of retry policy with the following keys:
|
495
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
496
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
497
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
498
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
499
|
+
# trigger a retry.
|
500
|
+
#
|
417
501
|
# @yield [commit] The block for mutating the data.
|
418
502
|
# @yieldparam [Google::Cloud::Spanner::Commit] commit The Commit object.
|
419
503
|
#
|
@@ -431,12 +515,13 @@ module Google
|
|
431
515
|
# c.insert "users", [{ id: 2, name: "Harvey", active: true }]
|
432
516
|
# end
|
433
517
|
#
|
434
|
-
def commit transaction_id: nil
|
518
|
+
def commit transaction_id: nil, call_options: nil
|
435
519
|
ensure_service!
|
436
520
|
commit = Commit.new
|
437
521
|
yield commit
|
438
522
|
commit_resp = service.commit path, commit.mutations,
|
439
|
-
transaction_id: transaction_id
|
523
|
+
transaction_id: transaction_id,
|
524
|
+
call_options: call_options
|
440
525
|
@last_updated_at = Time.now
|
441
526
|
Convert.timestamp_to_time commit_resp.commit_timestamp
|
442
527
|
end
|
@@ -467,6 +552,19 @@ module Google
|
|
467
552
|
#
|
468
553
|
# See [Data
|
469
554
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
555
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
556
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
557
|
+
# optional. The following settings can be provided:
|
558
|
+
#
|
559
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
560
|
+
# that overrides the default setting.
|
561
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
562
|
+
# setting of retry policy with the following keys:
|
563
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
564
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
565
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
566
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
567
|
+
# trigger a retry.
|
470
568
|
#
|
471
569
|
# @return [Time] The timestamp at which the operation committed.
|
472
570
|
#
|
@@ -480,8 +578,9 @@ module Google
|
|
480
578
|
# db.upsert "users", [{ id: 1, name: "Charlie", active: false },
|
481
579
|
# { id: 2, name: "Harvey", active: true }]
|
482
580
|
#
|
483
|
-
def upsert table, *rows, transaction_id: nil
|
484
|
-
|
581
|
+
def upsert table, *rows, transaction_id: nil, call_options: nil
|
582
|
+
opts = { transaction_id: transaction_id, call_options: call_options }
|
583
|
+
commit opts do |c|
|
485
584
|
c.upsert table, rows
|
486
585
|
end
|
487
586
|
end
|
@@ -512,6 +611,19 @@ module Google
|
|
512
611
|
#
|
513
612
|
# See [Data
|
514
613
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
614
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
615
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
616
|
+
# optional. The following settings can be provided:
|
617
|
+
#
|
618
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
619
|
+
# that overrides the default setting.
|
620
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
621
|
+
# setting of retry policy with the following keys:
|
622
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
623
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
624
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
625
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
626
|
+
# trigger a retry.
|
515
627
|
#
|
516
628
|
# @return [Time] The timestamp at which the operation committed.
|
517
629
|
#
|
@@ -525,8 +637,9 @@ module Google
|
|
525
637
|
# db.insert "users", [{ id: 1, name: "Charlie", active: false },
|
526
638
|
# { id: 2, name: "Harvey", active: true }]
|
527
639
|
#
|
528
|
-
def insert table, *rows, transaction_id: nil
|
529
|
-
|
640
|
+
def insert table, *rows, transaction_id: nil, call_options: nil
|
641
|
+
opts = { transaction_id: transaction_id, call_options: call_options }
|
642
|
+
commit opts do |c|
|
530
643
|
c.insert table, rows
|
531
644
|
end
|
532
645
|
end
|
@@ -556,6 +669,19 @@ module Google
|
|
556
669
|
#
|
557
670
|
# See [Data
|
558
671
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
672
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
673
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
674
|
+
# optional. The following settings can be provided:
|
675
|
+
#
|
676
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
677
|
+
# that overrides the default setting.
|
678
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
679
|
+
# setting of retry policy with the following keys:
|
680
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
681
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
682
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
683
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
684
|
+
# trigger a retry.
|
559
685
|
#
|
560
686
|
# @return [Time] The timestamp at which the operation committed.
|
561
687
|
#
|
@@ -569,8 +695,9 @@ module Google
|
|
569
695
|
# db.update "users", [{ id: 1, name: "Charlie", active: false },
|
570
696
|
# { id: 2, name: "Harvey", active: true }]
|
571
697
|
#
|
572
|
-
def update table, *rows, transaction_id: nil
|
573
|
-
|
698
|
+
def update table, *rows, transaction_id: nil, call_options: nil
|
699
|
+
opts = { transaction_id: transaction_id, call_options: call_options }
|
700
|
+
commit opts do |c|
|
574
701
|
c.update table, rows
|
575
702
|
end
|
576
703
|
end
|
@@ -602,6 +729,19 @@ module Google
|
|
602
729
|
#
|
603
730
|
# See [Data
|
604
731
|
# types](https://cloud.google.com/spanner/docs/data-definition-language#data_types).
|
732
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
733
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
734
|
+
# optional. The following settings can be provided:
|
735
|
+
#
|
736
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
737
|
+
# that overrides the default setting.
|
738
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
739
|
+
# setting of retry policy with the following keys:
|
740
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
741
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
742
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
743
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
744
|
+
# trigger a retry.
|
605
745
|
#
|
606
746
|
# @return [Time] The timestamp at which the operation committed.
|
607
747
|
#
|
@@ -615,8 +755,9 @@ module Google
|
|
615
755
|
# db.replace "users", [{ id: 1, name: "Charlie", active: false },
|
616
756
|
# { id: 2, name: "Harvey", active: true }]
|
617
757
|
#
|
618
|
-
def replace table, *rows, transaction_id: nil
|
619
|
-
|
758
|
+
def replace table, *rows, transaction_id: nil, call_options: nil
|
759
|
+
opts = { transaction_id: transaction_id, call_options: call_options }
|
760
|
+
commit opts do |c|
|
620
761
|
c.replace table, rows
|
621
762
|
end
|
622
763
|
end
|
@@ -630,6 +771,19 @@ module Google
|
|
630
771
|
# @param [Object, Array<Object>] keys A single, or list of keys or key
|
631
772
|
# ranges to match returned data to. Values should have exactly as many
|
632
773
|
# elements as there are columns in the primary key.
|
774
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
775
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
776
|
+
# optional. The following settings can be provided:
|
777
|
+
#
|
778
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
779
|
+
# that overrides the default setting.
|
780
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
781
|
+
# setting of retry policy with the following keys:
|
782
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
783
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
784
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
785
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
786
|
+
# trigger a retry.
|
633
787
|
#
|
634
788
|
# @return [Time] The timestamp at which the operation committed.
|
635
789
|
#
|
@@ -642,8 +796,9 @@ module Google
|
|
642
796
|
#
|
643
797
|
# db.delete "users", [1, 2, 3]
|
644
798
|
#
|
645
|
-
def delete table, keys = [], transaction_id: nil
|
646
|
-
|
799
|
+
def delete table, keys = [], transaction_id: nil, call_options: nil
|
800
|
+
opts = { transaction_id: transaction_id, call_options: call_options }
|
801
|
+
commit opts do |c|
|
647
802
|
c.delete table, keys
|
648
803
|
end
|
649
804
|
end
|
@@ -675,8 +830,8 @@ module Google
|
|
675
830
|
rescue Google::Cloud::NotFoundError
|
676
831
|
labels = @grpc.labels.to_h unless @grpc.labels.to_h.empty?
|
677
832
|
@grpc = service.create_session \
|
678
|
-
|
679
|
-
project_id, instance_id, database_id
|
833
|
+
V1::Spanner::Paths.database_path(
|
834
|
+
project: project_id, instance: instance_id, database: database_id
|
680
835
|
),
|
681
836
|
labels: labels
|
682
837
|
@last_updated_at = Time.now
|
@@ -693,8 +848,8 @@ module Google
|
|
693
848
|
rescue Google::Cloud::NotFoundError
|
694
849
|
labels = @grpc.labels.to_h unless @grpc.labels.to_h.empty?
|
695
850
|
@grpc = service.create_session \
|
696
|
-
|
697
|
-
project_id, instance_id, database_id
|
851
|
+
V1::Spanner::Paths.database_path(
|
852
|
+
project: project_id, instance: instance_id, database: database_id
|
698
853
|
),
|
699
854
|
labels: labels
|
700
855
|
false
|
@@ -718,7 +873,7 @@ module Google
|
|
718
873
|
|
719
874
|
##
|
720
875
|
# @private Creates a new Session instance from a
|
721
|
-
# Google::Spanner::V1::Session
|
876
|
+
# `Google::Cloud::Spanner::V1::Session`.
|
722
877
|
def self.from_grpc grpc, service, query_options: nil
|
723
878
|
new grpc, service, query_options: query_options
|
724
879
|
end
|
@@ -125,6 +125,19 @@ module Google
|
|
125
125
|
# * `:optimizer_version` (String) The version of optimizer to use.
|
126
126
|
# Empty to use database default. "latest" to use the latest
|
127
127
|
# available optimizer version.
|
128
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
129
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
130
|
+
# optional. The following settings can be provided:
|
131
|
+
#
|
132
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
133
|
+
# that overrides the default setting.
|
134
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
135
|
+
# setting of retry policy with the following keys:
|
136
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
137
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
138
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
139
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
140
|
+
# trigger a retry.
|
128
141
|
#
|
129
142
|
# @return [Google::Cloud::Spanner::Results] The results of the query
|
130
143
|
# execution.
|
@@ -243,13 +256,39 @@ module Google
|
|
243
256
|
# end
|
244
257
|
# end
|
245
258
|
#
|
246
|
-
|
259
|
+
# @example Query using custom timeout and retry policy:
|
260
|
+
# require "google/cloud/spanner"
|
261
|
+
#
|
262
|
+
# spanner = Google::Cloud::Spanner.new
|
263
|
+
# db = spanner.client "my-instance", "my-database"
|
264
|
+
#
|
265
|
+
# timeout = 30.0
|
266
|
+
# retry_policy = {
|
267
|
+
# initial_delay: 0.25,
|
268
|
+
# max_delay: 32.0,
|
269
|
+
# multiplier: 1.3,
|
270
|
+
# retry_codes: ["UNAVAILABLE"]
|
271
|
+
# }
|
272
|
+
# call_options = { timeout: timeout, retry_policy: retry_policy }
|
273
|
+
#
|
274
|
+
# db.snapshot do |snp|
|
275
|
+
# results = snp.execute_query \
|
276
|
+
# "SELECT * FROM users", call_options: call_options
|
277
|
+
#
|
278
|
+
# results.rows.each do |row|
|
279
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
280
|
+
# end
|
281
|
+
# end
|
282
|
+
#
|
283
|
+
def execute_query sql, params: nil, types: nil, query_options: nil,
|
284
|
+
call_options: nil
|
247
285
|
ensure_session!
|
248
286
|
|
249
287
|
params, types = Convert.to_input_params_and_types params, types
|
250
288
|
session.execute_query sql, params: params, types: types,
|
251
289
|
transaction: tx_selector,
|
252
|
-
query_options: query_options
|
290
|
+
query_options: query_options,
|
291
|
+
call_options: call_options
|
253
292
|
end
|
254
293
|
alias execute execute_query
|
255
294
|
alias query execute_query
|
@@ -271,6 +310,19 @@ module Google
|
|
271
310
|
# Optional.
|
272
311
|
# @param [Integer] limit If greater than zero, no more than this number
|
273
312
|
# of rows will be returned. The default is no limit.
|
313
|
+
# @param [Hash] call_options A hash of values to specify the custom
|
314
|
+
# call options, e.g., timeout, retries, etc. Call options are
|
315
|
+
# optional. The following settings can be provided:
|
316
|
+
#
|
317
|
+
# * `:timeout` (Numeric) A numeric value of custom timeout in seconds
|
318
|
+
# that overrides the default setting.
|
319
|
+
# * `:retry_policy` (Hash) A hash of values that overrides the default
|
320
|
+
# setting of retry policy with the following keys:
|
321
|
+
# * `:initial_delay` (`Numeric`) - The initial delay in seconds.
|
322
|
+
# * `:max_delay` (`Numeric`) - The max delay in seconds.
|
323
|
+
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
324
|
+
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
325
|
+
# trigger a retry.
|
274
326
|
#
|
275
327
|
# @return [Google::Cloud::Spanner::Results] The results of the read
|
276
328
|
# operation.
|
@@ -289,14 +341,16 @@ module Google
|
|
289
341
|
# end
|
290
342
|
# end
|
291
343
|
#
|
292
|
-
def read table, columns, keys: nil, index: nil, limit: nil
|
344
|
+
def read table, columns, keys: nil, index: nil, limit: nil,
|
345
|
+
call_options: nil
|
293
346
|
ensure_session!
|
294
347
|
|
295
348
|
columns = Array(columns).map(&:to_s)
|
296
349
|
keys = Convert.to_key_set keys
|
297
350
|
|
298
351
|
session.read table, columns, keys: keys, index: index, limit: limit,
|
299
|
-
transaction: tx_selector
|
352
|
+
transaction: tx_selector,
|
353
|
+
call_options: call_options
|
300
354
|
end
|
301
355
|
|
302
356
|
##
|
@@ -414,7 +468,7 @@ module Google
|
|
414
468
|
|
415
469
|
##
|
416
470
|
# @private Creates a new Snapshot instance from a
|
417
|
-
# Google::Spanner::V1::Transaction
|
471
|
+
# `Google::Cloud::Spanner::V1::Transaction`.
|
418
472
|
def self.from_grpc grpc, session
|
419
473
|
new.tap do |s|
|
420
474
|
s.instance_variable_set :@grpc, grpc
|
@@ -427,7 +481,7 @@ module Google
|
|
427
481
|
# The TransactionSelector to be used for queries
|
428
482
|
def tx_selector
|
429
483
|
return nil if transaction_id.nil?
|
430
|
-
|
484
|
+
V1::TransactionSelector.new id: transaction_id
|
431
485
|
end
|
432
486
|
|
433
487
|
##
|