google-cloud-spanner 2.27.0 → 2.29.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 +23 -0
- data/lib/google/cloud/spanner/backup/job/list.rb +8 -6
- data/lib/google/cloud/spanner/backup/job.rb +11 -6
- data/lib/google/cloud/spanner/batch_client.rb +18 -5
- data/lib/google/cloud/spanner/client.rb +56 -15
- data/lib/google/cloud/spanner/instance.rb +14 -5
- data/lib/google/cloud/spanner/interval.rb +1 -1
- data/lib/google/cloud/spanner/partition.rb +7 -1
- data/lib/google/cloud/spanner/pool.rb +15 -0
- data/lib/google/cloud/spanner/project.rb +17 -5
- data/lib/google/cloud/spanner/results.rb +102 -30
- data/lib/google/cloud/spanner/service.rb +142 -10
- data/lib/google/cloud/spanner/session.rb +67 -33
- data/lib/google/cloud/spanner/snapshot.rb +31 -2
- data/lib/google/cloud/spanner/transaction.rb +77 -31
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +1 -1
|
@@ -43,8 +43,18 @@ module Google
|
|
|
43
43
|
RST_STREAM_INTERNAL_ERROR = "Received RST_STREAM".freeze
|
|
44
44
|
EOS_INTERNAL_ERROR = "Received unexpected EOS on DATA frame from server".freeze
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
#
|
|
46
|
+
# Creates a new `Spanner::Service` instance.
|
|
47
|
+
# @param project [::String] The project id to use
|
|
48
|
+
# @param credentials [::Symbol, ::Google::Auth::Credentials] Credentials
|
|
49
|
+
# @param quota_project [::String, nil] Optional. The quota project id to use
|
|
50
|
+
# @param host [::String, nil] Optional. The endpoint override.
|
|
51
|
+
# @param timeout [::Numeric, nil] Optional. Timeout for Gapic client.
|
|
52
|
+
# @param lib_name [::String, nil] Optional. Library name for headers.
|
|
53
|
+
# @param lib_version [::String, nil] Optional. Library version for headers.
|
|
54
|
+
# @param enable_leader_aware_routing [::Boolean, nil] Optional. Whether Leader
|
|
55
|
+
# Aware Routing should be enabled.
|
|
56
|
+
# @param universe_domain [::String, nil] Optional. The domain of the universe to connect to.
|
|
57
|
+
# @private
|
|
48
58
|
def initialize project, credentials, quota_project: nil,
|
|
49
59
|
host: nil, timeout: nil, lib_name: nil, lib_version: nil,
|
|
50
60
|
enable_leader_aware_routing: nil, universe_domain: nil
|
|
@@ -82,6 +92,8 @@ module Google
|
|
|
82
92
|
GRPC::Core::CallCredentials.new credentials.client.updater_proc
|
|
83
93
|
end
|
|
84
94
|
|
|
95
|
+
# `V1::Spanner::Client` or a mock.
|
|
96
|
+
# @return [::Google::Cloud::Spanner::V1::Spanner::Client]
|
|
85
97
|
def service
|
|
86
98
|
return mocked_service if mocked_service
|
|
87
99
|
@service ||=
|
|
@@ -145,6 +157,11 @@ module Google
|
|
|
145
157
|
paged_enum.response
|
|
146
158
|
end
|
|
147
159
|
|
|
160
|
+
# Gets information about a particular instance
|
|
161
|
+
# @param name [::String] The name of the Spanner instance, e.g. 'myinstance'
|
|
162
|
+
# or path to the Spanner instance, e.g. `projects/myproject/instances/myinstance`.
|
|
163
|
+
# @private
|
|
164
|
+
# @return [::Google::Cloud::Spanner::Admin::Instance::V1::Instance]
|
|
148
165
|
def get_instance name, call_options: nil
|
|
149
166
|
opts = default_options call_options: call_options
|
|
150
167
|
request = { name: instance_path(name) }
|
|
@@ -329,13 +346,41 @@ module Google
|
|
|
329
346
|
service.get_session({ name: session_name }, opts)
|
|
330
347
|
end
|
|
331
348
|
|
|
349
|
+
# Creates a new Spanner session.
|
|
350
|
+
# This creates a `V1::Session` protobuf object not wrapped in `Spanner::Session`.
|
|
351
|
+
#
|
|
352
|
+
# @param database_name [::String] The full name of the database.
|
|
353
|
+
# @param labels [::Hash, nil] Optional. The labels to be applied to all sessions
|
|
354
|
+
# created by the client. Example: `"team" => "billing-service"`.
|
|
355
|
+
# @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
|
|
356
|
+
# call options. Example option `:timeout`.
|
|
357
|
+
# @param database_role [::String, nil] Optional. The Spanner session creator role.
|
|
358
|
+
# Example: `analyst`.
|
|
359
|
+
# @param multiplexed [::Boolean] Optional. Default to `false`.
|
|
360
|
+
# If `true`, specifies a multiplexed session.
|
|
361
|
+
# @return [::Google::Cloud::Spanner::V1::Session]
|
|
362
|
+
# @private
|
|
332
363
|
def create_session database_name, labels: nil,
|
|
333
|
-
call_options: nil, database_role: nil
|
|
364
|
+
call_options: nil, database_role: nil,
|
|
365
|
+
multiplexed: false
|
|
334
366
|
route_to_leader = LARHeaders.create_session
|
|
335
|
-
opts = default_options
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
367
|
+
opts = default_options(
|
|
368
|
+
session_name: database_name,
|
|
369
|
+
call_options: call_options,
|
|
370
|
+
route_to_leader: route_to_leader
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
# check if we need a session object in request or server defaults would work.
|
|
374
|
+
params_diff_from_default = !(labels.nil? && database_role.nil? && !multiplexed)
|
|
375
|
+
|
|
376
|
+
if params_diff_from_default
|
|
377
|
+
session = V1::Session.new(
|
|
378
|
+
labels: labels,
|
|
379
|
+
creator_role: database_role,
|
|
380
|
+
multiplexed: multiplexed
|
|
381
|
+
)
|
|
382
|
+
end
|
|
383
|
+
|
|
339
384
|
service.create_session(
|
|
340
385
|
{ database: database_name, session: session }, opts
|
|
341
386
|
)
|
|
@@ -414,7 +459,7 @@ module Google
|
|
|
414
459
|
resume_token: nil, partition_token: nil,
|
|
415
460
|
request_options: nil, call_options: nil,
|
|
416
461
|
data_boost_enabled: nil, directed_read_options: nil,
|
|
417
|
-
route_to_leader: nil
|
|
462
|
+
route_to_leader: nil, order_by: nil, lock_hint: nil
|
|
418
463
|
opts = default_options session_name: session_name,
|
|
419
464
|
call_options: call_options,
|
|
420
465
|
route_to_leader: route_to_leader
|
|
@@ -422,7 +467,8 @@ module Google
|
|
|
422
467
|
session: session_name, table: table_name, columns: columns,
|
|
423
468
|
key_set: keys, transaction: transaction, index: index,
|
|
424
469
|
limit: limit, resume_token: resume_token,
|
|
425
|
-
partition_token: partition_token, request_options: request_options
|
|
470
|
+
partition_token: partition_token, request_options: request_options,
|
|
471
|
+
order_by: order_by, lock_hint: lock_hint
|
|
426
472
|
}
|
|
427
473
|
request[:data_boost_enabled] = data_boost_enabled unless data_boost_enabled.nil?
|
|
428
474
|
request[:directed_read_options] = directed_read_options unless directed_read_options.nil?
|
|
@@ -463,6 +509,29 @@ module Google
|
|
|
463
509
|
service.partition_query request, opts
|
|
464
510
|
end
|
|
465
511
|
|
|
512
|
+
# Commits a transaction. Can be a predefined (`transaction_id`) transaction
|
|
513
|
+
# or a single-use created for this request. The request includes the mutations to be
|
|
514
|
+
# applied to rows in the database.
|
|
515
|
+
#
|
|
516
|
+
# @param session_name [::String]
|
|
517
|
+
# Required. The session in which the transaction to be committed is running.
|
|
518
|
+
# @param mutations [::Array<::Google::Cloud::Spanner::V1::Mutation>] Optional.
|
|
519
|
+
# The mutations to be executed when this transaction commits. All
|
|
520
|
+
# mutations are applied atomically, in the order they appear in
|
|
521
|
+
# this list. Defaults to an empty array.
|
|
522
|
+
# @param transaction_id [::String, nil] Optional.
|
|
523
|
+
# Commit a previously-started transaction. If nil, a new single-use transation will be used.
|
|
524
|
+
# @param exclude_txn_from_change_streams [::Boolean] Optional. Defaults to `false`.
|
|
525
|
+
# When `exclude_txn_from_change_streams` is set to `true`, it prevents read
|
|
526
|
+
# or write transactions from being tracked in change streams.
|
|
527
|
+
# @param commit_options [::Hash, nil] Optional. A hash of commit options.
|
|
528
|
+
# Example option: `:return_commit_stats`.
|
|
529
|
+
# @param request_options [::Hash, nil] Optional. Common request options.
|
|
530
|
+
# Example option: `:priority`.
|
|
531
|
+
# @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
|
|
532
|
+
# call options. Example option `:timeout`.
|
|
533
|
+
# @private
|
|
534
|
+
# @return [::Google::Cloud::Spanner::V1::CommitResponse]
|
|
466
535
|
def commit session_name, mutations = [],
|
|
467
536
|
transaction_id: nil, exclude_txn_from_change_streams: false,
|
|
468
537
|
commit_options: nil, request_options: nil, call_options: nil
|
|
@@ -484,10 +553,16 @@ module Google
|
|
|
484
553
|
}
|
|
485
554
|
|
|
486
555
|
request = add_commit_options request, commit_options
|
|
487
|
-
|
|
556
|
+
# request is a hash equivalent of `::Google::Cloud::Spanner::V1::CommitRequest`
|
|
488
557
|
service.commit request, opts
|
|
489
558
|
end
|
|
490
559
|
|
|
560
|
+
# Merges commit options hash to a hash representing a `V1::CommitRequest`.
|
|
561
|
+
# @param request [::Hash] A `::Google::Cloud::Spanner::V1::CommitRequest` in a hash form.
|
|
562
|
+
# @param commit_options [::Hash, nil] Optional. A hash of commit options.
|
|
563
|
+
# Example option: `:return_commit_stats`.
|
|
564
|
+
# @return [::Hash] An enriched `::Google::Cloud::Spanner::V1::CommitRequest` in a hash form.
|
|
565
|
+
# @private
|
|
491
566
|
def add_commit_options request, commit_options
|
|
492
567
|
if commit_options
|
|
493
568
|
if commit_options.key? :return_commit_stats
|
|
@@ -512,6 +587,38 @@ module Google
|
|
|
512
587
|
service.rollback request, opts
|
|
513
588
|
end
|
|
514
589
|
|
|
590
|
+
# Explicitly begins a new transaction, making a `BeginTransaction` rpc call,
|
|
591
|
+
# and creating and returning a `V1::Transaction` object.
|
|
592
|
+
#
|
|
593
|
+
# Explicit transaction creation can often be skipped:
|
|
594
|
+
# {::Google::Cloud::Spanner::V1::Spanner::Client#read Read},
|
|
595
|
+
# {::Google::Cloud::Spanner::V1::Spanner::Client#execute_sql ExecuteSql} and
|
|
596
|
+
# {::Google::Cloud::Spanner::V1::Spanner::Client#execute_batch_dml ExecuteBatchDml}
|
|
597
|
+
# can begin a new transaction as part of the request (so-called inline-begin).
|
|
598
|
+
# The inline-begin functionality is used in methods on `Spanner::Transaction` class,
|
|
599
|
+
# e.g. `Spanner::Transaction#read`, accessible to the end-users via the `Spanner::Client#transaction` method.
|
|
600
|
+
#
|
|
601
|
+
# All the above methods, and {::Google::Cloud::Spanner::V1::Spanner::Client#commit Commit}
|
|
602
|
+
# can utilize single-use transactions that do not require an explicit BeginTransaction call.
|
|
603
|
+
# Single-use transactions are used by the methods on `Spanner::Client` class,
|
|
604
|
+
# e.g. `Spanner::Client#read`, with the exception of `Spanner::Client#transaction`.
|
|
605
|
+
#
|
|
606
|
+
# @param session_name [::String]
|
|
607
|
+
# Required. The session in which the transaction is to be created.
|
|
608
|
+
# Values are of the form:
|
|
609
|
+
# `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
|
|
610
|
+
# @param exclude_txn_from_change_streams [::Boolean] Optional. Defaults to `false`.
|
|
611
|
+
# When `exclude_txn_from_change_streams` is set to `true`, it prevents read
|
|
612
|
+
# or write transactions from being tracked in change streams.
|
|
613
|
+
# @param request_options [::Hash, nil] Optional. Common request options.
|
|
614
|
+
# Example option: `:priority`.
|
|
615
|
+
# @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
|
|
616
|
+
# call options. Example option `:timeout`.
|
|
617
|
+
# @param route_to_leader [::String, nil] Optional. The value to be sent
|
|
618
|
+
# as `x-goog-spanner-route-to-leader` header for leader aware routing.
|
|
619
|
+
# Expected values: `"true"` or `"false"`.
|
|
620
|
+
# @private
|
|
621
|
+
# @return [::Google::Cloud::Spanner::V1::Transaction]
|
|
515
622
|
def begin_transaction session_name,
|
|
516
623
|
exclude_txn_from_change_streams: false,
|
|
517
624
|
request_options: nil,
|
|
@@ -647,6 +754,25 @@ module Google
|
|
|
647
754
|
databases.list_database_operations request, opts
|
|
648
755
|
end
|
|
649
756
|
|
|
757
|
+
# Lists the backup `::Google::Longrunning::Operation` long-running operations in
|
|
758
|
+
# the given instance. A backup operation has a name of the form
|
|
759
|
+
# projects/<project>/instances/<instance>/backups/<backup>/operations/<operation>.
|
|
760
|
+
# @param instance_id [::String] The name of the Spanner instance, e.g. 'myinstance'
|
|
761
|
+
# or path to the Spanner instance, e.g. `projects/myproject/instances/myinstance`.
|
|
762
|
+
# @param filter [::String, nil] Optional.
|
|
763
|
+
# An expression that filters the list of returned backup operations.
|
|
764
|
+
# Example filter: `done:true`.
|
|
765
|
+
# @param page_size [::Integer, nil] Optional.
|
|
766
|
+
# Number of operations to be returned in the response. If 0 or
|
|
767
|
+
# less, defaults to the server's maximum allowed page size.
|
|
768
|
+
# @param page_token [::String, nil] Optional.
|
|
769
|
+
# If set, `page_token` should contain a value received as a `next_page_token`
|
|
770
|
+
# from a previous `ListBackupOperationsResponse` to the same `parent`
|
|
771
|
+
# and with the same `filter`.
|
|
772
|
+
# @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
|
|
773
|
+
# call options. Example option `:timeout`.
|
|
774
|
+
# @private
|
|
775
|
+
# @return [::Gapic::PagedEnumerable<::Gapic::Operation>]
|
|
650
776
|
def list_backup_operations instance_id,
|
|
651
777
|
filter: nil, page_size: nil,
|
|
652
778
|
page_token: nil,
|
|
@@ -736,6 +862,12 @@ module Google
|
|
|
736
862
|
project: project
|
|
737
863
|
end
|
|
738
864
|
|
|
865
|
+
# Converts an instance name to instance path.
|
|
866
|
+
# If an instance path is given, returns it unchanged
|
|
867
|
+
# @param name [::String] name of the Spanner instance, e.g. 'myinstance'
|
|
868
|
+
# or path to the Spanner instance, e.g. `projects/myproject/instances/myinstance`.
|
|
869
|
+
# @private
|
|
870
|
+
# @return [::String]
|
|
739
871
|
def instance_path name
|
|
740
872
|
return name if name.to_s.include? "/"
|
|
741
873
|
|
|
@@ -43,19 +43,28 @@ module Google
|
|
|
43
43
|
# no operations are sent for more than an hour.
|
|
44
44
|
#
|
|
45
45
|
class Session
|
|
46
|
-
|
|
47
|
-
# @
|
|
46
|
+
# The wrapped `V1::Session` protobuf session object.
|
|
47
|
+
# @return [::Google::Cloud::Spanner::V1::Session]
|
|
48
|
+
# @private
|
|
48
49
|
attr_accessor :grpc
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
# @private
|
|
51
|
+
# The `Spanner::Service` object.
|
|
52
|
+
# @private
|
|
53
|
+
# @return [::Google::Cloud::Spanner::Service]
|
|
52
54
|
attr_accessor :service
|
|
53
55
|
|
|
54
|
-
|
|
55
|
-
#
|
|
56
|
+
# A hash of values to specify the custom query options for executing SQL query.
|
|
57
|
+
# Example option: `:optimizer_version`.
|
|
58
|
+
# @private
|
|
59
|
+
# @return [::Hash, nil]
|
|
56
60
|
attr_accessor :query_options
|
|
57
61
|
|
|
58
|
-
#
|
|
62
|
+
# Creates a new Session instance.
|
|
63
|
+
# @param grpc [::Google::Cloud::Spanner::V1::Session] Underlying `V1::Session` object.
|
|
64
|
+
# @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` object.
|
|
65
|
+
# @param query_options [::Hash, nil] Optional. A hash of values to specify the custom
|
|
66
|
+
# query options for executing SQL query. Example option: `:optimizer_version`.
|
|
67
|
+
# @private
|
|
59
68
|
def initialize grpc, service, query_options: nil
|
|
60
69
|
@grpc = grpc
|
|
61
70
|
@service = service
|
|
@@ -63,33 +72,38 @@ module Google
|
|
|
63
72
|
end
|
|
64
73
|
|
|
65
74
|
# The unique identifier for the project.
|
|
66
|
-
# @
|
|
75
|
+
# @private
|
|
76
|
+
# @return [::String]
|
|
67
77
|
def project_id
|
|
68
78
|
@grpc.name.split("/")[1]
|
|
69
79
|
end
|
|
70
80
|
|
|
71
81
|
# The unique identifier for the instance.
|
|
72
|
-
# @
|
|
82
|
+
# @private
|
|
83
|
+
# @return [::String]
|
|
73
84
|
def instance_id
|
|
74
85
|
@grpc.name.split("/")[3]
|
|
75
86
|
end
|
|
76
87
|
|
|
77
88
|
# The unique identifier for the database.
|
|
78
|
-
# @
|
|
89
|
+
# @private
|
|
90
|
+
# @return [::String]
|
|
79
91
|
def database_id
|
|
80
92
|
@grpc.name.split("/")[5]
|
|
81
93
|
end
|
|
82
94
|
|
|
83
95
|
# The unique identifier for the session.
|
|
84
|
-
# @
|
|
96
|
+
# @private
|
|
97
|
+
# @return [::String]
|
|
85
98
|
def session_id
|
|
86
99
|
@grpc.name.split("/")[7]
|
|
87
100
|
end
|
|
88
101
|
|
|
89
|
-
|
|
90
|
-
#
|
|
102
|
+
# Full session name.
|
|
103
|
+
# Values are of the form:
|
|
91
104
|
# `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
|
|
92
|
-
# @
|
|
105
|
+
# @private
|
|
106
|
+
# @return [::String]
|
|
93
107
|
def path
|
|
94
108
|
@grpc.name
|
|
95
109
|
end
|
|
@@ -360,7 +374,7 @@ module Google
|
|
|
360
374
|
response = service.execute_streaming_sql path, sql, **execute_query_options
|
|
361
375
|
|
|
362
376
|
results = Results.from_execute_query_response response, service, path, sql, execute_query_options
|
|
363
|
-
@last_updated_at =
|
|
377
|
+
@last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
|
|
364
378
|
results
|
|
365
379
|
end
|
|
366
380
|
|
|
@@ -430,7 +444,7 @@ module Google
|
|
|
430
444
|
batch.statements, seqno,
|
|
431
445
|
request_options: request_options,
|
|
432
446
|
call_options: call_options
|
|
433
|
-
@last_updated_at =
|
|
447
|
+
@last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
|
|
434
448
|
results
|
|
435
449
|
end
|
|
436
450
|
|
|
@@ -483,6 +497,14 @@ module Google
|
|
|
483
497
|
# * `:multiplier` (`Numeric`) - The incremental backoff multiplier.
|
|
484
498
|
# * `:retry_codes` (`Array<String>`) - The error codes that should
|
|
485
499
|
# trigger a retry.
|
|
500
|
+
# @param [::Google::Cloud::Spanner::V1::ReadRequest::OrderBy] order_by An option to control the order in which
|
|
501
|
+
# rows are returned from a read.
|
|
502
|
+
# To see the available options refer to
|
|
503
|
+
# ['Google::Cloud::Spanner::V1::ReadRequest::OrderBy'](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-ReadRequest-OrderBy)
|
|
504
|
+
# @param [::Google::Cloud::Spanner::V1::ReadRequest::LockHint] lock_hint A lock hint mechanism for reads done
|
|
505
|
+
# within a transaction.
|
|
506
|
+
# To see the available options refer to
|
|
507
|
+
# ['Google::Cloud::Spanner::V1::ReadRequest::LockHint'](https://cloud.google.com/ruby/docs/reference/google-cloud-spanner-v1/latest/Google-Cloud-Spanner-V1-ReadRequest-LockHint)
|
|
486
508
|
#
|
|
487
509
|
# @return [Google::Cloud::Spanner::Results] The results of the read
|
|
488
510
|
# operation.
|
|
@@ -503,7 +525,7 @@ module Google
|
|
|
503
525
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
|
504
526
|
transaction: nil, partition_token: nil, request_options: nil,
|
|
505
527
|
call_options: nil, data_boost_enabled: nil, directed_read_options: nil,
|
|
506
|
-
route_to_leader: nil
|
|
528
|
+
route_to_leader: nil, order_by: nil, lock_hint: nil
|
|
507
529
|
ensure_service!
|
|
508
530
|
|
|
509
531
|
read_options = {
|
|
@@ -512,7 +534,9 @@ module Google
|
|
|
512
534
|
partition_token: partition_token,
|
|
513
535
|
request_options: request_options,
|
|
514
536
|
call_options: call_options,
|
|
515
|
-
route_to_leader: route_to_leader
|
|
537
|
+
route_to_leader: route_to_leader,
|
|
538
|
+
order_by: order_by,
|
|
539
|
+
lock_hint: lock_hint
|
|
516
540
|
}
|
|
517
541
|
read_options[:data_boost_enabled] = data_boost_enabled unless data_boost_enabled.nil?
|
|
518
542
|
read_options[:directed_read_options] = directed_read_options unless directed_read_options.nil?
|
|
@@ -522,7 +546,7 @@ module Google
|
|
|
522
546
|
|
|
523
547
|
results = Results.from_read_response response, service, path, table, columns, read_options
|
|
524
548
|
|
|
525
|
-
@last_updated_at =
|
|
549
|
+
@last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
|
|
526
550
|
|
|
527
551
|
results
|
|
528
552
|
end
|
|
@@ -538,7 +562,7 @@ module Google
|
|
|
538
562
|
max_partitions: max_partitions,
|
|
539
563
|
call_options: call_options
|
|
540
564
|
|
|
541
|
-
@last_updated_at =
|
|
565
|
+
@last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
|
|
542
566
|
|
|
543
567
|
results
|
|
544
568
|
end
|
|
@@ -555,7 +579,7 @@ module Google
|
|
|
555
579
|
max_partitions: max_partitions,
|
|
556
580
|
call_options: call_options
|
|
557
581
|
|
|
558
|
-
@last_updated_at =
|
|
582
|
+
@last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
|
|
559
583
|
|
|
560
584
|
results
|
|
561
585
|
end
|
|
@@ -657,7 +681,7 @@ module Google
|
|
|
657
681
|
commit_options: commit_options,
|
|
658
682
|
request_options: request_options,
|
|
659
683
|
call_options: call_options
|
|
660
|
-
@last_updated_at =
|
|
684
|
+
@last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
|
|
661
685
|
resp = CommitResponse.from_grpc commit_resp
|
|
662
686
|
commit_options ? resp : resp.timestamp
|
|
663
687
|
end
|
|
@@ -755,7 +779,7 @@ module Google
|
|
|
755
779
|
request_options: request_options,
|
|
756
780
|
call_options: call_options
|
|
757
781
|
results = BatchWriteResults.new response
|
|
758
|
-
@last_updated_at =
|
|
782
|
+
@last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
|
|
759
783
|
results
|
|
760
784
|
end
|
|
761
785
|
|
|
@@ -1341,7 +1365,7 @@ module Google
|
|
|
1341
1365
|
# Rolls back the transaction, releasing any locks it holds.
|
|
1342
1366
|
def rollback transaction_id
|
|
1343
1367
|
service.rollback path, transaction_id
|
|
1344
|
-
@last_updated_at =
|
|
1368
|
+
@last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
|
|
1345
1369
|
true
|
|
1346
1370
|
end
|
|
1347
1371
|
|
|
@@ -1370,7 +1394,7 @@ module Google
|
|
|
1370
1394
|
def reload!
|
|
1371
1395
|
ensure_service!
|
|
1372
1396
|
@grpc = service.get_session path
|
|
1373
|
-
@last_updated_at =
|
|
1397
|
+
@last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
|
|
1374
1398
|
self
|
|
1375
1399
|
rescue Google::Cloud::NotFoundError
|
|
1376
1400
|
labels = @grpc.labels.to_h unless @grpc.labels.to_h.empty?
|
|
@@ -1379,7 +1403,7 @@ module Google
|
|
|
1379
1403
|
project: project_id, instance: instance_id, database: database_id
|
|
1380
1404
|
),
|
|
1381
1405
|
labels: labels
|
|
1382
|
-
@last_updated_at =
|
|
1406
|
+
@last_updated_at = Process.clock_gettime Process::CLOCK_MONOTONIC
|
|
1383
1407
|
self
|
|
1384
1408
|
end
|
|
1385
1409
|
|
|
@@ -1408,18 +1432,23 @@ module Google
|
|
|
1408
1432
|
service.delete_session path
|
|
1409
1433
|
end
|
|
1410
1434
|
|
|
1411
|
-
##
|
|
1412
|
-
# @private
|
|
1413
1435
|
# Determines if the session has been idle longer than the given
|
|
1414
1436
|
# duration.
|
|
1415
|
-
|
|
1437
|
+
# @param duration_sec [::Numeric] interval in seconds
|
|
1438
|
+
# @private
|
|
1439
|
+
# @return [::Boolean]
|
|
1440
|
+
def idle_since? duration_sec
|
|
1416
1441
|
return true if @last_updated_at.nil?
|
|
1417
|
-
|
|
1442
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC) > @last_updated_at + duration_sec
|
|
1418
1443
|
end
|
|
1419
1444
|
|
|
1420
|
-
|
|
1421
|
-
# @
|
|
1422
|
-
#
|
|
1445
|
+
# Creates a new Session instance from a `V1::Session`.
|
|
1446
|
+
# @param grpc [::Google::Cloud::Spanner::V1::Session] Underlying `V1::Session` object.
|
|
1447
|
+
# @param service [::Google::Cloud::Spanner::Service] A `Spanner::Service` ref.
|
|
1448
|
+
# @param query_options [::Hash, nil] Optional. A hash of values to specify the custom
|
|
1449
|
+
# query options for executing SQL query. Example option: `:optimizer_version`.
|
|
1450
|
+
# @private
|
|
1451
|
+
# @return [::Google::Cloud::Spanner::Session]
|
|
1423
1452
|
def self.from_grpc grpc, service, query_options: nil
|
|
1424
1453
|
new grpc, service, query_options: query_options
|
|
1425
1454
|
end
|
|
@@ -1439,6 +1468,11 @@ module Google
|
|
|
1439
1468
|
raise "Must have active connection to service" unless service
|
|
1440
1469
|
end
|
|
1441
1470
|
|
|
1471
|
+
# Merge two hashes
|
|
1472
|
+
# @param hash [::Hash, nil]
|
|
1473
|
+
# @param hash_to_merge [::Hash, nil]
|
|
1474
|
+
# @private
|
|
1475
|
+
# @return [::Hash, nil]
|
|
1442
1476
|
def merge_if_present hash, hash_to_merge
|
|
1443
1477
|
if hash.nil?
|
|
1444
1478
|
hash_to_merge
|
|
@@ -131,6 +131,18 @@ module Google
|
|
|
131
131
|
# available optimizer version.
|
|
132
132
|
# * `:optimizer_statistics_package` (String) Statistics package to
|
|
133
133
|
# use. Empty to use the database default.
|
|
134
|
+
# @param [Hash] request_options Common request options.
|
|
135
|
+
#
|
|
136
|
+
# * `:priority` (Symbol) The relative priority for requests.
|
|
137
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
|
138
|
+
# and does not guarantee priority or order of execution.
|
|
139
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
|
140
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
|
141
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
|
142
|
+
# * `:tag` (String) A per-request tag which can be applied to
|
|
143
|
+
# queries or reads, used for statistics collection. Tag must be a
|
|
144
|
+
# valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
|
|
145
|
+
# and 64 characters in length.
|
|
134
146
|
# @param [Hash] call_options A hash of values to specify the custom
|
|
135
147
|
# call options, e.g., timeout, retries, etc. Call options are
|
|
136
148
|
# optional. The following settings can be provided:
|
|
@@ -304,13 +316,17 @@ module Google
|
|
|
304
316
|
# end
|
|
305
317
|
#
|
|
306
318
|
def execute_query sql, params: nil, types: nil, query_options: nil,
|
|
307
|
-
|
|
319
|
+
request_options: nil, call_options: nil,
|
|
320
|
+
directed_read_options: nil
|
|
308
321
|
ensure_session!
|
|
309
322
|
|
|
310
323
|
params, types = Convert.to_input_params_and_types params, types
|
|
324
|
+
request_options = Convert.to_request_options request_options,
|
|
325
|
+
tag_type: :request_tag
|
|
311
326
|
session.execute_query sql, params: params, types: types,
|
|
312
327
|
transaction: tx_selector,
|
|
313
328
|
query_options: query_options,
|
|
329
|
+
request_options: request_options,
|
|
314
330
|
call_options: call_options,
|
|
315
331
|
directed_read_options: directed_read_options || @directed_read_options
|
|
316
332
|
end
|
|
@@ -334,6 +350,18 @@ module Google
|
|
|
334
350
|
# Optional.
|
|
335
351
|
# @param [Integer] limit If greater than zero, no more than this number
|
|
336
352
|
# of rows will be returned. The default is no limit.
|
|
353
|
+
# @param [Hash] request_options Common request options.
|
|
354
|
+
#
|
|
355
|
+
# * `:priority` (Symbol) The relative priority for requests.
|
|
356
|
+
# The priority acts as a hint to the Cloud Spanner scheduler
|
|
357
|
+
# and does not guarantee priority or order of execution.
|
|
358
|
+
# Valid values are `:PRIORITY_LOW`, `:PRIORITY_MEDIUM`,
|
|
359
|
+
# `:PRIORITY_HIGH`. If priority not set then default is
|
|
360
|
+
# `PRIORITY_UNSPECIFIED` is equivalent to `:PRIORITY_HIGH`.
|
|
361
|
+
# * `:tag` (String) A per-request tag which can be applied to
|
|
362
|
+
# queries or reads, used for statistics collection. Tag must be a
|
|
363
|
+
# valid identifier of the form: `[a-zA-Z][a-zA-Z0-9_\-]` between 2
|
|
364
|
+
# and 64 characters in length.
|
|
337
365
|
# @param [Hash] call_options A hash of values to specify the custom
|
|
338
366
|
# call options, e.g., timeout, retries, etc. Call options are
|
|
339
367
|
# optional. The following settings can be provided:
|
|
@@ -380,7 +408,7 @@ module Google
|
|
|
380
408
|
# end
|
|
381
409
|
#
|
|
382
410
|
def read table, columns, keys: nil, index: nil, limit: nil,
|
|
383
|
-
call_options: nil, directed_read_options: nil
|
|
411
|
+
request_options: nil, call_options: nil, directed_read_options: nil
|
|
384
412
|
ensure_session!
|
|
385
413
|
|
|
386
414
|
columns = Array(columns).map(&:to_s)
|
|
@@ -388,6 +416,7 @@ module Google
|
|
|
388
416
|
|
|
389
417
|
session.read table, columns, keys: keys, index: index, limit: limit,
|
|
390
418
|
transaction: tx_selector,
|
|
419
|
+
request_options: request_options,
|
|
391
420
|
call_options: call_options,
|
|
392
421
|
directed_read_options: directed_read_options || @directed_read_options
|
|
393
422
|
end
|