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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/CONTRIBUTING.md +1 -1
  4. data/lib/google-cloud-bigtable.rb +19 -21
  5. data/lib/google/cloud/bigtable.rb +11 -17
  6. data/lib/google/cloud/bigtable/app_profile.rb +148 -82
  7. data/lib/google/cloud/bigtable/app_profile/job.rb +5 -8
  8. data/lib/google/cloud/bigtable/app_profile/list.rb +11 -5
  9. data/lib/google/cloud/bigtable/chunk_processor.rb +23 -35
  10. data/lib/google/cloud/bigtable/cluster.rb +38 -11
  11. data/lib/google/cloud/bigtable/cluster/job.rb +3 -7
  12. data/lib/google/cloud/bigtable/cluster/list.rb +20 -18
  13. data/lib/google/cloud/bigtable/column_family.rb +22 -229
  14. data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
  15. data/lib/google/cloud/bigtable/column_range.rb +9 -1
  16. data/lib/google/cloud/bigtable/convert.rb +12 -4
  17. data/lib/google/cloud/bigtable/errors.rb +4 -1
  18. data/lib/google/cloud/bigtable/gc_rule.rb +184 -65
  19. data/lib/google/cloud/bigtable/instance.rb +136 -126
  20. data/lib/google/cloud/bigtable/instance/cluster_map.rb +9 -7
  21. data/lib/google/cloud/bigtable/instance/job.rb +4 -3
  22. data/lib/google/cloud/bigtable/instance/list.rb +14 -9
  23. data/lib/google/cloud/bigtable/longrunning_job.rb +6 -0
  24. data/lib/google/cloud/bigtable/mutation_entry.rb +19 -23
  25. data/lib/google/cloud/bigtable/mutation_operations.rb +82 -29
  26. data/lib/google/cloud/bigtable/policy.rb +9 -5
  27. data/lib/google/cloud/bigtable/project.rb +62 -140
  28. data/lib/google/cloud/bigtable/read_modify_write_rule.rb +9 -4
  29. data/lib/google/cloud/bigtable/read_operations.rb +28 -41
  30. data/lib/google/cloud/bigtable/routing_policy.rb +171 -0
  31. data/lib/google/cloud/bigtable/row.rb +18 -7
  32. data/lib/google/cloud/bigtable/row_filter.rb +49 -20
  33. data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +71 -43
  34. data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +4 -1
  35. data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +74 -43
  36. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +22 -7
  37. data/lib/google/cloud/bigtable/row_range.rb +5 -0
  38. data/lib/google/cloud/bigtable/rows_mutator.rb +14 -17
  39. data/lib/google/cloud/bigtable/rows_reader.rb +18 -14
  40. data/lib/google/cloud/bigtable/sample_row_key.rb +5 -2
  41. data/lib/google/cloud/bigtable/service.rb +161 -242
  42. data/lib/google/cloud/bigtable/status.rb +76 -0
  43. data/lib/google/cloud/bigtable/table.rb +141 -236
  44. data/lib/google/cloud/bigtable/table/cluster_state.rb +7 -1
  45. data/lib/google/cloud/bigtable/table/list.rb +14 -7
  46. data/lib/google/cloud/bigtable/value_range.rb +5 -0
  47. data/lib/google/cloud/bigtable/version.rb +1 -1
  48. metadata +27 -25
  49. data/lib/google/cloud/bigtable/table/column_family_map.rb +0 -70
@@ -17,6 +17,7 @@ module Google
17
17
  module Cloud
18
18
  module Bigtable
19
19
  class AppProfile
20
+ ##
20
21
  # # Job
21
22
  #
22
23
  # A resource representing the long-running, asynchronous processing of
@@ -34,7 +35,7 @@ module Google
34
35
  # bigtable = Google::Cloud::Bigtable.new
35
36
  #
36
37
  # instance = bigtable.instance("my-instance")
37
- # app_profile = bigtable.instance("my-app-profile")
38
+ # app_profile = instance.app_profile("my-app-profile")
38
39
  #
39
40
  # app_profile.description = "User data instance app profile"
40
41
  # routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
@@ -59,6 +60,7 @@ module Google
59
60
  # end
