google-cloud-bigtable 0.6.1 → 1.0.1
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/AUTHENTICATION.md +4 -26
- data/CHANGELOG.md +85 -0
- data/CONTRIBUTING.md +1 -1
- data/OVERVIEW.md +388 -19
- data/lib/google-cloud-bigtable.rb +19 -22
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +1 -1
- data/lib/google/bigtable/v2/bigtable_pb.rb +3 -0
- data/lib/google/bigtable/v2/bigtable_services_pb.rb +1 -1
- data/lib/google/cloud/bigtable.rb +11 -17
- data/lib/google/cloud/bigtable/admin.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +42 -21
- data/lib/google/cloud/bigtable/app_profile.rb +162 -96
- data/lib/google/cloud/bigtable/app_profile/job.rb +5 -8
- data/lib/google/cloud/bigtable/app_profile/list.rb +18 -12
- data/lib/google/cloud/bigtable/chunk_processor.rb +24 -36
- data/lib/google/cloud/bigtable/cluster.rb +45 -18
- data/lib/google/cloud/bigtable/cluster/job.rb +3 -7
- data/lib/google/cloud/bigtable/cluster/list.rb +22 -20
- data/lib/google/cloud/bigtable/column_family.rb +18 -231
- data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
- data/lib/google/cloud/bigtable/column_range.rb +15 -7
- data/lib/google/cloud/bigtable/convert.rb +12 -4
- data/lib/google/cloud/bigtable/errors.rb +4 -1
- data/lib/google/cloud/bigtable/gc_rule.rb +188 -69
- data/lib/google/cloud/bigtable/instance.rb +209 -189
- data/lib/google/cloud/bigtable/instance/cluster_map.rb +17 -13
- data/lib/google/cloud/bigtable/instance/job.rb +6 -5
- data/lib/google/cloud/bigtable/instance/list.rb +18 -13
- data/lib/google/cloud/bigtable/longrunning_job.rb +7 -1
- data/lib/google/cloud/bigtable/mutation_entry.rb +36 -39
- data/lib/google/cloud/bigtable/mutation_operations.rb +90 -73
- data/lib/google/cloud/bigtable/policy.rb +9 -5
- data/lib/google/cloud/bigtable/project.rb +87 -196
- data/lib/google/cloud/bigtable/read_modify_write_rule.rb +15 -10
- data/lib/google/cloud/bigtable/read_operations.rb +42 -59
- data/lib/google/cloud/bigtable/routing_policy.rb +172 -0
- data/lib/google/cloud/bigtable/row.rb +32 -21
- data/lib/google/cloud/bigtable/row_filter.rb +80 -35
- data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +119 -68
- data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +8 -2
- data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +117 -66
- data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +24 -9
- data/lib/google/cloud/bigtable/row_range.rb +5 -0
- data/lib/google/cloud/bigtable/rows_mutator.rb +14 -21
- data/lib/google/cloud/bigtable/rows_reader.rb +23 -18
- data/lib/google/cloud/bigtable/sample_row_key.rb +6 -3
- data/lib/google/cloud/bigtable/service.rb +200 -253
- data/lib/google/cloud/bigtable/status.rb +76 -0
- data/lib/google/cloud/bigtable/table.rb +158 -262
- data/lib/google/cloud/bigtable/table/cluster_state.rb +17 -6
- data/lib/google/cloud/bigtable/table/list.rb +16 -9
- data/lib/google/cloud/bigtable/v2.rb +1 -1
- data/lib/google/cloud/bigtable/v2/bigtable_client.rb +12 -12
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +16 -13
- data/lib/google/cloud/bigtable/value_range.rb +19 -13
- data/lib/google/cloud/bigtable/version.rb +1 -1
- metadata +67 -25
- data/lib/google/cloud/bigtable/table/column_family_map.rb +0 -70
@@ -0,0 +1,76 @@
|
|
1
|
+
# Copyright 2019 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
|
+
module Google
|
17
|
+
module Cloud
|
18
|
+
module Bigtable
|
19
|
+
##
|
20
|
+
# # Status
|
21
|
+
#
|
22
|
+
# Represents a logical error model from the Bigtable service, containing an
|
23
|
+
# error code, an error message, and optional error details.
|
24
|
+
#
|
25
|
+
# @attr [Integer] code The status code, which should be an enum value of
|
26
|
+
# [google.rpc.Code](https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto).
|
27
|
+
# @attr [String] description The human-readable description for the status code, which should be an enum value of
|
28
|
+
# [google.rpc.Code](https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto). For example,
|
29
|
+
# `INVALID_ARGUMENT`.
|
30
|
+
# @attr [String] message A developer-facing error message, which should be in English.
|
31
|
+
# @attr [Array<String>] details A list of messages that carry the error details.
|
32
|
+
#
|
33
|
+
# @example
|
34
|
+
# require "google/cloud/bigtable"
|
35
|
+
#
|
36
|
+
# bigtable = Google::Cloud::Bigtable.new
|
37
|
+
#
|
38
|
+
# table = bigtable.table("my-instance", "my-table")
|
39
|
+
#
|
40
|
+
# entries = []
|
41
|
+
# entries << table.new_mutation_entry("row-1").set_cell("cf1", "field1", "XYZ")
|
42
|
+
# entries << table.new_mutation_entry("row-2").set_cell("cf1", "field1", "ABC")
|
43
|
+
# responses = table.mutate_rows(entries)
|
44
|
+
#
|
45
|
+
# responses.each do |response|
|
46
|
+
# puts response.status.description
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
class Status
|
50
|
+
attr_reader :code, :description, :message, :details
|
51
|
+
|
52
|
+
##
|
53
|
+
# @private Creates a Status object.
|
54
|
+
def initialize code, description, message, details
|
55
|
+
@code = code
|
56
|
+
@description = description
|
57
|
+
@message = message
|
58
|
+
@details = details
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# @private New Status from a Google::Rpc::Status object.
|
63
|
+
def self.from_grpc grpc
|
64
|
+
new grpc.code, description_for(grpc.code), grpc.message, grpc.details
|
65
|
+
end
|
66
|
+
|
67
|
+
# @private Get a descriptive symbol for a google.rpc.Code integer
|
68
|
+
def self.description_for code
|
69
|
+
["OK", "CANCELLED", "UNKNOWN", "INVALID_ARGUMENT", "DEADLINE_EXCEEDED", "NOT_FOUND", "ALREADY_EXISTS",
|
70
|
+
"PERMISSION_DENIED", "RESOURCE_EXHAUSTED", "FAILED_PRECONDITION", "ABORTED", "OUT_OF_RANGE", "UNIMPLEMENTED",
|
71
|
+
"INTERNAL", "UNAVAILABLE", "DATA_LOSS", "UNAUTHENTICATED"][code]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -17,8 +17,7 @@
|
|
17
17
|
|
18
18
|
require "google/cloud/bigtable/table/list"
|
19
19
|
require "google/cloud/bigtable/table/cluster_state"
|
20
|
-
require "google/cloud/bigtable/
|
21
|
-
require "google/cloud/bigtable/table/column_family_map"
|
20
|
+
require "google/cloud/bigtable/column_family_map"
|
22
21
|
require "google/cloud/bigtable/gc_rule"
|
23
22
|
require "google/cloud/bigtable/mutation_operations"
|
24
23
|
require "google/cloud/bigtable/read_operations"
|
@@ -26,6 +25,7 @@ require "google/cloud/bigtable/read_operations"
|
|
26
25
|
module Google
|
27
26
|
module Cloud
|
28
27
|
module Bigtable
|
28
|
+
##
|
29
29
|
# # Table
|
30
30
|
#
|
31
31
|
# A collection of user data indexed by row, column, and timestamp.
|
@@ -36,23 +36,14 @@ module Google
|
|
36
36
|
#
|
37
37
|
# bigtable = Google::Cloud::Bigtable.new
|
38
38
|
#
|
39
|
-
# table = bigtable.table("my-instance", "my-table"
|
39
|
+
# table = bigtable.table("my-instance", "my-table")
|
40
40
|
#
|
41
|
-
# table.
|
42
|
-
# p
|
43
|
-
#
|
41
|
+
# if table.exists?
|
42
|
+
# p "Table exists."
|
43
|
+
# else
|
44
|
+
# p "Table does not exist"
|
44
45
|
# end
|
45
46
|
#
|
46
|
-
# # Get column family by name
|
47
|
-
# cf1 = table.column_families.find_by_name("cf1")
|
48
|
-
#
|
49
|
-
# # Create column family
|
50
|
-
# gc_rule = Google::Cloud::Bigtable::GcRule.max_versions(3)
|
51
|
-
# cf2 = table.column_families.create("cf2", gc_rule)
|
52
|
-
#
|
53
|
-
# # Delete table
|
54
|
-
# table.delete
|
55
|
-
#
|
56
47
|
class Table
|
57
48
|
# @!parse extend MutationOperations
|
58
49
|
include MutationOperations
|
@@ -64,7 +55,9 @@ module Google
|
|
64
55
|
# The gRPC Service object.
|
65
56
|
attr_accessor :service
|
66
57
|
|
58
|
+
##
|
67
59
|
# @return [String] App profile ID for request routing.
|
60
|
+
#
|
68
61
|
attr_accessor :app_profile_id
|
69
62
|
|
70
63
|
# @private
|
@@ -76,100 +69,168 @@ module Google
|
|
76
69
|
@view = view || :SCHEMA_VIEW
|
77
70
|
end
|
78
71
|
|
79
|
-
|
72
|
+
##
|
73
|
+
# The unique identifier for the project to which the table belongs.
|
80
74
|
#
|
81
75
|
# @return [String]
|
76
|
+
#
|
82
77
|
def project_id
|
83
78
|
@grpc.name.split("/")[1]
|
84
79
|
end
|
85
80
|
|
86
|
-
|
81
|
+
##
|
82
|
+
# The unique identifier for the instance to which the table belongs.
|
87
83
|
#
|
88
84
|
# @return [String]
|
85
|
+
#
|
89
86
|
def instance_id
|
90
87
|
@grpc.name.split("/")[3]
|
91
88
|
end
|
92
89
|
|
90
|
+
##
|
93
91
|
# The unique identifier for the table.
|
94
92
|
#
|
95
93
|
# @return [String]
|
94
|
+
#
|
96
95
|
def name
|
97
96
|
@grpc.name.split("/")[5]
|
98
97
|
end
|
99
98
|
alias table_id name
|
100
99
|
|
100
|
+
##
|
101
101
|
# The full path for the table resource. Values are of the form
|
102
102
|
# `projects/<project_id>/instances/<instance_id>/table/<table_id>`.
|
103
103
|
#
|
104
104
|
# @return [String]
|
105
|
+
#
|
105
106
|
def path
|
106
107
|
@grpc.name
|
107
108
|
end
|
108
109
|
|
109
|
-
|
110
|
+
##
|
111
|
+
# Reloads table data.
|
110
112
|
#
|
111
113
|
# @param view [Symbol] Table view type.
|
112
|
-
# Default view type is `:SCHEMA_VIEW
|
114
|
+
# Default view type is `:SCHEMA_VIEW`.
|
113
115
|
# Valid view types are:
|
114
116
|
#
|
115
|
-
# * `:NAME_ONLY` - Only populates `name
|
116
|
-
# * `:SCHEMA_VIEW` - Only populates `name` and fields related to the table's schema
|
117
|
+
# * `:NAME_ONLY` - Only populates `name`.
|
118
|
+
# * `:SCHEMA_VIEW` - Only populates `name` and fields related to the table's schema.
|
117
119
|
# * `:REPLICATION_VIEW` - Only populates `name` and fields related to the table's replication state.
|
118
|
-
# * `:FULL` - Populates all fields
|
120
|
+
# * `:FULL` - Populates all fields.
|
119
121
|
#
|
120
122
|
# @return [Google::Cloud::Bigtable::Table]
|
121
|
-
|
123
|
+
#
|
122
124
|
def reload! view: nil
|
123
125
|
@view = view || :SCHEMA_VIEW
|
124
|
-
@grpc = service.get_table
|
126
|
+
@grpc = service.get_table instance_id, name, view: view
|
125
127
|
self
|
126
128
|
end
|
127
129
|
|
130
|
+
##
|
128
131
|
# Map from cluster ID to per-cluster table state.
|
129
132
|
# If it could not be determined whether or not the table has data in a
|
130
133
|
# particular cluster (for example, if its zone is unavailable), then
|
131
134
|
# there will be an entry for the cluster with UNKNOWN `replication_status`.
|
132
|
-
# Views: `FULL
|
135
|
+
# Views: `FULL`.
|
133
136
|
#
|
134
137
|
# @return [Array<Google::Cloud::Bigtable::Table::ClusterState>]
|
138
|
+
#
|
135
139
|
def cluster_states
|
136
|
-
check_view_and_load
|
140
|
+
check_view_and_load :REPLICATION_VIEW
|
137
141
|
@grpc.cluster_states.map do |name, state_grpc|
|
138
|
-
ClusterState.from_grpc
|
142
|
+
ClusterState.from_grpc state_grpc, name
|
139
143
|
end
|
140
144
|
end
|
141
145
|
|
142
|
-
|
143
|
-
#
|
146
|
+
##
|
147
|
+
# Returns a frozen object containing the column families configured for
|
148
|
+
# the table, mapped by column family name. Reloads the table if
|
149
|
+
# necessary to retrieve the column families data, since it is only
|
150
|
+
# available in a table with view type `SCHEMA_VIEW` or `FULL`.
|
151
|
+
#
|
152
|
+
# Also accepts a block for making modifications to the table's column
|
153
|
+
# families. After the modifications are completed, the table will be
|
154
|
+
# updated with the changes, and the updated column families will be
|
155
|
+
# returned.
|
156
|
+
#
|
157
|
+
# @yield [column_families] A block for modifying the table's column
|
158
|
+
# families. Applies multiple column modifications. Performs a series
|
159
|
+
# of column family modifications on the specified table. Either all or
|
160
|
+
# none of the modifications will occur before this method returns, but
|
161
|
+
# data requests received prior to that point may see a table where
|
162
|
+
# only some modifications have taken effect.
|
163
|
+
# @yieldparam [ColumnFamilyMap] column_families
|
164
|
+
# A mutable object containing the column families for the table,
|
165
|
+
# mapped by column family name. Any changes made to this object will
|
166
|
+
# be stored in API.
|
167
|
+
#
|
168
|
+
# @return [ColumnFamilyMap] A frozen object containing the
|
169
|
+
# column families for the table, mapped by column family name.
|
170
|
+
#
|
171
|
+
# @example
|
172
|
+
# require "google/cloud/bigtable"
|
173
|
+
#
|
174
|
+
# bigtable = Google::Cloud::Bigtable.new
|
175
|
+
#
|
176
|
+
# table = bigtable.table("my-instance", "my-table", perform_lookup: true)
|
177
|
+
#
|
178
|
+
# table.column_families.each do |name, cf|
|
179
|
+
# puts name
|
180
|
+
# puts cf.gc_rule
|
181
|
+
# end
|
182
|
+
#
|
183
|
+
# # Get a column family by name
|
184
|
+
# cf1 = table.column_families["cf1"]
|
185
|
+
#
|
186
|
+
# @example Modify the table's column families
|
187
|
+
# require "google/cloud/bigtable"
|
188
|
+
#
|
189
|
+
# bigtable = Google::Cloud::Bigtable.new
|
190
|
+
#
|
191
|
+
# table = bigtable.table("my-instance", "my-table", perform_lookup: true)
|
192
|
+
#
|
193
|
+
# table.column_families do |cfm|
|
194
|
+
# cfm.add "cf4", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
|
195
|
+
# cfm.add "cf5", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)
|
196
|
+
#
|
197
|
+
# rule_1 = Google::Cloud::Bigtable::GcRule.max_versions(3)
|
198
|
+
# rule_2 = Google::Cloud::Bigtable::GcRule.max_age(600)
|
199
|
+
# rule_union = Google::Cloud::Bigtable::GcRule.union(rule_1, rule_2)
|
200
|
+
# cfm.update "cf2", gc_rule: rule_union
|
144
201
|
#
|
202
|
+
# cfm.delete "cf3"
|
203
|
+
# end
|
145
204
|
#
|
146
|
-
#
|
205
|
+
# puts table.column_families["cf3"] #=> nil
|
147
206
|
#
|
148
207
|
def column_families
|
149
|
-
check_view_and_load
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
table_id: table_id
|
157
|
-
)
|
208
|
+
check_view_and_load :SCHEMA_VIEW
|
209
|
+
|
210
|
+
if block_given?
|
211
|
+
column_families = ColumnFamilyMap.from_grpc @grpc.column_families
|
212
|
+
yield column_families
|
213
|
+
modifications = column_families.modifications @grpc.column_families
|
214
|
+
@grpc = service.modify_column_families instance_id, table_id, modifications if modifications.any?
|
158
215
|
end
|
216
|
+
|
217
|
+
ColumnFamilyMap.from_grpc(@grpc.column_families).freeze
|
159
218
|
end
|
160
219
|
|
220
|
+
##
|
161
221
|
# The granularity (e.g. `MILLIS`, `MICROS`) at which timestamps are stored in
|
162
222
|
# this table. Timestamps not matching the granularity will be rejected.
|
163
223
|
# If unspecified at creation time, the value will be set to `MILLIS`.
|
164
|
-
# Views: `SCHEMA_VIEW`, `FULL
|
224
|
+
# Views: `SCHEMA_VIEW`, `FULL`.
|
165
225
|
#
|
166
226
|
# @return [Symbol]
|
167
227
|
#
|
168
228
|
def granularity
|
169
|
-
check_view_and_load
|
229
|
+
check_view_and_load :SCHEMA_VIEW
|
170
230
|
@grpc.granularity
|
171
231
|
end
|
172
232
|
|
233
|
+
##
|
173
234
|
# The table keeps data versioned at a granularity of 1 ms.
|
174
235
|
#
|
175
236
|
# @return [Boolean]
|
@@ -178,6 +239,7 @@ module Google
|
|
178
239
|
granularity == :MILLIS
|
179
240
|
end
|
180
241
|
|
242
|
+
##
|
181
243
|
# Permanently deletes the table from a instance.
|
182
244
|
#
|
183
245
|
# @return [Boolean] Returns `true` if the table was deleted.
|
@@ -187,15 +249,16 @@ module Google
|
|
187
249
|
#
|
188
250
|
# bigtable = Google::Cloud::Bigtable.new
|
189
251
|
#
|
190
|
-
#
|
252
|
+
# table = bigtable.table("my-instance", "my-table")
|
191
253
|
# table.delete
|
192
254
|
#
|
193
255
|
def delete
|
194
256
|
ensure_service!
|
195
|
-
service.delete_table
|
257
|
+
service.delete_table instance_id, name
|
196
258
|
true
|
197
259
|
end
|
198
260
|
|
261
|
+
##
|
199
262
|
# Checks to see if the table exists.
|
200
263
|
#
|
201
264
|
# @return [Boolean]
|
@@ -219,7 +282,7 @@ module Google
|
|
219
282
|
# bigtable = Google::Cloud::Bigtable.new
|
220
283
|
#
|
221
284
|
# instance = bigtable.instance("my-instance")
|
222
|
-
# table =
|
285
|
+
# table = instance.table("my-table")
|
223
286
|
#
|
224
287
|
# if table.exists?
|
225
288
|
# p "Table exists."
|
@@ -227,205 +290,51 @@ module Google
|
|
227
290
|
# p "Table does not exist"
|
228
291
|
# end
|
229
292
|
#
|
230
|
-
|
231
293
|
def exists?
|
232
294
|
!service.get_table(instance_id, name, view: :NAME_ONLY).nil?
|
233
295
|
rescue Google::Cloud::NotFoundError
|
234
296
|
false
|
235
297
|
end
|
236
298
|
|
237
|
-
# Returns a column family object that can be used to perform create,
|
238
|
-
# update, or delete operations.
|
239
|
-
#
|
240
|
-
# @param name [String] Name of the column family
|
241
|
-
# @param gc_rule [Google::Cloud::Bigtable::GcRule] The garbage
|
242
|
-
# collection rule to be used for the column family. Optional. The
|
243
|
-
# service default value will be used when not specified.
|
244
|
-
#
|
245
|
-
# @example Create column family
|
246
|
-
# require "google/cloud/bigtable"
|
247
|
-
#
|
248
|
-
# bigtable = Google::Cloud::Bigtable.new
|
249
|
-
#
|
250
|
-
# table = bigtable.table("my-instance", my-table)
|
251
|
-
#
|
252
|
-
# # OR get table from Instance object.
|
253
|
-
# instance = bigtable.instance("my-instance")
|
254
|
-
# table = instance.table("my-table")
|
255
|
-
#
|
256
|
-
# gc_rule = Google::Cloud::Bigtable::GcRule.max_versions(5)
|
257
|
-
# column_family = table.column_family("cf1", gc_rule)
|
258
|
-
# column_family.create
|
259
|
-
#
|
260
|
-
# @example Update column family
|
261
|
-
# require "google/cloud/bigtable"
|
262
|
-
#
|
263
|
-
# bigtable = Google::Cloud::Bigtable.new
|
264
|
-
#
|
265
|
-
# table = bigtable.table("my-instance", "my-table")
|
266
|
-
#
|
267
|
-
# gc_rule = Google::Cloud::Bigtable::GcRule.max_age(1800)
|
268
|
-
# column_family = table.column_family("cf2", gc_rule)
|
269
|
-
# column_family.save
|
270
|
-
# # OR Using alias method update.
|
271
|
-
# column_family.update
|
272
|
-
#
|
273
|
-
# @example Delete column family
|
274
|
-
# require "google/cloud/bigtable"
|
275
|
-
#
|
276
|
-
# bigtable = Google::Cloud::Bigtable.new
|
277
|
-
#
|
278
|
-
# table = bigtable.table("my-instance", "my-table")
|
279
|
-
#
|
280
|
-
# column_family = table.column_family("cf3")
|
281
|
-
# column_family.delete
|
282
|
-
#
|
283
|
-
def column_family name, gc_rule = nil
|
284
|
-
cf_grpc = Google::Bigtable::Admin::V2::ColumnFamily.new
|
285
|
-
cf_grpc.gc_rule = gc_rule.to_grpc if gc_rule
|
286
|
-
|
287
|
-
ColumnFamily.from_grpc(
|
288
|
-
cf_grpc,
|
289
|
-
service,
|
290
|
-
name: name,
|
291
|
-
instance_id: instance_id,
|
292
|
-
table_id: table_id
|
293
|
-
)
|
294
|
-
end
|
295
|
-
|
296
|
-
# Applies multitple column modifications.
|
297
|
-
# Performs a series of column family modifications on the specified table.
|
298
|
-
# Either all or none of the modifications will occur before this method
|
299
|
-
# returns, but data requests received prior to that point may see a table
|
300
|
-
# where only some modifications have taken effect.
|
301
|
-
#
|
302
|
-
# @param modifications [Array<Google::Cloud::Bigtable::ColumnFamilyModification>]
|
303
|
-
# Modifications to be atomically applied to the specified table's families.
|
304
|
-
# Entries are applied in order, meaning that earlier modifications can be
|
305
|
-
# masked by later ones (in the case of repeated updates to the same family,
|
306
|
-
# for example).
|
307
|
-
# @return [Google::Cloud::Bigtable::Table] Table with updated column families.
|
308
|
-
#
|
309
|
-
# @example Apply multiple modificationss
|
310
|
-
# require "google/cloud/bigtable"
|
311
|
-
#
|
312
|
-
# bigtable = Google::Cloud::Bigtable.new
|
313
|
-
#
|
314
|
-
# instance = bigtable.instance("my-instance")
|
315
|
-
# table = instance.table("my-table")
|
316
|
-
#
|
317
|
-
# modifications = []
|
318
|
-
# modifications << Google::Cloud::Bigtable::ColumnFamily.create_modification(
|
319
|
-
# "cf1", Google::Cloud::Bigtable::GcRule.max_age(600))
|
320
|
-
# )
|
321
|
-
#
|
322
|
-
# modifications << Google::Cloud::Bigtable::ColumnFamily.update_modification(
|
323
|
-
# "cf2", Google::Cloud::Bigtable::GcRule.max_versions(5)
|
324
|
-
# )
|
325
|
-
#
|
326
|
-
# gc_rule_1 = Google::Cloud::Bigtable::GcRule.max_versions(3)
|
327
|
-
# gc_rule_2 = Google::Cloud::Bigtable::GcRule.max_age(600)
|
328
|
-
# modifications << Google::Cloud::Bigtable::ColumnFamily.update_modification(
|
329
|
-
# "cf3", Google::Cloud::Bigtable::GcRule.union(gc_rule_1, gc_rule_2)
|
330
|
-
# )
|
331
|
-
#
|
332
|
-
# max_age_gc_rule = Google::Cloud::Bigtable::GcRule.max_age(300)
|
333
|
-
# modifications << Google::Cloud::Bigtable::ColumnFamily.update_modification(
|
334
|
-
# "cf4", Google::Cloud::Bigtable::GcRule.union(max_version_gc_rule)
|
335
|
-
# )
|
336
|
-
#
|
337
|
-
# modifications << Google::Cloud::Bigtable::ColumnFamily.drop_modification("cf5")
|
338
|
-
#
|
339
|
-
# table = bigtable.modify_column_families(modifications)
|
340
|
-
#
|
341
|
-
# p table.column_families
|
342
|
-
|
343
|
-
def modify_column_families modifications
|
344
|
-
ensure_service!
|
345
|
-
self.class.modify_column_families(
|
346
|
-
service,
|
347
|
-
instance_id,
|
348
|
-
table_id,
|
349
|
-
modifications
|
350
|
-
)
|
351
|
-
end
|
352
|
-
|
353
|
-
# @private
|
354
|
-
#
|
355
|
-
# Performs a series of column family modifications on the specified table.
|
356
|
-
# Either all or none of the modifications will occur before this method
|
357
|
-
# returns, but data requests received prior to that point may see a table
|
358
|
-
# where only some modifications have taken effect.
|
359
|
-
#
|
360
|
-
# @param service [Google::Cloud::Bigtable::Service]
|
361
|
-
# @param instance_id [String]
|
362
|
-
# The unique ID of the instance the table is in.
|
363
|
-
# @param table_id [String]
|
364
|
-
# The unique ID of the table whose families should be modified.
|
365
|
-
# @param modifications [Array<Google::Bigtable::Admin::V2::ModifyColumnFamiliesRequest::Modification> | Google::Bigtable::Admin::V2::ModifyColumnFamiliesRequest::Modification]
|
366
|
-
# Modifications to be atomically applied to the specified table's families.
|
367
|
-
# Entries are applied in order, meaning that earlier modifications can be
|
368
|
-
# masked by later ones (in the case of repeated updates to the same family,
|
369
|
-
# for example).
|
370
|
-
# @return [Google::Cloud::Bigtable::Table] Table with updated column families.
|
371
|
-
#
|
372
|
-
def self.modify_column_families \
|
373
|
-
service,
|
374
|
-
instance_id,
|
375
|
-
table_id,
|
376
|
-
modifications
|
377
|
-
modifications = [modifications] unless modifications.is_a?(Array)
|
378
|
-
grpc = service.modify_column_families(
|
379
|
-
instance_id,
|
380
|
-
table_id,
|
381
|
-
modifications
|
382
|
-
)
|
383
|
-
from_grpc(grpc, service)
|
384
|
-
end
|
385
|
-
|
386
299
|
# @private
|
387
300
|
# Creates a table.
|
388
301
|
#
|
389
302
|
# @param service [Google::Cloud::Bigtable::Service]
|
390
303
|
# @param instance_id [String]
|
391
304
|
# @param table_id [String]
|
392
|
-
# @param column_families [
|
305
|
+
# @param column_families [ColumnFamilyMap]
|
393
306
|
# @param granularity [Symbol]
|
394
307
|
# @param initial_splits [Array<String>]
|
395
308
|
# @yield [column_families] A block for adding column_families.
|
396
|
-
# @yieldparam [
|
309
|
+
# @yieldparam [ColumnFamilyMap]
|
397
310
|
#
|
398
311
|
# @return [Google::Cloud::Bigtable::Table]
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
column_families
|
404
|
-
|
405
|
-
|
406
|
-
|
312
|
+
#
|
313
|
+
def self.create service, instance_id, table_id, column_families: nil, granularity: nil, initial_splits: nil
|
314
|
+
if column_families
|
315
|
+
# create an un-frozen and duplicate object
|
316
|
+
column_families = ColumnFamilyMap.from_grpc column_families.to_grpc
|
317
|
+
end
|
318
|
+
column_families ||= ColumnFamilyMap.new
|
319
|
+
|
407
320
|
yield column_families if block_given?
|
408
321
|
|
409
322
|
table = Google::Bigtable::Admin::V2::Table.new({
|
410
|
-
column_families: column_families.
|
411
|
-
granularity:
|
323
|
+
column_families: column_families.to_grpc_hash,
|
324
|
+
granularity: granularity
|
412
325
|
}.delete_if { |_, v| v.nil? })
|
413
326
|
|
414
|
-
grpc = service.create_table
|
415
|
-
|
416
|
-
table_id,
|
417
|
-
table,
|
418
|
-
initial_splits: initial_splits
|
419
|
-
)
|
420
|
-
from_grpc(grpc, service)
|
327
|
+
grpc = service.create_table instance_id, table_id, table, initial_splits: initial_splits
|
328
|
+
from_grpc grpc, service
|
421
329
|
end
|
422
330
|
|
331
|
+
##
|
423
332
|
# Generates a consistency token for a table. The token can be used in
|
424
333
|
# CheckConsistency to check whether mutations to the table that finished
|
425
334
|
# before this call started have been replicated. The tokens will be available
|
426
335
|
# for 90 days.
|
427
336
|
#
|
428
|
-
# @return [String]
|
337
|
+
# @return [String] The generated consistency token
|
429
338
|
#
|
430
339
|
# @example
|
431
340
|
# require "google/cloud/bigtable"
|
@@ -439,15 +348,16 @@ module Google
|
|
439
348
|
#
|
440
349
|
def generate_consistency_token
|
441
350
|
ensure_service!
|
442
|
-
response = service.generate_consistency_token
|
351
|
+
response = service.generate_consistency_token instance_id, name
|
443
352
|
response.consistency_token
|
444
353
|
end
|
445
354
|
|
355
|
+
##
|
446
356
|
# Checks replication consistency based on a consistency token. Replication is
|
447
357
|
# considered consistent if replication has caught up based on the conditions
|
448
358
|
# specified in the token and the check request.
|
449
359
|
# @param token [String] Consistency token
|
450
|
-
# @return [Boolean]
|
360
|
+
# @return [Boolean] `true` if replication is consistent
|
451
361
|
#
|
452
362
|
# @example
|
453
363
|
# require "google/cloud/bigtable"
|
@@ -465,14 +375,15 @@ module Google
|
|
465
375
|
#
|
466
376
|
def check_consistency token
|
467
377
|
ensure_service!
|
468
|
-
response = service.check_consistency
|
378
|
+
response = service.check_consistency instance_id, name, token
|
469
379
|
response.consistent
|
470
380
|
end
|
471
381
|
|
382
|
+
##
|
472
383
|
# Wait for replication to check replication consistency.
|
473
384
|
# Checks replication consistency by generating a consistency token and
|
474
385
|
# making the `check_consistency` API call 5 times (by default).
|
475
|
-
# If the response is consistent, returns true
|
386
|
+
# If the response is consistent, returns `true`. Otherwise tries again
|
476
387
|
# repeatedly until the timeout. If the check does not succeed by the
|
477
388
|
# timeout, returns `false`.
|
478
389
|
#
|
@@ -480,14 +391,14 @@ module Google
|
|
480
391
|
# Timeout in seconds. Defaults value is 600 seconds.
|
481
392
|
# @param check_interval [Integer]
|
482
393
|
# Consistency check interval in seconds. Default is 5 seconds.
|
483
|
-
# @return [Boolean]
|
394
|
+
# @return [Boolean] `true` if replication is consistent
|
484
395
|
#
|
485
396
|
# @example
|
486
397
|
# require "google/cloud/bigtable"
|
487
398
|
#
|
488
399
|
# bigtable = Google::Cloud::Bigtable.new
|
489
400
|
#
|
490
|
-
# table = bigtable.table("
|
401
|
+
# table = bigtable.table("my-instance", "my-table", perform_lookup: true)
|
491
402
|
#
|
492
403
|
# if table.wait_for_replication
|
493
404
|
# puts "Replication done"
|
@@ -499,37 +410,24 @@ module Google
|
|
499
410
|
# end
|
500
411
|
#
|
501
412
|
def wait_for_replication timeout: 600, check_interval: 5
|
502
|
-
if check_interval > timeout
|
503
|
-
raise(
|
504
|
-
InvalidArgumentError,
|
505
|
-
"'check_interval' can not be greather then timeout"
|
506
|
-
)
|
507
|
-
end
|
413
|
+
raise InvalidArgumentError, "'check_interval' cannot be greater than timeout" if check_interval > timeout
|
508
414
|
token = generate_consistency_token
|
509
415
|
status = false
|
510
416
|
start_at = Time.now
|
511
417
|
|
512
418
|
loop do
|
513
|
-
status = check_consistency
|
419
|
+
status = check_consistency token
|
514
420
|
|
515
421
|
break if status || (Time.now - start_at) >= timeout
|
516
|
-
sleep
|
422
|
+
sleep check_interval
|
517
423
|
end
|
518
424
|
status
|
519
425
|
end
|
520
426
|
|
521
|
-
|
522
|
-
# Gets the data client instance.
|
523
|
-
#
|
524
|
-
# @return [Google::Cloud::Bigtable::V2::BigtableClient]
|
525
|
-
#
|
526
|
-
def client
|
527
|
-
service.client
|
528
|
-
end
|
529
|
-
|
427
|
+
##
|
530
428
|
# Deletes all rows.
|
531
429
|
#
|
532
|
-
# @param timeout [Integer] Call timeout in seconds
|
430
|
+
# @param timeout [Integer] Call timeout in seconds.
|
533
431
|
# Use in case of insufficient deadline for DropRowRange, then
|
534
432
|
# try again with a longer request deadline.
|
535
433
|
# @return [Boolean]
|
@@ -547,13 +445,14 @@ module Google
|
|
547
445
|
# table.delete_all_rows(timeout: 120) # 120 seconds.
|
548
446
|
#
|
549
447
|
def delete_all_rows timeout: nil
|
550
|
-
drop_row_range
|
448
|
+
drop_row_range delete_all_data: true, timeout: timeout
|
551
449
|
end
|
552
450
|
|
451
|
+
##
|
553
452
|
# Deletes rows using row key prefix.
|
554
453
|
#
|
555
|
-
# @param prefix [String] Row key prefix (for example, "user")
|
556
|
-
# @param timeout [Integer] Call timeout in seconds
|
454
|
+
# @param prefix [String] Row key prefix (for example, "user").
|
455
|
+
# @param timeout [Integer] Call timeout in seconds.
|
557
456
|
# @return [Boolean]
|
558
457
|
# @example
|
559
458
|
# require "google/cloud/bigtable"
|
@@ -565,15 +464,16 @@ module Google
|
|
565
464
|
# table.delete_rows_by_prefix("user-100")
|
566
465
|
#
|
567
466
|
# # With timeout
|
568
|
-
# table.
|
467
|
+
# table.delete_rows_by_prefix("user-1", timeout: 120) # 120 seconds.
|
569
468
|
#
|
570
469
|
def delete_rows_by_prefix prefix, timeout: nil
|
571
|
-
drop_row_range
|
470
|
+
drop_row_range row_key_prefix: prefix, timeout: timeout
|
572
471
|
end
|
573
472
|
|
473
|
+
##
|
574
474
|
# Drops row range by row key prefix or deletes all.
|
575
475
|
#
|
576
|
-
# @param row_key_prefix [String] Row key prefix (for example, "user")
|
476
|
+
# @param row_key_prefix [String] Row key prefix (for example, "user").
|
577
477
|
# @param delete_all_data [Boolean]
|
578
478
|
# @return [Boolean]
|
579
479
|
#
|
@@ -585,22 +485,19 @@ module Google
|
|
585
485
|
# table = bigtable.table("my-instance", "my-table")
|
586
486
|
#
|
587
487
|
# # Delete rows using row key prefix.
|
588
|
-
# table.drop_row_range("user-100")
|
488
|
+
# table.drop_row_range(row_key_prefix: "user-100")
|
589
489
|
#
|
590
490
|
# # Delete all data With timeout
|
591
491
|
# table.drop_row_range(delete_all_data: true, timeout: 120) # 120 seconds.
|
592
492
|
#
|
593
|
-
def drop_row_range
|
594
|
-
row_key_prefix: nil,
|
595
|
-
delete_all_data: nil,
|
596
|
-
timeout: nil
|
493
|
+
def drop_row_range row_key_prefix: nil, delete_all_data: nil, timeout: nil
|
597
494
|
ensure_service!
|
598
495
|
service.drop_row_range(
|
599
496
|
instance_id,
|
600
497
|
name,
|
601
|
-
row_key_prefix:
|
498
|
+
row_key_prefix: row_key_prefix,
|
602
499
|
delete_all_data_from_table: delete_all_data,
|
603
|
-
timeout:
|
500
|
+
timeout: timeout
|
604
501
|
)
|
605
502
|
true
|
606
503
|
end
|
@@ -614,7 +511,7 @@ module Google
|
|
614
511
|
# @return [Google::Cloud::Bigtable::Table]
|
615
512
|
#
|
616
513
|
def self.from_grpc grpc, service, view: nil
|
617
|
-
new
|
514
|
+
new grpc, service, view: view
|
618
515
|
end
|
619
516
|
|
620
517
|
# @private
|
@@ -627,8 +524,8 @@ module Google
|
|
627
524
|
# @return [Google::Cloud::Bigtable::Table]
|
628
525
|
#
|
629
526
|
def self.from_path path, service
|
630
|
-
grpc = Google::Bigtable::Admin::V2::Table.new
|
631
|
-
new
|
527
|
+
grpc = Google::Bigtable::Admin::V2::Table.new name: path
|
528
|
+
new grpc, service, view: :NAME_ONLY
|
632
529
|
end
|
633
530
|
|
634
531
|
protected
|
@@ -642,9 +539,9 @@ module Google
|
|
642
539
|
end
|
643
540
|
|
644
541
|
FIELDS_BY_VIEW = {
|
645
|
-
SCHEMA_VIEW:
|
542
|
+
SCHEMA_VIEW: ["granularity", "column_families"],
|
646
543
|
REPLICATION_VIEW: ["cluster_states"],
|
647
|
-
FULL:
|
544
|
+
FULL: ["granularity", "column_families", "cluster_states"]
|
648
545
|
}.freeze
|
649
546
|
|
650
547
|
# @private
|
@@ -653,13 +550,12 @@ module Google
|
|
653
550
|
# @param view [Symbol] Expected view type.
|
654
551
|
#
|
655
552
|
def check_view_and_load view
|
656
|
-
|
553
|
+
ensure_service!
|
554
|
+
@loaded_views ||= Set.new [@view]
|
657
555
|
|
658
|
-
if @loaded_views.include?(view) || @loaded_views.include?(:FULL)
|
659
|
-
return
|
660
|
-
end
|
556
|
+
return if @loaded_views.include?(view) || @loaded_views.include?(:FULL)
|
661
557
|
|
662
|
-
grpc = service.get_table
|
558
|
+
grpc = service.get_table instance_id, table_id, view: view
|
663
559
|
@loaded_views << view
|
664
560
|
|
665
561
|
FIELDS_BY_VIEW[view].each do |field|
|