google-cloud-spanner 1.15.0 → 2.1.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 +49 -0
- data/CONTRIBUTING.md +5 -5
- data/TROUBLESHOOTING.md +0 -6
- data/lib/google-cloud-spanner.rb +10 -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 +315 -0
- data/lib/google/cloud/spanner/backup/job.rb +274 -0
- data/lib/google/cloud/spanner/backup/job/list.rb +177 -0
- data/lib/google/cloud/spanner/backup/list.rb +169 -0
- data/lib/google/cloud/spanner/backup/restore/job.rb +246 -0
- 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 +7 -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 +275 -15
- data/lib/google/cloud/spanner/database/backup_info.rb +105 -0
- data/lib/google/cloud/spanner/database/job.rb +5 -2
- data/lib/google/cloud/spanner/database/job/list.rb +177 -0
- data/lib/google/cloud/spanner/database/list.rb +1 -1
- data/lib/google/cloud/spanner/database/restore_info.rb +63 -0
- data/lib/google/cloud/spanner/fields.rb +8 -8
- data/lib/google/cloud/spanner/instance.rb +401 -8
- 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 +9 -6
- data/lib/google/cloud/spanner/service.rb +392 -302
- 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 +28 -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
@@ -0,0 +1,169 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
require "delegate"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module Spanner
|
21
|
+
class Backup
|
22
|
+
##
|
23
|
+
# # List
|
24
|
+
#
|
25
|
+
# Google::Cloud::Spanner::Backup::List is a special case Array with
|
26
|
+
# additional values.
|
27
|
+
#
|
28
|
+
class List < DelegateClass(::Array)
|
29
|
+
# @private
|
30
|
+
# The gRPC Service object.
|
31
|
+
attr_accessor :service
|
32
|
+
|
33
|
+
# @private
|
34
|
+
# The gRPC page enumerable object.
|
35
|
+
attr_accessor :grpc
|
36
|
+
|
37
|
+
##
|
38
|
+
# @private Create a new Backup::List with an array of
|
39
|
+
# Backup instances.
|
40
|
+
def initialize arr = []
|
41
|
+
super arr
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Whether there is a next page of backups.
|
46
|
+
#
|
47
|
+
# @return [Boolean]
|
48
|
+
#
|
49
|
+
# @example
|
50
|
+
# require "google/cloud/spanner"
|
51
|
+
#
|
52
|
+
# spanner = Google::Cloud::Spanner.new
|
53
|
+
#
|
54
|
+
# instance = spanner.instance "my-instance"
|
55
|
+
# backups = instance.backups
|
56
|
+
#
|
57
|
+
# if backups.next?
|
58
|
+
# next_backups = backups.next
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
def next?
|
62
|
+
grpc.next_page?
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# Retrieve the next page of backups.
|
67
|
+
#
|
68
|
+
# @return [Google::Cloud::Spanner::Backup::List]
|
69
|
+
#
|
70
|
+
# @example
|
71
|
+
# require "google/cloud/spanner"
|
72
|
+
#
|
73
|
+
# spanner = Google::Cloud::Spanner.new
|
74
|
+
#
|
75
|
+
# instance = spanner.instance "my-instance"
|
76
|
+
# backups = instance.backups
|
77
|
+
|
78
|
+
# if backups.next?
|
79
|
+
# next_backups = backups.next
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
def next
|
83
|
+
ensure_service!
|
84
|
+
|
85
|
+
return nil unless next?
|
86
|
+
grpc.next_page
|
87
|
+
self.class.from_grpc grpc, service
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Retrieves remaining results by repeatedly invoking {#next} until
|
92
|
+
# {#next?} returns `false`. Calls the given block once for each
|
93
|
+
# result, which is passed as the argument to the block.
|
94
|
+
#
|
95
|
+
# An Enumerator is returned if no block is given.
|
96
|
+
#
|
97
|
+
# This method will make repeated API calls until all remaining results
|
98
|
+
# are retrieved. (Unlike `#each`, for example, which merely iterates
|
99
|
+
# over the results returned by a single API call.) Use with caution.
|
100
|
+
#
|
101
|
+
# @yield [backup] The block for accessing each backup.
|
102
|
+
# @yieldparam [Google::Cloud::Spanner::Backup] backup The backup
|
103
|
+
# object.
|
104
|
+
#
|
105
|
+
# @return [Enumerator]
|
106
|
+
#
|
107
|
+
# @example Iterating each backup by passing a block:
|
108
|
+
# require "google/cloud/spanner"
|
109
|
+
#
|
110
|
+
# spanner = Google::Cloud::Spanner.new
|
111
|
+
#
|
112
|
+
# instance = spanner.instance "my-instance"
|
113
|
+
# backups = instance.backups
|
114
|
+
#
|
115
|
+
# backups.all do |backup|
|
116
|
+
# puts backup.backup_id
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
# @example Using the enumerator by not passing a block:
|
120
|
+
# require "google/cloud/spanner"
|
121
|
+
#
|
122
|
+
# spanner = Google::Cloud::Spanner.new
|
123
|
+
#
|
124
|
+
# instance = spanner.instance "my-instance"
|
125
|
+
# backups = instance.backups
|
126
|
+
#
|
127
|
+
# all_backup_ids = backups.all.map do |backup|
|
128
|
+
# backup.backup_id
|
129
|
+
# end
|
130
|
+
#
|
131
|
+
def all
|
132
|
+
return enum_for :all unless block_given?
|
133
|
+
|
134
|
+
results = self
|
135
|
+
loop do
|
136
|
+
results.each { |r| yield r }
|
137
|
+
break unless next?
|
138
|
+
grpc.next_page
|
139
|
+
results = self.class.from_grpc grpc, service
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# @private
|
145
|
+
# New Backup::List from a
|
146
|
+
# `Gapic::PagedEnumerable<Google::Cloud::Spanner::Admin::Database::V1::Backup>`
|
147
|
+
# object.
|
148
|
+
def self.from_grpc grpc, service
|
149
|
+
backups = List.new(Array(grpc.response.backups).map do |backup|
|
150
|
+
Backup.from_grpc backup, service
|
151
|
+
end)
|
152
|
+
|
153
|
+
backups.grpc = grpc
|
154
|
+
backups.service = service
|
155
|
+
backups
|
156
|
+
end
|
157
|
+
|
158
|
+
protected
|
159
|
+
|
160
|
+
##
|
161
|
+
# Raise an error unless an active service is available.
|
162
|
+
def ensure_service!
|
163
|
+
raise "Must have active connection" unless @service
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,246 @@
|
|
1
|
+
# Copyright 2020 Google LLC
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
|
16
|
+
require "google/cloud/spanner/status"
|
17
|
+
|
18
|
+
module Google
|
19
|
+
module Cloud
|
20
|
+
module Spanner
|
21
|
+
class Backup
|
22
|
+
class Restore
|
23
|
+
##
|
24
|
+
# # Job
|
25
|
+
#
|
26
|
+
# A resource representing the long-running, asynchronous processing of
|
27
|
+
# a backup restore. The job can be refreshed to retrieve the restored
|
28
|
+
# database object once the operation has been completed.
|
29
|
+
#
|
30
|
+
# See {Backup#restore}
|
31
|
+
#
|
32
|
+
# @see https://cloud.google.com/spanner/reference/rpc/google.longrunning#google.longrunning.Operation
|
33
|
+
# Long-running Operation
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# require "google/cloud/spanner"
|
37
|
+
#
|
38
|
+
# spanner = Google::Cloud::Spanner.new
|
39
|
+
#
|
40
|
+
# instance = spanner.instance "my-instance"
|
41
|
+
# backup = instance.backup "my-backup"
|
42
|
+
# job = backup.restore "my-restored-database"
|
43
|
+
#
|
44
|
+
# job.done? #=> false
|
45
|
+
# job.reload! # API call
|
46
|
+
# job.done? #=> true
|
47
|
+
#
|
48
|
+
# if job.error?
|
49
|
+
# status = job.error
|
50
|
+
# else
|
51
|
+
# database = job.database
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
class Job
|
55
|
+
##
|
56
|
+
# @private The `Gapic::Operation` gRPC object.
|
57
|
+
attr_accessor :grpc
|
58
|
+
|
59
|
+
##
|
60
|
+
# @private The gRPC Service object.
|
61
|
+
attr_accessor :service
|
62
|
+
|
63
|
+
##
|
64
|
+
# @private Creates a new Restore::Job instance.
|
65
|
+
def initialize
|
66
|
+
@grpc = nil
|
67
|
+
@service = nil
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# The database is the object of the operation.
|
72
|
+
#
|
73
|
+
# @return [Database, nil] The database instance, or
|
74
|
+
# `nil` if the operation is not complete.
|
75
|
+
#
|
76
|
+
# @example
|
77
|
+
# require "google/cloud/spanner"
|
78
|
+
#
|
79
|
+
# spanner = Google::Cloud::Spanner.new
|
80
|
+
#
|
81
|
+
# instance = spanner.instance "my-instance"
|
82
|
+
# backup = instance.backup "my-backup"
|
83
|
+
# job = backup.restore "my-restored-database"
|
84
|
+
#
|
85
|
+
# job.done? #=> false
|
86
|
+
# job.reload!
|
87
|
+
# job.done? #=> true
|
88
|
+
# database = job.database
|
89
|
+
#
|
90
|
+
def database
|
91
|
+
return nil unless done?
|
92
|
+
return nil unless @grpc.grpc_op.result == :response
|
93
|
+
Database.from_grpc @grpc.results, service
|
94
|
+
end
|
95
|
+
|
96
|
+
##
|
97
|
+
# Checks if the processing of the restore operation is complete.
|
98
|
+
#
|
99
|
+
# @return [boolean] `true` when complete, `false` otherwise.
|
100
|
+
#
|
101
|
+
# @example
|
102
|
+
# require "google/cloud/spanner"
|
103
|
+
#
|
104
|
+
# spanner = Google::Cloud::Spanner.new
|
105
|
+
#
|
106
|
+
# instance = spanner.instance "my-instance"
|
107
|
+
# backup = instance.backup "my-backup"
|
108
|
+
# job = backup.restore "my-restored-database"
|
109
|
+
#
|
110
|
+
# job.done? #=> false
|
111
|
+
#
|
112
|
+
def done?
|
113
|
+
@grpc.done?
|
114
|
+
end
|
115
|
+
|
116
|
+
##
|
117
|
+
# Checks if the processing of the restore operation has errored.
|
118
|
+
#
|
119
|
+
# @return [boolean] `true` when errored, `false` otherwise.
|
120
|
+
#
|
121
|
+
# @example
|
122
|
+
# require "google/cloud/spanner"
|
123
|
+
#
|
124
|
+
# spanner = Google::Cloud::Spanner.new
|
125
|
+
#
|
126
|
+
# instance = spanner.instance "my-instance"
|
127
|
+
# backup = instance.backup "my-backup"
|
128
|
+
# job = backup.restore "my-restored-database"
|
129
|
+
#
|
130
|
+
# job.error? #=> false
|
131
|
+
#
|
132
|
+
def error?
|
133
|
+
@grpc.error?
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# The status if the operation associated with this job produced an
|
138
|
+
# error.
|
139
|
+
#
|
140
|
+
# @return [Google::Cloud::Spanner::Status, nil] A status object with
|
141
|
+
# the status code and message, or `nil` if no error occurred.
|
142
|
+
#
|
143
|
+
# @example
|
144
|
+
# require "google/cloud/spanner"
|
145
|
+
#
|
146
|
+
# spanner = Google::Cloud::Spanner.new
|
147
|
+
#
|
148
|
+
# instance = spanner.instance "my-instance"
|
149
|
+
# backup = instance.backup "my-backup"
|
150
|
+
# job = backup.restore "my-restored-database"
|
151
|
+
#
|
152
|
+
# job.error? # true
|
153
|
+
#
|
154
|
+
# error = job.error
|
155
|
+
#
|
156
|
+
def error
|
157
|
+
return nil unless error?
|
158
|
+
Google::Cloud::Spanner::Status.from_grpc @grpc.error
|
159
|
+
end
|
160
|
+
|
161
|
+
##
|
162
|
+
# Reloads the job with current data from the long-running,
|
163
|
+
# asynchronous processing of a restore operation.
|
164
|
+
#
|
165
|
+
# @return [Backup::Job] The same job instance.
|
166
|
+
#
|
167
|
+
# @example
|
168
|
+
# require "google/cloud/spanner"
|
169
|
+
#
|
170
|
+
# spanner = Google::Cloud::Spanner.new
|
171
|
+
#
|
172
|
+
# instance = spanner.instance "my-instance"
|
173
|
+
# backup = instance.backup "my-backup"
|
174
|
+
# job = backup.restore "my-restored-database"
|
175
|
+
#
|
176
|
+
# job.done? #=> false
|
177
|
+
# job.reload! # API call
|
178
|
+
# job.done? #=> true
|
179
|
+
#
|
180
|
+
def reload!
|
181
|
+
@grpc.reload!
|
182
|
+
self
|
183
|
+
end
|
184
|
+
alias refresh! reload!
|
185
|
+
|
186
|
+
##
|
187
|
+
# Reloads the job until the operation is complete. The delay between
|
188
|
+
# reloads will incrementally increase.
|
189
|
+
#
|
190
|
+
# @example
|
191
|
+
# require "google/cloud/spanner"
|
192
|
+
#
|
193
|
+
# spanner = Google::Cloud::Spanner.new
|
194
|
+
#
|
195
|
+
# instance = spanner.instance "my-instance"
|
196
|
+
# backup = instance.backup "my-backup"
|
197
|
+
# job = backup.restore "my-restored-database"
|
198
|
+
#
|
199
|
+
# job.done? #=> false
|
200
|
+
# job.wait_until_done!
|
201
|
+
# job.done? #=> true
|
202
|
+
#
|
203
|
+
def wait_until_done!
|
204
|
+
@grpc.wait_until_done!
|
205
|
+
end
|
206
|
+
|
207
|
+
##
|
208
|
+
# The operation progress in percentage.
|
209
|
+
#
|
210
|
+
# @return [Integer]
|
211
|
+
def progress_percent
|
212
|
+
@grpc.metadata.progress.progress_percent
|
213
|
+
end
|
214
|
+
|
215
|
+
##
|
216
|
+
# The operation start time.
|
217
|
+
#
|
218
|
+
# @return [Time, nil]
|
219
|
+
def start_time
|
220
|
+
return nil unless @grpc.metadata.progress.start_time
|
221
|
+
Convert.timestamp_to_time @grpc.metadata.progress.start_time
|
222
|
+
end
|
223
|
+
|
224
|
+
##
|
225
|
+
# The operation end time.
|
226
|
+
#
|
227
|
+
# @return [Time, nil]
|
228
|
+
def end_time
|
229
|
+
return nil unless @grpc.metadata.progress.end_time
|
230
|
+
Convert.timestamp_to_time @grpc.metadata.progress.end_time
|
231
|
+
end
|
232
|
+
|
233
|
+
##
|
234
|
+
# @private New Restore::Job from a `Gapic::Operation` object.
|
235
|
+
def self.from_grpc grpc, service
|
236
|
+
new.tap do |job|
|
237
|
+
job.instance_variable_set :@grpc, grpc
|
238
|
+
job.instance_variable_set :@service, service
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
@@ -407,8 +407,8 @@ module Google
|
|
407
407
|
def session
|
408
408
|
ensure_service!
|
409
409
|
grpc = @project.service.create_session \
|
410
|
-
|
411
|
-
project_id, instance_id, database_id
|
410
|
+
V1::Spanner::Paths.database_path(
|
411
|
+
project: project_id, instance: instance_id, database: database_id
|
412
412
|
),
|
413
413
|
labels: @session_labels
|
414
414
|
Session.from_grpc grpc, @project.service, query_options: @query_options
|
@@ -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,10 +217,11 @@ 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
|
-
execute_sql_grpc =
|
224
|
+
execute_sql_grpc = V1::ExecuteSqlRequest.new(
|
211
225
|
{
|
212
226
|
session: session.path,
|
213
227
|
sql: sql,
|
@@ -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,11 +306,12 @@ 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
|
285
|
-
read_grpc =
|
314
|
+
read_grpc = V1::ReadRequest.new(
|
286
315
|
{
|
287
316
|
session: session.path,
|
288
317
|
table: table,
|
@@ -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
|
##
|
@@ -663,17 +760,15 @@ module Google
|
|
663
760
|
def self.load data, service: nil, query_options: nil
|
664
761
|
data = JSON.parse data, symbolize_names: true unless data.is_a? Hash
|
665
762
|
|
666
|
-
session_grpc =
|
667
|
-
|
668
|
-
transaction_grpc = Google::Spanner::V1::Transaction.decode \
|
669
|
-
Base64.decode64(data[:transaction])
|
763
|
+
session_grpc = V1::Session.decode Base64.decode64(data[:session])
|
764
|
+
transaction_grpc = V1::Transaction.decode Base64.decode64(data[:transaction])
|
670
765
|
|
671
766
|
from_grpc transaction_grpc, Session.from_grpc(session_grpc, service, query_options: query_options)
|
672
767
|
end
|
673
768
|
|
674
769
|
##
|
675
770
|
# @private Creates a new BatchSnapshot instance from a
|
676
|
-
# Google::Spanner::V1::Transaction
|
771
|
+
# `Google::Cloud::Spanner::V1::Transaction`.
|
677
772
|
def self.from_grpc grpc, session
|
678
773
|
new grpc, session
|
679
774
|
end
|
@@ -682,7 +777,7 @@ module Google
|
|
682
777
|
|
683
778
|
# The TransactionSelector to be used for queries
|
684
779
|
def tx_selector
|
685
|
-
|
780
|
+
V1::TransactionSelector.new id: transaction_id
|
686
781
|
end
|
687
782
|
|
688
783
|
##
|
@@ -692,7 +787,7 @@ module Google
|
|
692
787
|
raise "Must have active connection to service" unless session
|
693
788
|
end
|
694
789
|
|
695
|
-
def execute_partition_query partition
|
790
|
+
def execute_partition_query partition, call_options: nil
|
696
791
|
query_options = partition.execute.query_options
|
697
792
|
query_options = query_options.to_h unless query_options.nil?
|
698
793
|
session.execute_query \
|
@@ -701,16 +796,18 @@ module Google
|
|
701
796
|
types: partition.execute.param_types.to_h,
|
702
797
|
transaction: partition.execute.transaction,
|
703
798
|
partition_token: partition.execute.partition_token,
|
704
|
-
query_options: query_options
|
799
|
+
query_options: query_options,
|
800
|
+
call_options: call_options
|
705
801
|
end
|
706
802
|
|
707
|
-
def execute_partition_read partition
|
803
|
+
def execute_partition_read partition, call_options: nil
|
708
804
|
session.read partition.read.table,
|
709
805
|
partition.read.columns.to_a,
|
710
806
|
keys: partition.read.key_set,
|
711
807
|
index: partition.read.index,
|
712
808
|
transaction: partition.read.transaction,
|
713
|
-
partition_token: partition.read.partition_token
|
809
|
+
partition_token: partition.read.partition_token,
|
810
|
+
call_options: call_options
|
714
811
|
end
|
715
812
|
end
|
716
813
|
end
|