60
61
  #
61
62
  class Job < LongrunningJob
63
+ ##
62
64
  # The instance that is the object of the operation.
63
65
  #
64
66
  # @return [Google::Cloud::Bigtable::AppProfile, nil] The app profile instance, or
@@ -70,7 +72,7 @@ module Google
70
72
  # bigtable = Google::Cloud::Bigtable.new
71
73
  #
72
74
  # instance = bigtable.instance("my-instance")
73
- # app_profile = bigtable.instance("my-app-profile")
75
+ # app_profile = instance.app_profile("my-app-profile")
74
76
  #
75
77
  # app_profile.description = "User data instance app profile"
76
78
  # routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
@@ -81,11 +83,6 @@ module Google
81
83
  #
82
84
  # job = app_profile.save
83
85
  #
84
- # job.done? #=> false
85
- # job.reload!
86
- # job.done? #=> true
87
- #
88
- # # OR
89
86
  # job.wait_until_done!
90
87
  #
91
88
  # app_profile = job.app_profile
@@ -93,7 +90,7 @@ module Google
93
90
  def app_profile
94
91
  return nil unless done?
95
92
  return nil unless @grpc.grpc_op.result == :response
96
- AppProfile.from_grpc(@grpc.results, service)
93
+ AppProfile.from_grpc @grpc.results, service
97
94
  end
98
95
  end
99
96
  end
@@ -19,6 +19,7 @@ module Google
19
19
  module Cloud
20
20
  module Bigtable
21
21
  class AppProfile
22
+ ##
22
23
  # AppProfile::List is a special-case array with additional
23
24
  # values.
24
25
  class List < DelegateClass(::Array)
@@ -33,9 +34,10 @@ module Google
33
34
  # @private
34
35
  # Creates a new AppProfile::List with an array of snapshot instances.
35
36
  def initialize arr = []
36
- super(arr)
37
+ super arr
37
38
  end
38
39
 
40
+ ##
39
41
  # Whether there is a next page of instances.
40
42
  #
41
43
  # @return [Boolean]
@@ -51,10 +53,12 @@ module Google
51
53
  # if app_profiles.next?
52
54
  # next_app_profiles = app_profiles.next
53
55
  # end
56
+ #
54
57
  def next?
55
58
  grpc.next_page?
56
59
  end
57
60
 
61
+ ##
58
62
  # Retrieves the next page of app_profiles.
59
63
  #
60
64
  # @return [AppProfile::List] The list of instances.
@@ -70,14 +74,16 @@ module Google
70
74
  # if app_profiles.next?
71
75
  # next_app_profiles = app_profiles.next
72
76
  # end
77
+ #
73
78
  def next
74
79
  ensure_grpc!
75
80
 
76
81
  return nil unless next?
77
82
  grpc.next_page
78
- self.class.from_grpc(grpc, service)
83
+ self.class.from_grpc grpc, service
79
84
  end
80
85
 
86
+ ##
81
87
  # Retrieves remaining results by repeatedly invoking {#next} until
82
88
  # {#next?} returns `false`. Calls the given block once for each
83
89
  # result, which is passed as the argument to the block.
@@ -117,14 +123,14 @@ module Google
117
123
  # end
118
124
  #
119
125
  def all
120
- return enum_for(:all) unless block_given?
126
+ return enum_for :all unless block_given?
121
127
 
122
128
  results = self
123
129
  loop do
124
130
  results.each { |r| yield r }
125
131
  break unless next?
126
132
  grpc.next_page
127
- results = self.class.from_grpc(grpc, service)
133
+ results = self.class.from_grpc grpc, service
128
134
  end
129
135
  end
130
136
 
@@ -136,7 +142,7 @@ module Google
136
142
  def self.from_grpc grpc, service
137
143
  app_profiles = List.new(
138
144
  Array(grpc.response.app_profiles).map do |app_profile|
139
- AppProfile.from_grpc(app_profile, service)
145
+ AppProfile.from_grpc app_profile, service
140
146
  end
141
147
  )
142
148
  app_profiles.grpc = grpc
@@ -46,6 +46,7 @@ module Google
46
46
  reset_to_new_row
