google-cloud-spanner 2.26.0 → 2.28.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 +21 -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/batch_write_results.rb +2 -2
- data/lib/google/cloud/spanner/client.rb +55 -14
- data/lib/google/cloud/spanner/convert.rb +5 -0
- data/lib/google/cloud/spanner/instance.rb +14 -5
- data/lib/google/cloud/spanner/interval.rb +309 -0
- data/lib/google/cloud/spanner/partition.rb +7 -1
- data/lib/google/cloud/spanner/pool.rb +17 -2
- 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/transaction.rb +77 -31
- data/lib/google/cloud/spanner/version.rb +1 -1
- metadata +5 -4
|
@@ -36,6 +36,16 @@ module Google
|
|
|
36
36
|
# and `Session` objects as values.
|
|
37
37
|
attr_accessor :sessions_in_use
|
|
38
38
|
|
|
39
|
+
# Creates a new Session pool that manages non-multiplexed sessions.
|
|
40
|
+
# @param client [::Google::Cloud::Spanner::Client] A `Spanner::Client` reference
|
|
41
|
+
# @param min [::Integer] Min number of sessions to keep
|
|
42
|
+
# @param max [::Integer] Max number of sessions to keep
|
|
43
|
+
# @param keepalive [::Numeric] How long after their last usage the sessions can be reclaimed
|
|
44
|
+
# @param fail [::Boolean] If `true` the pool will raise `SessionLimitError` if number of new sessions
|
|
45
|
+
# needed is more that can be created due to the `max` parameter. If `false` it will wait instead.
|
|
46
|
+
# @param threads [::Integer, nil] Number of threads in the thread pool that is used for keepalive and
|
|
47
|
+
# release session actions. If `nil` the Pool will choose a reasonable default.
|
|
48
|
+
# @private
|
|
39
49
|
def initialize client, min: 10, max: 100, keepalive: 1800,
|
|
40
50
|
fail: true, threads: nil
|
|
41
51
|
@client = client
|
|
@@ -52,6 +62,11 @@ module Google
|
|
|
52
62
|
init
|
|
53
63
|
end
|
|
54
64
|
|
|
65
|
+
# Provides a session for running an operation
|
|
66
|
+
# @yield session Session a client can use to run an operation
|
|
67
|
+
# @yieldparam [::Google::Cloud::Spanner::Session] `Spanner::Session` to run an operation
|
|
68
|
+
# @private
|
|
69
|
+
# @return [nil]
|
|
55
70
|
def with_session
|
|
56
71
|
session = checkout_session
|
|
57
72
|
begin
|
|
@@ -221,8 +236,8 @@ module Google
|
|
|
221
236
|
@keepalive_task.execute
|
|
222
237
|
end
|
|
223
238
|
|
|
224
|
-
def future
|
|
225
|
-
Concurrent::Future.new(executor: @thread_pool, &
|
|
239
|
+
def future(&)
|
|
240
|
+
Concurrent::Future.new(executor: @thread_pool, &).execute
|
|
226
241
|
end
|
|
227
242
|
end
|
|
228
243
|
end
|
|
@@ -66,12 +66,22 @@ module Google
|
|
|
66
66
|
# end
|
|
67
67
|
#
|
|
68
68
|
class Project
|
|
69
|
-
|
|
70
|
-
# @private
|
|
71
|
-
|
|
69
|
+
# The `Spanner::Service` reference.
|
|
70
|
+
# @private
|
|
71
|
+
# @return [::Google::Cloud::Spanner::Service]
|
|
72
|
+
attr_accessor :service
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
#
|
|
74
|
+
# A hash of values to specify the custom query options for executing SQL query.
|
|
75
|
+
# Example option: `:optimizer_version`.
|
|
76
|
+
# @private
|
|
77
|
+
# @return [::Hash, nil]
|
|
78
|
+
attr_accessor :query_options
|
|
79
|
+
|
|
80
|
+
# Creates a new Spanner Project instance.
|
|
81
|
+
# @param service [::Google::Cloud::Spanner::Service] The `Spanner::Service` ref.
|
|
82
|
+
# @param query_options [::Hash, nil] Optional. A hash of values to specify the custom
|
|
83
|
+
# query options for executing SQL query. Example option: `:optimizer_version`.
|
|
84
|
+
# @private
|
|
75
85
|
def initialize service, query_options: nil
|
|
76
86
|
@service = service
|
|
77
87
|
@query_options = query_options
|
|
@@ -80,6 +90,8 @@ module Google
|
|
|
80
90
|
##
|
|
81
91
|
# The identifier for the Cloud Spanner project.
|
|
82
92
|
#
|
|
93
|
+
# @return [::String]
|
|
94
|
+
#
|
|
83
95
|
# @example
|
|
84
96
|
# require "google/cloud"
|
|
85
97
|
#
|
|
@@ -40,19 +40,44 @@ module Google
|
|
|
40
40
|
# puts "Column #{name} is type #{type}"
|
|
41
41
|
# end
|
|
42
42
|
#
|
|
43
|
+
# results.rows.each do |row|
|
|
44
|
+
# puts "User #{row[:id]} is #{row[:name]}"
|
|
45
|
+
# end
|
|
46
|
+
#
|
|
43
47
|
class Results
|
|
44
|
-
|
|
45
|
-
#
|
|
46
|
-
#
|
|
48
|
+
# The `V1::ResultSetMetadata` protobuf object from the first
|
|
49
|
+
# PartialResultSet.
|
|
50
|
+
# @private
|
|
51
|
+
# @return [::Google::Cloud::Spanner::V1::ResultSetMetadata]
|
|
47
52
|
attr_reader :metadata
|
|
48
53
|
|
|
54
|
+
# Creates a new Results instance.
|
|
55
|
+
# @param service [::Google::Cloud::Spanner::Service] The `Spanner::Service` reference.
|
|
56
|
+
# @param partial_result_sets [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>]
|
|
57
|
+
# Raw enumerable from grpc `StreamingRead` call.
|
|
58
|
+
# @param session_name [::String] Required.
|
|
59
|
+
# The session in which the transaction to be committed is running.
|
|
60
|
+
# Values are of the form:
|
|
61
|
+
# `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
|
|
62
|
+
# @param metadata [::Google::Cloud::Spanner::V1::ResultSetMetadata] ParialResultSet metadata object
|
|
63
|
+
# @param stats [::Google::Cloud::Spanner::V1::ResultSetStats] Query plan and execution statistics
|
|
64
|
+
# for the statement that produced this streaming result set.
|
|
65
|
+
# @private
|
|
66
|
+
def initialize service, partial_result_sets, session_name, metadata, stats
|
|
67
|
+
@service = service
|
|
68
|
+
@partial_result_sets = partial_result_sets
|
|
69
|
+
@session_name = session_name
|
|
70
|
+
@metadata = metadata
|
|
71
|
+
@stats = stats
|
|
72
|
+
end
|
|
73
|
+
|
|
49
74
|
##
|
|
50
75
|
# The read timestamp chosen for single-use snapshots (read-only
|
|
51
76
|
# transactions).
|
|
52
77
|
# @return [Time] The chosen timestamp.
|
|
53
78
|
def timestamp
|
|
54
|
-
return nil if
|
|
55
|
-
Convert.timestamp_to_time
|
|
79
|
+
return nil if transaction.nil?
|
|
80
|
+
Convert.timestamp_to_time transaction.read_timestamp
|
|
56
81
|
end
|
|
57
82
|
|
|
58
83
|
##
|
|
@@ -78,9 +103,9 @@ module Google
|
|
|
78
103
|
@fields ||= Fields.from_grpc @metadata.row_type.fields
|
|
79
104
|
end
|
|
80
105
|
|
|
81
|
-
|
|
106
|
+
# Returns a transaction from the first ResultSet's metadata if available
|
|
82
107
|
# @private
|
|
83
|
-
#
|
|
108
|
+
# @return [::Google::Cloud::Spanner::V1::Transaction, nil]
|
|
84
109
|
def transaction
|
|
85
110
|
@metadata&.transaction
|
|
86
111
|
end
|
|
@@ -128,16 +153,18 @@ module Google
|
|
|
128
153
|
loop do
|
|
129
154
|
begin
|
|
130
155
|
if should_resume_request
|
|
131
|
-
@
|
|
156
|
+
@partial_result_sets = resume_request(resume_token)
|
|
132
157
|
buffered_responses = []
|
|
133
158
|
should_resume_request = false
|
|
134
159
|
elsif should_retry_request
|
|
135
|
-
@
|
|
160
|
+
@partial_result_sets = retry_request()
|
|
136
161
|
buffered_responses = []
|
|
137
162
|
should_retry_request = false
|
|
138
163
|
end
|
|
139
164
|
|
|
140
|
-
|
|
165
|
+
# @type [::Google::Cloud::Spanner::V1::PartialResultsSet]
|
|
166
|
+
grpc = @partial_result_sets.next
|
|
167
|
+
|
|
141
168
|
# metadata should be set before the first iteration...
|
|
142
169
|
@metadata ||= grpc.metadata
|
|
143
170
|
@stats ||= grpc.stats
|
|
@@ -243,13 +270,13 @@ module Google
|
|
|
243
270
|
def resume_request resume_token
|
|
244
271
|
if @execute_query_options
|
|
245
272
|
@service.execute_streaming_sql(
|
|
246
|
-
@
|
|
273
|
+
@session_name,
|
|
247
274
|
@sql,
|
|
248
275
|
**@execute_query_options.merge(resume_token: resume_token)
|
|
249
276
|
)
|
|
250
277
|
else
|
|
251
278
|
@service.streaming_read_table(
|
|
252
|
-
@
|
|
279
|
+
@session_name,
|
|
253
280
|
@table,
|
|
254
281
|
@columns,
|
|
255
282
|
**@read_options.merge(resume_token: resume_token)
|
|
@@ -262,9 +289,9 @@ module Google
|
|
|
262
289
|
# Retries a request, by re-executing it from scratch.
|
|
263
290
|
def retry_request
|
|
264
291
|
if @execute_query_options
|
|
265
|
-
@service.execute_streaming_sql @
|
|
292
|
+
@service.execute_streaming_sql @session_name, @sql, **@execute_query_options
|
|
266
293
|
else
|
|
267
|
-
@service.streaming_read_table @
|
|
294
|
+
@service.streaming_read_table @session_name, @table, @columns, **@read_options
|
|
268
295
|
end
|
|
269
296
|
end
|
|
270
297
|
|
|
@@ -295,35 +322,80 @@ module Google
|
|
|
295
322
|
@stats.row_count == :row_count_exact
|
|
296
323
|
end
|
|
297
324
|
|
|
325
|
+
# Creates a `Spanner::Results` for a given `PartialResultSet` grpc stream.
|
|
326
|
+
# @param partial_result_sets [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>]
|
|
327
|
+
# Raw enumerable from underlying grpc call.
|
|
328
|
+
# @param service [::Google::Cloud::Spanner::Service] The `Spanner::Service` reference.
|
|
329
|
+
# @param session_name [::String] Required.
|
|
330
|
+
# The session in which the transaction to be committed is running.
|
|
331
|
+
# Values are of the form:
|
|
332
|
+
# `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
|
|
298
333
|
# @private
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
end
|
|
334
|
+
# @return [::Google::Cloud::Spanner::Results]
|
|
335
|
+
def self.from_partial_result_sets partial_result_sets, service, session_name
|
|
336
|
+
# @type [::Google::Cloud::Spanner::V1::PartialResultSet]
|
|
337
|
+
partial_result_set = partial_result_sets.peek
|
|
338
|
+
metadata = partial_result_set.metadata
|
|
339
|
+
stats = partial_result_set.stats
|
|
340
|
+
new service, partial_result_sets, session_name, metadata, stats
|
|
307
341
|
rescue GRPC::BadStatus => e
|
|
308
342
|
raise Google::Cloud::Error.from_error(e)
|
|
309
343
|
end
|
|
310
344
|
|
|
345
|
+
# Creates a `Spanner::Results` wrapper from ExecuteStreamingSql call results and params.
|
|
346
|
+
# @param response [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>]
|
|
347
|
+
# Raw enumerable from grpc `ExecuteStreamingSql` call.
|
|
348
|
+
# @param service [::Google::Cloud::Spanner::Service] The `Spanner::Service` reference.
|
|
349
|
+
# @param session_name [::String] Required.
|
|
350
|
+
# The session in which the transaction to be committed is running.
|
|
351
|
+
# Values are of the form:
|
|
352
|
+
# `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
|
|
353
|
+
# @param sql [::String] The SQL query string that was executed.
|
|
354
|
+
# @param execute_query_options [::Hash] Full request options
|
|
355
|
+
# that were sent to the `service.execute_streaming_sql`. This hash joins params needed to
|
|
356
|
+
# construct `::Gapic::CallOptions`, e.g. `call_options` and header-related `route_to_leader`
|
|
357
|
+
# with params specific to `execute_streaming_sql`, such as `seqno`.
|
|
311
358
|
# @private
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
359
|
+
# @return [::Google::Cloud::Spanner::Results]
|
|
360
|
+
def self.from_execute_query_response response, service, session_name, sql, execute_query_options
|
|
361
|
+
from_partial_result_sets(response, service, session_name).tap do |results|
|
|
362
|
+
execute_query_options_copy = execute_query_options.dup
|
|
363
|
+
unless results.metadata.transaction.nil?
|
|
364
|
+
execute_query_options_copy[:transaction] = V1::TransactionSelector.new id: results.metadata.transaction.id
|
|
365
|
+
end
|
|
366
|
+
|
|
315
367
|
results.instance_variable_set :@sql, sql
|
|
316
|
-
results.instance_variable_set :@execute_query_options,
|
|
368
|
+
results.instance_variable_set :@execute_query_options, execute_query_options_copy
|
|
317
369
|
end
|
|
318
370
|
end
|
|
319
371
|
|
|
372
|
+
# Creates a `Spanner::Results` wrapper from StreamingRead call results and params.
|
|
373
|
+
# @param response [::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>]
|
|
374
|
+
# Raw enumerable from grpc `StreamingRead` call.
|
|
375
|
+
# @param service [::Google::Cloud::Spanner::Service] The `Spanner::Service` reference.
|
|
376
|
+
# @param session_name [::String] Required.
|
|
377
|
+
# The session in which the transaction to be committed is running.
|
|
378
|
+
# Values are of the form:
|
|
379
|
+
# `projects/<project_id>/instances/<instance_id>/databases/<database_id>/sessions/<session_id>`.
|
|
380
|
+
# @param table [::String] The name of the table in the database that was read by `StreamingRead` request.
|
|
381
|
+
# @param columns [::Array<String, Symbol>] The columns of table that were returned
|
|
382
|
+
# by the `StreamingRead` request.
|
|
383
|
+
# @param read_options [::Hash] Full request options
|
|
384
|
+
# that were sent to the `service.streaming_read_table`. This hash joins params needed to
|
|
385
|
+
# construct `::Gapic::CallOptions`, e.g. `call_options` and header-related `route_to_leader`
|
|
386
|
+
# with params specific to `streaming_read_table`, such as `keys`.
|
|
320
387
|
# @private
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
388
|
+
# @return [::Google::Cloud::Spanner::Results]
|
|
389
|
+
def self.from_read_response response, service, session_name, table, columns, read_options
|
|
390
|
+
from_partial_result_sets(response, service, session_name).tap do |results|
|
|
391
|
+
read_options_copy = read_options.dup
|
|
392
|
+
unless results.metadata.transaction.nil?
|
|
393
|
+
read_options_copy[:transaction] = V1::TransactionSelector.new id: results.metadata.transaction.id
|
|
394
|
+
end
|
|
395
|
+
|
|
324
396
|
results.instance_variable_set :@table, table
|
|
325
397
|
results.instance_variable_set :@columns, columns
|
|
326
|
-
results.instance_variable_set :@read_options,
|
|
398
|
+
results.instance_variable_set :@read_options, read_options_copy
|
|
327
399
|
end
|
|
328
400
|
end
|
|
329
401
|
|
|
@@ -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
|
|