google-cloud-bigtable 0.6.2 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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 +2 -2
- data/lib/google/cloud/bigtable/admin/v2.rb +2 -2
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +2 -2
- data/lib/google/cloud/bigtable/admin/v2/credentials.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/options.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +7 -6
- data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +2 -2
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +1 -1
- data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +7 -55
- data/lib/google/cloud/bigtable/admin/v2/doc/google/type/expr.rb +1 -1
- 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 +2 -2
- data/lib/google/cloud/bigtable/v2/bigtable_client.rb +13 -13
- data/lib/google/cloud/bigtable/v2/credentials.rb +1 -1
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +17 -14
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +1 -1
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +1 -1
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +1 -1
- data/lib/google/cloud/bigtable/v2/doc/google/rpc/status.rb +7 -55
- 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
@@ -18,6 +18,7 @@
|
|
18
18
|
module Google
|
19
19
|
module Cloud
|
20
20
|
module Bigtable
|
21
|
+
##
|
21
22
|
# # ReadModifyWriteRule
|
22
23
|
#
|
23
24
|
# Specifies an atomic read/modify/write operation on the latest value of the
|
@@ -35,7 +36,7 @@ module Google
|
|
35
36
|
#
|
36
37
|
class ReadModifyWriteRule
|
37
38
|
# @private
|
38
|
-
#
|
39
|
+
# Creates an instance of ReadModifyWriteRule
|
39
40
|
#
|
40
41
|
# @param family [String]
|
41
42
|
# The name of the family to which the read/modify/write should be applied.
|
@@ -48,7 +49,8 @@ module Google
|
|
48
49
|
@grpc.column_qualifier = qualifier
|
49
50
|
end
|
50
51
|
|
51
|
-
|
52
|
+
##
|
53
|
+
# Creates an instance of an append-value rule.
|
52
54
|
#
|
53
55
|
# @param family [String]
|
54
56
|
# The name of the family to which the read/modify/write should be applied.
|
@@ -65,12 +67,13 @@ module Google
|
|
65
67
|
# )
|
66
68
|
#
|
67
69
|
def self.append family, qualifier, value
|
68
|
-
rule = new
|
69
|
-
rule.append
|
70
|
+
rule = new family, qualifier
|
71
|
+
rule.append value
|
70
72
|
rule
|
71
73
|
end
|
72
74
|
|
73
|
-
|
75
|
+
##
|
76
|
+
# Creates an instance of an increment-amount rule.
|
74
77
|
#
|
75
78
|
# @param family [String]
|
76
79
|
# The name of the family to which the read/modify/write should be applied.
|
@@ -83,18 +86,19 @@ module Google
|
|
83
86
|
# as a 64-bit big-endian signed integer), or the entire request will fail.
|
84
87
|
# @return [Google::Cloud::Bigtable::ReadModifyWriteRule]
|
85
88
|
#
|
86
|
-
# @example
|
89
|
+
# @example
|
87
90
|
# rule = Google::Cloud::Bigtable::ReadModifyWriteRule.increment(
|
88
91
|
# "cf", "field01", 1
|
89
92
|
# )
|
90
93
|
#
|
91
94
|
def self.increment family, qualifier, amount
|
92
|
-
rule = new
|
93
|
-
rule.increment
|
95
|
+
rule = new family, qualifier
|
96
|
+
rule.increment amount
|
94
97
|
rule
|
95
98
|
end
|
96
99
|
|
97
|
-
|
100
|
+
##
|
101
|
+
# Sets the append value.
|
98
102
|
#
|
99
103
|
# @param value [String]
|
100
104
|
# @return [Google::Cloud::Bigtable::ReadModifyWriteRule]
|
@@ -104,7 +108,8 @@ module Google
|
|
104
108
|
self
|
105
109
|
end
|
106
110
|
|
107
|
-
|
111
|
+
##
|
112
|
+
# Sets the increment amount.
|
108
113
|
#
|
109
114
|
# @param amount [Integer]
|
110
115
|
# @return [Google::Cloud::Bigtable::ReadModifyWriteRule]
|
@@ -24,6 +24,7 @@ require "google/cloud/bigtable/sample_row_key"
|
|
24
24
|
module Google
|
25
25
|
module Cloud
|
26
26
|
module Bigtable
|
27
|
+
##
|
27
28
|
# # ReadOperations
|
28
29
|
#
|
29
30
|
# Collection of read-rows APIs.
|
@@ -33,6 +34,7 @@ module Google
|
|
33
34
|
# * Read rows
|
34
35
|
#
|
35
36
|
module ReadOperations
|
37
|
+
##
|
36
38
|
# Reads sample row keys.
|
37
39
|
#
|
38
40
|
# Returns a sample of row keys in the table. The returned row keys will
|
@@ -45,7 +47,7 @@ module Google
|
|
45
47
|
# Yield block for each processed SampleRowKey.
|
46
48
|
#
|
47
49
|
# @example
|
48
|
-
# require "google/cloud"
|
50
|
+
# require "google/cloud/bigtable"
|
49
51
|
#
|
50
52
|
# bigtable = Google::Cloud::Bigtable.new
|
51
53
|
# table = bigtable.table("my-instance", "my-table")
|
@@ -56,17 +58,15 @@ module Google
|
|
56
58
|
# end
|
57
59
|
#
|
58
60
|
def sample_row_keys
|
59
|
-
return enum_for
|
61
|
+
return enum_for :sample_row_keys unless block_given?
|
60
62
|
|
61
|
-
response =
|
62
|
-
path,
|
63
|
-
app_profile_id: @app_profile_id
|
64
|
-
)
|
63
|
+
response = service.sample_row_keys path, app_profile_id: @app_profile_id
|
65
64
|
response.each do |grpc|
|
66
|
-
yield SampleRowKey.from_grpc
|
65
|
+
yield SampleRowKey.from_grpc grpc
|
67
66
|
end
|
68
67
|
end
|
69
68
|
|
69
|
+
##
|
70
70
|
# Reads rows.
|
71
71
|
#
|
72
72
|
# Streams back the contents of all requested rows in key order, optionally
|
@@ -86,7 +86,7 @@ module Google
|
|
86
86
|
# The default (zero) is to return all results.
|
87
87
|
# @return [Array<Google::Cloud::Bigtable::Row> | :yields: row]
|
88
88
|
# Array of row or yield block for each processed row.
|
89
|
-
# @example Read with limit
|
89
|
+
# @example Read with limit.
|
90
90
|
# require "google/cloud/bigtable"
|
91
91
|
#
|
92
92
|
# bigtable = Google::Cloud::Bigtable.new
|
@@ -96,7 +96,7 @@ module Google
|
|
96
96
|
# puts row
|
97
97
|
# end
|
98
98
|
#
|
99
|
-
# @example Read using row keys
|
99
|
+
# @example Read using row keys.
|
100
100
|
# require "google/cloud/bigtable"
|
101
101
|
#
|
102
102
|
# bigtable = Google::Cloud::Bigtable.new
|
@@ -106,20 +106,19 @@ module Google
|
|
106
106
|
# puts row
|
107
107
|
# end
|
108
108
|
#
|
109
|
-
# @example Read using row ranges
|
109
|
+
# @example Read using row ranges.
|
110
110
|
# require "google/cloud/bigtable"
|
111
111
|
#
|
112
112
|
# bigtable = Google::Cloud::Bigtable.new
|
113
113
|
# table = bigtable.table("my-instance", "my-table")
|
114
114
|
#
|
115
|
-
# range =
|
115
|
+
# range = table.new_row_range.between("user-1", "user-100")
|
116
116
|
#
|
117
117
|
# table.read_rows(ranges: range).each do |row|
|
118
118
|
# puts row
|
119
119
|
# end
|
120
120
|
#
|
121
|
-
# @example Read using filter
|
122
|
-
#
|
121
|
+
# @example Read using filter.
|
123
122
|
# require "google/cloud/bigtable"
|
124
123
|
#
|
125
124
|
# bigtable = Google::Cloud::Bigtable.new
|
@@ -133,8 +132,7 @@ module Google
|
|
133
132
|
# puts row
|
134
133
|
# end
|
135
134
|
#
|
136
|
-
# @example Read using filter with limit
|
137
|
-
#
|
135
|
+
# @example Read using filter with limit.
|
138
136
|
# require "google/cloud/bigtable"
|
139
137
|
#
|
140
138
|
# bigtable = Google::Cloud::Bigtable.new
|
@@ -148,52 +146,33 @@ module Google
|
|
148
146
|
# puts row
|
149
147
|
# end
|
150
148
|
#
|
151
|
-
def read_rows
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
limit: nil,
|
156
|
-
&block
|
157
|
-
unless block_given?
|
158
|
-
return enum_for(
|
159
|
-
:read_rows,
|
160
|
-
keys: keys,
|
161
|
-
ranges: ranges,
|
162
|
-
filter: filter,
|
163
|
-
limit: limit
|
164
|
-
)
|
165
|
-
end
|
166
|
-
row_set = build_row_set(keys, ranges)
|
149
|
+
def read_rows keys: nil, ranges: nil, filter: nil, limit: nil, &block
|
150
|
+
return enum_for :read_rows, keys: keys, ranges: ranges, filter: filter, limit: limit unless block_given?
|
151
|
+
|
152
|
+
row_set = build_row_set keys, ranges
|
167
153
|
rows_limit = limit
|
168
154
|
rows_filter = filter.to_grpc if filter
|
169
|
-
rows_reader = RowsReader.new
|
155
|
+
rows_reader = RowsReader.new self
|
170
156
|
|
171
157
|
begin
|
172
|
-
rows_reader.read
|
173
|
-
rows: row_set,
|
174
|
-
filter: rows_filter,
|
175
|
-
rows_limit: rows_limit,
|
176
|
-
&block
|
177
|
-
)
|
158
|
+
rows_reader.read rows: row_set, filter: rows_filter, rows_limit: rows_limit, &block
|
178
159
|
rescue *RowsReader::RETRYABLE_ERRORS => e
|
179
160
|
rows_reader.retry_count += 1
|
180
|
-
unless rows_reader.retryable?
|
181
|
-
|
182
|
-
end
|
183
|
-
rows_limit, row_set = rows_reader.retry_options(limit, row_set)
|
161
|
+
raise Google::Cloud::Error.from_error(e) unless rows_reader.retryable?
|
162
|
+
rows_limit, row_set = rows_reader.retry_options limit, row_set
|
184
163
|
retry
|
185
164
|
end
|
186
165
|
end
|
187
166
|
|
167
|
+
##
|
188
168
|
# Reads a single row by row key.
|
189
169
|
#
|
190
|
-
# @param key [String] Row key. Required
|
170
|
+
# @param key [String] Row key. Required.
|
191
171
|
# @param filter [Google::Cloud::Bigtable::RowFilter]
|
192
172
|
# The filter to apply to the contents of the specified row. Optional.
|
193
173
|
# @return [Google::Cloud::Bigtable::Row]
|
194
174
|
#
|
195
|
-
# @example
|
196
|
-
#
|
175
|
+
# @example
|
197
176
|
# require "google/cloud/bigtable"
|
198
177
|
#
|
199
178
|
# bigtable = Google::Cloud::Bigtable.new
|
@@ -201,8 +180,7 @@ module Google
|
|
201
180
|
#
|
202
181
|
# row = table.read_row("user-1")
|
203
182
|
#
|
204
|
-
# @example Read row
|
205
|
-
#
|
183
|
+
# @example Read row with filter.
|
206
184
|
# require "google/cloud/bigtable"
|
207
185
|
#
|
208
186
|
# bigtable = Google::Cloud::Bigtable.new
|
@@ -216,6 +194,7 @@ module Google
|
|
216
194
|
read_rows(keys: [key], filter: filter).first
|
217
195
|
end
|
218
196
|
|
197
|
+
##
|
219
198
|
# Creates a new instance of ValueRange.
|
220
199
|
#
|
221
200
|
# @return [Google::Cloud::Bigtable::ValueRange]
|
@@ -226,14 +205,14 @@ module Google
|
|
226
205
|
# bigtable = Google::Cloud::Bigtable.new
|
227
206
|
# table = bigtable.table("my-instance", "my-table")
|
228
207
|
#
|
229
|
-
# range = table.
|
208
|
+
# range = table.new_value_range
|
230
209
|
# range.from("abc")
|
231
210
|
# range.to("xyz")
|
232
211
|
#
|
233
212
|
# # OR
|
234
213
|
# range = table.new_value_range.from("abc").to("xyz")
|
235
214
|
#
|
236
|
-
# @example With exclusive from range
|
215
|
+
# @example With exclusive from range.
|
237
216
|
# require "google/cloud/bigtable"
|
238
217
|
#
|
239
218
|
# bigtable = Google::Cloud::Bigtable.new
|
@@ -245,9 +224,10 @@ module Google
|
|
245
224
|
Google::Cloud::Bigtable::ValueRange.new
|
246
225
|
end
|
247
226
|
|
248
|
-
|
227
|
+
##
|
228
|
+
# Gets a new instance of ColumnRange.
|
249
229
|
#
|
250
|
-
# @param family [String] Column family name
|
230
|
+
# @param family [String] Column family name.
|
251
231
|
# @return [Google::Cloud::Bigtable::ColumnRange]
|
252
232
|
#
|
253
233
|
# @example
|
@@ -256,14 +236,14 @@ module Google
|
|
256
236
|
# bigtable = Google::Cloud::Bigtable.new
|
257
237
|
# table = bigtable.table("my-instance", "my-table")
|
258
238
|
#
|
259
|
-
# range = table.
|
239
|
+
# range = table.new_column_range("test-family")
|
260
240
|
# range.from("abc")
|
261
241
|
# range.to("xyz")
|
262
242
|
#
|
263
243
|
# # OR
|
264
244
|
# range = table.new_column_range("test-family").from("key-1").to("key-5")
|
265
245
|
#
|
266
|
-
# @example With exclusive from range
|
246
|
+
# @example With exclusive from range.
|
267
247
|
# require "google/cloud/bigtable"
|
268
248
|
#
|
269
249
|
# bigtable = Google::Cloud::Bigtable.new
|
@@ -272,10 +252,11 @@ module Google
|
|
272
252
|
# range = table.new_column_range("test-family").from("key-1", inclusive: false).to("key-5")
|
273
253
|
#
|
274
254
|
def new_column_range family
|
275
|
-
Google::Cloud::Bigtable::ColumnRange.new
|
255
|
+
Google::Cloud::Bigtable::ColumnRange.new family
|
276
256
|
end
|
277
257
|
|
278
|
-
|
258
|
+
##
|
259
|
+
# Gets a new instance of RowRange.
|
279
260
|
#
|
280
261
|
# @return [Google::Cloud::Bigtable::RowRange]
|
281
262
|
#
|
@@ -285,14 +266,14 @@ module Google
|
|
285
266
|
# bigtable = Google::Cloud::Bigtable.new
|
286
267
|
# table = bigtable.table("my-instance", "my-table")
|
287
268
|
#
|
288
|
-
# range = table.
|
269
|
+
# range = table.new_row_range
|
289
270
|
# range.from("abc")
|
290
271
|
# range.to("xyz")
|
291
272
|
#
|
292
273
|
# # OR
|
293
274
|
# range = table.new_row_range.from("key-1").to("key-5")
|
294
275
|
#
|
295
|
-
# @example With exclusive from range
|
276
|
+
# @example With exclusive from range.
|
296
277
|
# require "google/cloud/bigtable"
|
297
278
|
#
|
298
279
|
# bigtable = Google::Cloud::Bigtable.new
|
@@ -304,6 +285,7 @@ module Google
|
|
304
285
|
Google::Cloud::Bigtable::RowRange.new
|
305
286
|
end
|
306
287
|
|
288
|
+
##
|
307
289
|
# Gets a row filter.
|
308
290
|
#
|
309
291
|
# @return [Google::Cloud::Bigtable::RowRange]
|
@@ -322,6 +304,7 @@ module Google
|
|
322
304
|
|
323
305
|
private
|
324
306
|
|
307
|
+
##
|
325
308
|
# Builds a RowSet object from row keys and row ranges.
|
326
309
|
#
|
327
310
|
# @param row_keys [Array<String>]
|
@@ -333,11 +316,11 @@ module Google
|
|
333
316
|
row_set[:row_keys] = row_keys if row_keys
|
334
317
|
|
335
318
|
if row_ranges
|
336
|
-
row_ranges = [row_ranges] unless row_ranges.instance_of?
|
319
|
+
row_ranges = [row_ranges] unless row_ranges.instance_of? Array
|
337
320
|
row_set[:row_ranges] = row_ranges.map(&:to_grpc)
|
338
321
|
end
|
339
322
|
|
340
|
-
Google::Bigtable::V2::RowSet.new
|
323
|
+
Google::Bigtable::V2::RowSet.new row_set
|
341
324
|
end
|
342
325
|
end
|
343
326
|
end
|
@@ -0,0 +1,172 @@
|
|
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
|
+
# # RoutingPolicy
|
21
|
+
#
|
22
|
+
# An abstract routing policy.
|
23
|
+
#
|
24
|
+
# See subclasses for concrete implementations:
|
25
|
+
# * {Google::Cloud::Bigtable::MultiClusterRoutingUseAny} - Read/write
|
26
|
+
# requests may be routed to any cluster in the instance and will
|
27
|
+
# fail over to another cluster in the event of transient errors or
|
28
|
+
# delays. Choosing this option sacrifices read-your-writes
|
29
|
+
# consistency to improve availability.
|
30
|
+
# * {Google::Cloud::Bigtable::SingleClusterRouting} - Unconditionally
|
31
|
+
# routes all read/write requests to a specific cluster. This option
|
32
|
+
# preserves read-your-writes consistency but does not improve
|
33
|
+
# availability. Value contains `cluster_id` and optional field
|
34
|
+
# `allow_transactional_writes`.
|
35
|
+
#
|
36
|
+
# @example Create an app profile with a single cluster routing policy.
|
37
|
+
# require "google/cloud/bigtable"
|
38
|
+
#
|
39
|
+
# bigtable = Google::Cloud::Bigtable.new
|
40
|
+
#
|
41
|
+
# instance = bigtable.instance("my-instance")
|
42
|
+
#
|
43
|
+
# routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
|
44
|
+
# "my-instance-cluster-1",
|
45
|
+
# allow_transactional_writes: true
|
46
|
+
# )
|
47
|
+
#
|
48
|
+
# app_profile = instance.create_app_profile(
|
49
|
+
# "my-app-profile",
|
50
|
+
# routing_policy,
|
51
|
+
# description: "App profile for user data instance"
|
52
|
+
# )
|
53
|
+
# puts app_profile.routing_policy
|
54
|
+
#
|
55
|
+
# @example Create an app profile with multi-cluster routing policy.
|
56
|
+
# require "google/cloud/bigtable"
|
57
|
+
#
|
58
|
+
# bigtable = Google::Cloud::Bigtable.new
|
59
|
+
#
|
60
|
+
# instance = bigtable.instance("my-instance")
|
61
|
+
#
|
62
|
+
# routing_policy = Google::Cloud::Bigtable::AppProfile.multi_cluster_routing
|
63
|
+
#
|
64
|
+
# app_profile = instance.create_app_profile(
|
65
|
+
# "my-app-profile",
|
66
|
+
# routing_policy,
|
67
|
+
# description: "App profile for user data instance"
|
68
|
+
# )
|
69
|
+
# puts app_profile.routing_policy
|
70
|
+
#
|
71
|
+
class RoutingPolicy
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# A multi-cluster routing policy for all read/write requests that use the
|
76
|
+
# associated app profile.
|
77
|
+
#
|
78
|
+
# Read/write requests may be routed to any cluster in the instance, and will
|
79
|
+
# fail over to another cluster in the event of transient errors or delays.
|
80
|
+
# Choosing this option sacrifices read-your-writes consistency to improve
|
81
|
+
# availability.
|
82
|
+
#
|
83
|
+
# @example
|
84
|
+
# require "google/cloud/bigtable"
|
85
|
+
#
|
86
|
+
# bigtable = Google::Cloud::Bigtable.new
|
87
|
+
#
|
88
|
+
# instance = bigtable.instance("my-instance")
|
89
|
+
#
|
90
|
+
# routing_policy = Google::Cloud::Bigtable::AppProfile.multi_cluster_routing
|
91
|
+
#
|
92
|
+
# app_profile = instance.create_app_profile(
|
93
|
+
# "my-app-profile",
|
94
|
+
# routing_policy,
|
95
|
+
# description: "App profile for user data instance"
|
96
|
+
# )
|
97
|
+
# puts app_profile.routing_policy
|
98
|
+
#
|
99
|
+
class MultiClusterRoutingUseAny < RoutingPolicy
|
100
|
+
# @private
|
101
|
+
def to_grpc
|
102
|
+
Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny.new
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# A single-cluster routing policy for all read/write requests that use the
|
108
|
+
# associated app profile.
|
109
|
+
#
|
110
|
+
# Unconditionally routes all read/write requests to a specific cluster.
|
111
|
+
# This option preserves read-your-writes consistency, but does not improve
|
112
|
+
# availability.
|
113
|
+
#
|
114
|
+
# @example
|
115
|
+
# require "google/cloud/bigtable"
|
116
|
+
#
|
117
|
+
# bigtable = Google::Cloud::Bigtable.new
|
118
|
+
#
|
119
|
+
# instance = bigtable.instance("my-instance")
|
120
|
+
#
|
121
|
+
# routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
|
122
|
+
# "my-instance-cluster-1",
|
123
|
+
# allow_transactional_writes: true
|
124
|
+
# )
|
125
|
+
#
|
126
|
+
# app_profile = instance.create_app_profile(
|
127
|
+
# "my-app-profile",
|
128
|
+
# routing_policy,
|
129
|
+
# description: "App profile for user data instance"
|
130
|
+
# )
|
131
|
+
# puts app_profile.routing_policy
|
132
|
+
#
|
133
|
+
# @!attribute [rw] cluster_id
|
134
|
+
# @return [String]
|
135
|
+
# The cluster to which read/write requests should be routed.
|
136
|
+
# @!attribute [rw] allow_transactional_writes
|
137
|
+
# @return [true, false]
|
138
|
+
# If true, `CheckAndMutateRow` and `ReadModifyWriteRow` requests are
|
139
|
+
# allowed by this app profile. It is unsafe to send these requests to
|
140
|
+
# the same table/row/column in multiple clusters.
|
141
|
+
# Default value is false.
|
142
|
+
#
|
143
|
+
class SingleClusterRouting < RoutingPolicy
|
144
|
+
attr_reader :cluster_id, :allow_transactional_writes
|
145
|
+
|
146
|
+
##
|
147
|
+
# Creates a new single-cluster routing policy.
|
148
|
+
#
|
149
|
+
# @param cluster_id [String] The cluster to which read/write requests
|
150
|
+
# should be routed.
|
151
|
+
# @param allow_transactional_writes [Boolean]
|
152
|
+
# If true, `CheckAndMutateRow` and `ReadModifyWriteRow` requests are
|
153
|
+
# allowed by this app profile. It is unsafe to send these requests to
|
154
|
+
# the same table/row/column in multiple clusters.
|
155
|
+
# Default value is false.
|
156
|
+
#
|
157
|
+
def initialize cluster_id, allow_transactional_writes
|
158
|
+
@cluster_id = cluster_id
|
159
|
+
@allow_transactional_writes = allow_transactional_writes
|
160
|
+
end
|
161
|
+
|
162
|
+
# @private
|
163
|
+
def to_grpc
|
164
|
+
Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting.new(
|
165
|
+
cluster_id: cluster_id,
|
166
|
+
allow_transactional_writes: allow_transactional_writes
|
167
|
+
)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|