47
47
  end
48
48
 
49
+ ##
49
50
  # Process chunk and build full row with cells
50
51
  #
51
52
  # @param chunk [Google::Bigtable::V2::ReadRowsResponse::CellChunk]
@@ -53,12 +54,8 @@ module Google
53
54
  def process chunk
54
55
  self.chunk = chunk
55
56
 
56
- if chunk.commit_row
57
- raise_if(
58
- chunk.value_size > 0,
59
- "Commit rows cannot have a non-zero value_size."
60
- )
61
- end
57
+
58
+ raise_if chunk.value_size.positive?, "Commit rows cannot have a non-zero value_size." if chunk.commit_row
62
59
 
63
60
  if state == NEW_ROW
64
61
  process_new_row
@@ -69,6 +66,7 @@ module Google
69
66
  end
70
67
  end
71
68
 
69
+ ##
72
70
  # Validate row status commit or reset
73
71
  #
74
72
  # @raise [Google::Cloud::Bigtable::InvalidRowStateError]
@@ -81,11 +79,12 @@ module Google
81
79
  chunk.family_name ||
82
80
  chunk.qualifier ||
83
81
  !chunk.value.empty? ||
84
- chunk.timestamp_micros > 0)
82
+ chunk.timestamp_micros.positive?)
85
83
 
86
84
  raise_if value, "A reset should have no data"
87
85
  end
88
86
 
87
+ ##
89
88
  # Validate chunk has new row state
90
89
  #
91
90
  # @raise [Google::Cloud::Bigtable::InvalidRowStateError]
@@ -94,36 +93,29 @@ module Google
94
93
  # or if family name or column qualifier are empty
95
94
  #
96
95
  def validate_new_row
97
- raise_if(row.key, "A new row cannot have existing state")
98
- raise_if(chunk.row_key.empty?, "A row key must be set")
99
- raise_if(chunk.reset_row, "A new row cannot be reset")
100
- raise_if(
101
- last_key == chunk.row_key,
102
- "A commit happened but the same key followed"
103
- )
104
- raise_if(chunk.family_name.nil?, "A family must be set")
105
- raise_if(chunk.qualifier.nil?, "A column qualifier must be set")
96
+ raise_if row.key, "A new row cannot have existing state"
97
+ raise_if chunk.row_key.empty?, "A row key must be set"
98
+ raise_if chunk.reset_row, "A new row cannot be reset"
99
+ raise_if last_key == chunk.row_key, "A commit happened but the same key followed"
100
+ raise_if chunk.family_name.nil?, "A family must be set"
101
+ raise_if chunk.qualifier.nil?, "A column qualifier must be set"
106
102
  end
107
103
 
104
+ ##
108
105
  # Validate chunk merge is in progress to build new row
109
106
  #
110
107
  # @raise [Google::Cloud::Bigtable::InvalidRowStateError]
111
108
  # If row and chunk row key are not same or chunk row key is empty.
112
109
  #
113
110
  def validate_row_in_progress
114
- raise_if(
115
- !chunk.row_key.empty? && chunk.row_key != row.key,
116
- "A commit is required between row keys"
117
- )
111
+ raise_if !chunk.row_key.empty? && chunk.row_key != row.key, "A commit is required between row keys"
118
112
 
119
- raise_if(
120
- chunk.family_name && chunk.qualifier.nil?,
121
- "A qualifier must be specified"
122
- )
113
+ raise_if chunk.family_name && chunk.qualifier.nil?, "A qualifier must be specified"
123
114
 
124
115
  validate_reset_row
125
116
  end
126
117
 
118
+ ##
127
119
  # Process new row by setting values from current chunk.
128
120
  #
129
121
  # @return [Google::Cloud::Bigtable::Row]
@@ -142,6 +134,7 @@ module Google
142
134
  next_state!
143
135
  end
144
136
 
137
+ ##
145
138
  # Process chunk if row state is in progress
146
139
  #
147
140
  # @return [Google::Cloud::Bigtable::Row]
@@ -158,6 +151,7 @@ module Google
158
151
  next_state!
159
152
  end
160
153
 
154
+ ##
161
155
  # Process chunk if row cell state is in progress
