Class: Google::Cloud::Bigtable::GcRule

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/bigtable/gc_rule.rb

Overview

GcRule

A rule or rules for determining which cells to delete during garbage collection.

Garbage collection (GC) executes opportunistically in the background, so it is possible for reads to return a cell even if it matches the active GC expression for its column family.

GC Rule types:

  • max_num_versions - A garbage-collection rule that explicitly states the maximum number of cells to keep for all columns in a column family.
  • max_age - A garbage-collection rule based on the timestamp for each cell. With this type of garbage-collection rule, you set the time to live (TTL) for data. Cloud Bigtable looks at each column family during garbage collection and removes any cells that have expired.
  • union - A union garbage-collection policy will remove all data matching any of a set of given rules.
  • intersection - An intersection garbage-collection policy will remove all data matching all of a set of given rules.

Examples:

Create a table with column families.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table("my-instance", "my-table") do |cfm|
  cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
  cfm.add("cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))

  gc_rule = Google::Cloud::Bigtable::GcRule.union(
    Google::Cloud::Bigtable::GcRule.max_age(1800),
    Google::Cloud::Bigtable::GcRule.max_versions(3)
  )
  cfm.add("cf3", gc_rule: gc_rule)
end

puts table.column_families["cf1"].gc_rule.max_versions
puts table.column_families["cf2"].gc_rule.max_age
puts table.column_families["cf3"].gc_rule.union

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.intersection(*rules) ⇒ Google::Cloud::Bigtable::GcRule

Creates a intersection GCRule instance.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table("my-instance", "my-table") do |cfm|
  gc_rule = Google::Cloud::Bigtable::GcRule.intersection(
    Google::Cloud::Bigtable::GcRule.max_age(1800),
    Google::Cloud::Bigtable::GcRule.max_versions(3)
  )
  cfm.add("cf1", gc_rule: gc_rule)
end

Parameters:

Returns:



309
310
311
312
313
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 309

def self.intersection *rules
  new.tap do |gc_rule|
    gc_rule.intersection = rules
  end
end

.max_age(age) ⇒ Google::Cloud::Bigtable::GcRule

Creates a GcRule instance with max age.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table("my-instance", "my-table") do |cfm|
  cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
end

Parameters:

  • age (Integer)

    Max age in seconds.

Returns:



257
258
259
260
261
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 257

def self.max_age age
  new.tap do |gc_rule|
    gc_rule.max_age = age
  end
end

.max_versions(versions) ⇒ Google::Cloud::Bigtable::GcRule

Creates a GcRule instance with max number of versions.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table("my-instance", "my-table") do |cfm|
  cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
end

Parameters:

  • versions (Integer)

    Max number of versions

Returns:



236
237
238
239
240
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 236

def self.max_versions versions
  new.tap do |gc_rule|
    gc_rule.max_versions = versions
  end
end

.union(*rules) ⇒ Google::Cloud::Bigtable::GcRule

Creates a union GcRule instance.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table("my-instance", "my-table") do |cfm|
  gc_rule = Google::Cloud::Bigtable::GcRule.union(
    Google::Cloud::Bigtable::GcRule.max_age(1800),
    Google::Cloud::Bigtable::GcRule.max_versions(3)
  )
  cfm.add("cf1", gc_rule: gc_rule)
end

Parameters:

Returns:



283
284
285
286
287
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 283

def self.union *rules
  new.tap do |gc_rule|
    gc_rule.union = rules
  end
end

Instance Method Details

#intersectionArray<Google::Cloud::Bigtable::GcRule>?

Gets the intersection rules collection for this GcRule.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table("my-instance", "my-table") do |cfm|
  gc_rule = Google::Cloud::Bigtable::GcRule.intersection(
    Google::Cloud::Bigtable::GcRule.max_age(1800),
    Google::Cloud::Bigtable::GcRule.max_versions(3)
  )
  cfm.add("cf1", gc_rule: gc_rule)
end

puts table.column_families["cf1"].gc_rule.intersection

Returns:



173
174
175
176
177
178
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 173

def intersection
  return nil unless @grpc.intersection
  @grpc.intersection.rules.map do |gc_rule_grpc|
    self.class.from_grpc gc_rule_grpc
  end
end

#intersection=(rules) ⇒ Object

Sets the intersection rules collection for this GcRule.

Parameters:



148
149
150
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 148

def intersection= rules
  @grpc.intersection = Google::Bigtable::Admin::V2::GcRule::Intersection.new rules: rules.map(&:to_grpc)
end

#max_ageNumeric?

Gets the garbage-collection rule based on the timestamp for each cell. With this type of garbage-collection rule, you set the time to live (TTL) for data. Cloud Bigtable looks at each column family during garbage collection and removes any cells that have expired.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table("my-instance", "my-table") do |cfm|
  cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
end

puts table.column_families["cf1"].gc_rule.max_age

Returns:

  • (Numeric, nil)

    Max age in seconds.



138
139
140
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 138

def max_age
  Convert.duration_to_number @grpc.max_age
end

#max_age=(age) ⇒ Object

Sets a garbage-collection rule based on the timestamp for each cell. With this type of garbage-collection rule, you set the time to live (TTL) for data. Cloud Bigtable looks at each column family during garbage collection and removes any cells that have expired.

Parameters:

  • age (Numeric)

    Max age in seconds. Values must be at least one millisecond, and will be truncated to microsecond granularity.



115
116
117
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 115

def max_age= age
  @grpc.max_age = Convert.number_to_duration age
end

#max_versionsInteger?

Gets the garbage-collection rule that explicitly states the maximum number of cells to keep for all columns in a column family.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table("my-instance", "my-table") do |cfm|
  cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
end

puts table.column_families["cf1"].gc_rule.max_versions

Returns:

  • (Integer, nil)


102
103
104
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 102

def max_versions
  @grpc.max_num_versions
end

#max_versions=(versions) ⇒ Object

Sets a garbage-collection rule that explicitly states the maximum number of cells to keep for all columns in a column family.

Parameters:

  • versions (Integer)


81
82
83
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 81

def max_versions= versions
  @grpc.max_num_versions = versions
end

#unionArray<Google::Cloud::Bigtable::GcRule>?

Gets the union rules collection for this GcRule. A union garbage-collection policy will remove all data matching any of its set of given rules.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table("my-instance", "my-table") do |cfm|
  gc_rule = Google::Cloud::Bigtable::GcRule.union(
    Google::Cloud::Bigtable::GcRule.max_age(1800),
    Google::Cloud::Bigtable::GcRule.max_versions(3)
  )
  cfm.add("cf1", gc_rule: gc_rule)
end

puts table.column_families["cf1"].gc_rule.union

Returns:



214
215
216
217
218
219
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 214

def union
  return nil unless @grpc.union
  @grpc.union.rules.map do |gc_rule_grpc|
    self.class.from_grpc gc_rule_grpc
  end
end

#union=(rules) ⇒ Object

Sets the union rules collection for this GcRule. A union garbage-collection policy will remove all data matching any of its set of given rules.

Parameters:



188
189
190
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 188

def union= rules
  @grpc.union = Google::Bigtable::Admin::V2::GcRule::Union.new rules: rules.map(&:to_grpc)
end