google-cloud-bigtable 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/CONTRIBUTING.md +1 -1
- data/lib/google-cloud-bigtable.rb +19 -21
- data/lib/google/cloud/bigtable.rb +11 -17
- data/lib/google/cloud/bigtable/app_profile.rb +148 -82
- data/lib/google/cloud/bigtable/app_profile/job.rb +5 -8
- data/lib/google/cloud/bigtable/app_profile/list.rb +11 -5
- data/lib/google/cloud/bigtable/chunk_processor.rb +23 -35
- data/lib/google/cloud/bigtable/cluster.rb +38 -11
- data/lib/google/cloud/bigtable/cluster/job.rb +3 -7
- data/lib/google/cloud/bigtable/cluster/list.rb +20 -18
- data/lib/google/cloud/bigtable/column_family.rb +22 -229
- data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
- data/lib/google/cloud/bigtable/column_range.rb +9 -1
- 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 +184 -65
- data/lib/google/cloud/bigtable/instance.rb +136 -126
- data/lib/google/cloud/bigtable/instance/cluster_map.rb +9 -7
- data/lib/google/cloud/bigtable/instance/job.rb +4 -3
- data/lib/google/cloud/bigtable/instance/list.rb +14 -9
- data/lib/google/cloud/bigtable/longrunning_job.rb +6 -0
- data/lib/google/cloud/bigtable/mutation_entry.rb +19 -23
- data/lib/google/cloud/bigtable/mutation_operations.rb +82 -29
- data/lib/google/cloud/bigtable/policy.rb +9 -5
- data/lib/google/cloud/bigtable/project.rb +62 -140
- data/lib/google/cloud/bigtable/read_modify_write_rule.rb +9 -4
- data/lib/google/cloud/bigtable/read_operations.rb +28 -41
- data/lib/google/cloud/bigtable/routing_policy.rb +171 -0
- data/lib/google/cloud/bigtable/row.rb +18 -7
- data/lib/google/cloud/bigtable/row_filter.rb +49 -20
- data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +71 -43
- data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +4 -1
- data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +74 -43
- data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +22 -7
- data/lib/google/cloud/bigtable/row_range.rb +5 -0
- data/lib/google/cloud/bigtable/rows_mutator.rb +14 -17
- data/lib/google/cloud/bigtable/rows_reader.rb +18 -14
- data/lib/google/cloud/bigtable/sample_row_key.rb +5 -2
- data/lib/google/cloud/bigtable/service.rb +161 -242
- data/lib/google/cloud/bigtable/status.rb +76 -0
- data/lib/google/cloud/bigtable/table.rb +141 -236
- data/lib/google/cloud/bigtable/table/cluster_state.rb +7 -1
- data/lib/google/cloud/bigtable/table/list.rb +14 -7
- data/lib/google/cloud/bigtable/value_range.rb +5 -0
- data/lib/google/cloud/bigtable/version.rb +1 -1
- metadata +27 -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,36 +69,45 @@ module Google
|
|
76
69
|
@view = view || :SCHEMA_VIEW
|
77
70
|
end
|
78
71
|
|
72
|
+
##
|
79
73
|
# The unique identifier for the project.
|
80
74
|
#
|
81
75
|
# @return [String]
|
76
|
+
#
|
82
77
|
def project_id
|
83
78
|
@grpc.name.split("/")[1]
|
84
79
|
end
|
85
80
|
|
81
|
+
##
|
86
82
|
# The unique identifier for the instance.
|
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
|
|
110
|
+
##
|
109
111
|
# Reload table information.
|
110
112
|
#
|
111
113
|
# @param view [Symbol] Table view type.
|
@@ -118,13 +120,14 @@ module Google
|
|
118
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
|
@@ -132,32 +135,89 @@ module Google
|
|
132
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)
|
144
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
|
145
201
|
#
|
146
|
-
#
|
202
|
+
# cfm.delete "cf3"
|
203
|
+
# end
|
204
|
+
#
|
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`.
|
@@ -166,10 +226,11 @@ module Google
|
|
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,199 +290,45 @@ 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
|
@@ -439,10 +348,11 @@ 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.
|
@@ -465,10 +375,11 @@ 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).
|
@@ -487,7 +398,7 @@ module Google
|
|
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,21 +410,16 @@ 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' can not be greather then 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
|
@@ -527,6 +433,7 @@ module Google
|
|
527
433
|
service.client
|
528
434
|
end
|
529
435
|
|
436
|
+
##
|
530
437
|
# Deletes all rows.
|
531
438
|
#
|
532
439
|
# @param timeout [Integer] Call timeout in seconds
|
@@ -547,9 +454,10 @@ module Google
|
|
547
454
|
# table.delete_all_rows(timeout: 120) # 120 seconds.
|
548
455
|
#
|
549
456
|
def delete_all_rows timeout: nil
|
550
|
-
drop_row_range
|
457
|
+
drop_row_range delete_all_data: true, timeout: timeout
|
551
458
|
end
|
552
459
|
|
460
|
+
##
|
553
461
|
# Deletes rows using row key prefix.
|
554
462
|
#
|
555
463
|
# @param prefix [String] Row key prefix (for example, "user")
|
@@ -565,12 +473,13 @@ module Google
|
|
565
473
|
# table.delete_rows_by_prefix("user-100")
|
566
474
|
#
|
567
475
|
# # With timeout
|
568
|
-
# table.
|
476
|
+
# table.delete_rows_by_prefix("user-1", timeout: 120) # 120 seconds.
|
569
477
|
#
|
570
478
|
def delete_rows_by_prefix prefix, timeout: nil
|
571
|
-
drop_row_range
|
479
|
+
drop_row_range row_key_prefix: prefix, timeout: timeout
|
572
480
|
end
|
573
481
|
|
482
|
+
##
|
574
483
|
# Drops row range by row key prefix or deletes all.
|
575
484
|
#
|
576
485
|
# @param row_key_prefix [String] Row key prefix (for example, "user")
|
@@ -585,22 +494,19 @@ module Google
|
|
585
494
|
# table = bigtable.table("my-instance", "my-table")
|
586
495
|
#
|
587
496
|
# # Delete rows using row key prefix.
|
588
|
-
# table.drop_row_range("user-100")
|
497
|
+
# table.drop_row_range(row_key_prefix: "user-100")
|
589
498
|
#
|
590
499
|
# # Delete all data With timeout
|
591
500
|
# table.drop_row_range(delete_all_data: true, timeout: 120) # 120 seconds.
|
592
501
|
#
|
593
|
-
def drop_row_range
|
594
|
-
row_key_prefix: nil,
|
595
|
-
delete_all_data: nil,
|
596
|
-
timeout: nil
|
502
|
+
def drop_row_range row_key_prefix: nil, delete_all_data: nil, timeout: nil
|
597
503
|
ensure_service!
|
598
504
|
service.drop_row_range(
|
599
505
|
instance_id,
|
600
506
|
name,
|
601
|
-
row_key_prefix:
|
507
|
+
row_key_prefix: row_key_prefix,
|
602
508
|
delete_all_data_from_table: delete_all_data,
|
603
|
-
timeout:
|
509
|
+
timeout: timeout
|
604
510
|
)
|
605
511
|
true
|
606
512
|
end
|
@@ -614,7 +520,7 @@ module Google
|
|
614
520
|
# @return [Google::Cloud::Bigtable::Table]
|
615
521
|
#
|
616
522
|
def self.from_grpc grpc, service, view: nil
|
617
|
-
new
|
523
|
+
new grpc, service, view: view
|
618
524
|
end
|
619
525
|
|
620
526
|
# @private
|
@@ -627,8 +533,8 @@ module Google
|
|
627
533
|
# @return [Google::Cloud::Bigtable::Table]
|
628
534
|
#
|
629
535
|
def self.from_path path, service
|
630
|
-
grpc = Google::Bigtable::Admin::V2::Table.new
|
631
|
-
new
|
536
|
+
grpc = Google::Bigtable::Admin::V2::Table.new name: path
|
537
|
+
new grpc, service, view: :NAME_ONLY
|
632
538
|
end
|
633
539
|
|
634
540
|
protected
|
@@ -642,9 +548,9 @@ module Google
|
|
642
548
|
end
|
643
549
|
|
644
550
|
FIELDS_BY_VIEW = {
|
645
|
-
SCHEMA_VIEW:
|
551
|
+
SCHEMA_VIEW: ["granularity", "column_families"],
|
646
552
|
REPLICATION_VIEW: ["cluster_states"],
|
647
|
-
FULL:
|
553
|
+
FULL: ["granularity", "column_families", "cluster_states"]
|
648
554
|
}.freeze
|
649
555
|
|
650
556
|
# @private
|
@@ -653,13 +559,12 @@ module Google
|
|
653
559
|
# @param view [Symbol] Expected view type.
|
654
560
|
#
|
655
561
|
def check_view_and_load view
|
656
|
-
|
562
|
+
ensure_service!
|
563
|
+
@loaded_views ||= Set.new [@view]
|
657
564
|
|
658
|
-
if @loaded_views.include?(view) || @loaded_views.include?(:FULL)
|
659
|
-
return
|
660
|
-
end
|
565
|
+
return if @loaded_views.include?(view) || @loaded_views.include?(:FULL)
|
661
566
|
|
662
|
-
grpc = service.get_table
|
567
|
+
grpc = service.get_table instance_id, table_id, view: view
|
663
568
|
@loaded_views << view
|
664
569
|
|
665
570
|
FIELDS_BY_VIEW[view].each do |field|
|