162
156
  #
163
157
  # @return [Google::Cloud::Bigtable::Row]
@@ -170,6 +164,7 @@ module Google
170
164
  next_state!
171
165
  end
172
166
 
167
+ ##
173
168
  # Set next state of row.
174
169
  #
175
170
  # @return [Google::Cloud::Bigtable::Row]
@@ -198,13 +193,7 @@ module Google
198
193
 
199
194
  # Build cell and append to row.
200
195
  def persist_cell
201
- cell = Row::Cell.new(
202
- cur_family,
203
- cur_qaul,
204
- cur_ts,
205
- cur_val,
206
- cur_labels
207
- )
196
+ cell = Row::Cell.new cur_family, cur_qaul, cur_ts, cur_val, cur_labels
208
197
  row.cells[cur_family] << cell
209
198
 
210
199
  # Clear cached cell values
@@ -224,6 +213,7 @@ module Google
224
213
  self.cur_labels = nil
225
214
  end
226
215
 
216
+ ##
227
217
  # Validate last row is completed
228
218
  #
229
219
  # @raise [Google::Cloud::Bigtable::InvalidRowStateError]
@@ -232,14 +222,12 @@ module Google
232
222
  def validate_last_row_complete
233
223
  return if row.key.nil?
234
224
 
235
- raise_if(
236
- !chunk.commit_row,
237
- "Response ended with pending row without commit"
238
- )
225
+ raise_if !chunk.commit_row, "Response ended with pending row without commit"
239
226
  end
240
227
 
241
228
  private
242
229
 
230
+ ##
243
231
  # Raise error on condition failure
244
232
  #
245
233
  # @raise [Google::Cloud::Bigtable::InvalidRowStateError]
@@ -21,6 +21,7 @@ require "google/cloud/bigtable/cluster/job"
21
21
  module Google
22
22
  module Cloud
23
23
  module Bigtable
24
+ ##
24
25
  # # Cluster
25
26
  #
26
27
  # A configuration object describing how Cloud Bigtable should treat traffic
@@ -54,59 +55,74 @@ module Google
54
55
  @service = service
55
56
  end
56
57
 
58
+ ##
57
59
  # The unique identifier for the project.
58
60
  #
59
61
  # @return [String]
62
+ #
60
63
  def project_id
61
64
  @grpc.name.split("/")[1]
62
65
  end
63
66
 
67
+ ##
64
68
  # The unique identifier for the instance.
65
69
  #
66
70
  # @return [String]
71
+ #
67
72
  def instance_id
68
73
  @grpc.name.split("/")[3]
69
74
  end
70
75
 
76
+ ##
71
77
  # The unique identifier for the cluster.
72
78
  #
73
79
  # @return [String]
80
+ #
74
81
  def cluster_id
75
82
  @grpc.name.split("/")[5]
76
83
  end
77
84
 
85
+ ##
78
86
  # The unique name of the cluster. Value in the form
79
87
  # `projects/<project_id>/instances/<instance_id>/clusters/<cluster_id>`.
80
88
  #
81
89
  # @return [String]
90
+ #
82
91
  def path
83
92
  @grpc.name
84
93
  end
85
94
 
95
+ ##
86
96
  # The current instance state.
87
97
  # Possible values are
88
98
  # `:CREATING`, `:READY`, `:STATE_NOT_KNOWN`, `:RESIZING`, `:DISABLED`.
89
99
  #
90
100
  # @return [Symbol]
101
+ #
91
102
  def state
92
103
  @grpc.state
93
104
  end
94
105
 
106
+ ##
95
107
  # The cluster has been successfully created and is ready to serve requests.
96
108
  #
97
109
  # @return [Boolean]
110
+ #
98
111
  def ready?
99
112
  state == :READY
100
113
  end
101
114
 
115
+ ##
102
116
  # The instance is currently being created, and may be destroyed if the
103
117
  # creation process encounters an error.
104
118
  #
105
119
  # @return [Boolean]
120
+ #
106
121
  def creating?
107
122
  state == :CREATING
108
123
  end
109
124
 
125
+ ##
110
126
  # The cluster is currently being resized, and may revert to its previous
111
127
  # node count if the process encounters an error.
112
128
  # A cluster is still capable of serving requests while being resized,
@@ -114,59 +130,73 @@ module Google
114
130
  # between the starting and requested states.
115
131
  #
116
132
  # @return [Boolean]
133
+ #
117
134
  def resizing?
118
135
  state == :RESIZING
119
136
  end
120
137
 
138
+ ##
121
139
  # The cluster has no backing nodes. The data (tables) still
122
140
  # exist, but no operations can be performed on the cluster.
123
141
  #
124
142
  # @return [Boolean]
143
+ #
125
144
  def disabled?
126
145
  state == :DISABLED
127
146
  end
128
147
 
148
+ ##
129
149
  # The number of nodes allocated to this cluster.
130
150
  #
131
151
  # @return [Integer]
152
+ #
132
153
  def nodes
133
154
  @grpc.serve_nodes
134
155
  end
135
156
 
157
+ ##
136
158
  # The number of nodes allocated to this cluster. More nodes enable higher
137
159
  # throughput and more consistent performance.
138
160
  #
139
161
  # @param serve_nodes [Integer] Number of nodes
162
+ #
140
163
  def nodes= serve_nodes
141
164
  @grpc.serve_nodes = serve_nodes
142
165
  end
143
166
 
167
+ ##
144
168
  # The type of storage used by this cluster to serve its
145
169
  # parent instance's tables, unless explicitly overridden.
146
170
  # Valid values are `:SSD`(Flash (SSD) storage should be used),
147
171
  # `:HDD`(Magnetic drive (HDD) storage should be used)
148
172
  #
149
173
  # @return [Symbol]
174
+ #
150
175
  def storage_type
151
176
  @grpc.default_storage_type
152
177
  end
153
178
 
179
+ ##
154
180
  # Cluster location.
155
181
  # For example, "us-east1-b"
156
182
  #
157
183
  # @return [String]
184
+ #
158
185
  def location
159
186
  @grpc.location.split("/")[3]
160
187
  end
161
188
 
189
+ ##
162
190
  # Cluster location path in form of
163
191
  # `projects/<project_id>/locations/<zone>`
164
192
  #
165
193
  # @return [String]
194
+ #
166
195
  def location_path
167
196
  @grpc.location
168
197
  end
169
198
 
199
+ ##
170
200
  # Update cluster.
171
201
  #
172
202
  # `serve_nodes` is the only updatable field
@@ -199,25 +229,22 @@ module Google
199
229
  #
200
230
  def save
201
231
  ensure_service!
202
- grpc = service.update_cluster(
203
- instance_id,
204
- cluster_id,
205
- location_path,
206
- nodes
207
- )
208
- Cluster::Job.from_grpc(grpc, service)
232
+ grpc = service.update_cluster instance_id, cluster_id, location_path, nodes
233
+ Cluster::Job.from_grpc grpc, service
209
234
  end
210
235
  alias update save
211
236
 
237
+ ##
212
238
  # Reloads cluster information.
213
239
  #
214
240
  # @return [Google::Cloud::Bigtable::Cluster]
215
-
241
+ #
216
242
  def reload!
217
- @grpc = service.get_cluster(instance_id, cluster_id)
243
+ @grpc = service.get_cluster instance_id, cluster_id
218
244
  self
219
245
  end
220
246
 
247
+ ##
221
248
  # Permanently deletes the cluster.
222
249
  #
223
250
  # @return [Boolean] Returns `true` if the cluster was deleted.
@@ -233,7 +260,7 @@ module Google
233
260
  #
234
261
  def delete
235
262
  ensure_service!
236
- service.delete_cluster(instance_id, cluster_id)
263
+ service.delete_cluster instance_id, cluster_id
237
264
  true
238
265
  end
239
266
 
@@ -246,7 +273,7 @@ module Google
246
273
  # @param service [Google::Cloud::Bigtable::Service]
247
274
  # @return [Google::Cloud::Bigtable::Cluster]
248
275
  def self.from_grpc grpc, service
249
- new(grpc, service)
276
+ new grpc, service
250
277
  end
251
278
 
252
279
  protected