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

See Also:

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:



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

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:



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

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:



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

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:



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

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:



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

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:



150
151
152
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 150

def intersection= rules
  @grpc.intersection = Google::Cloud::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.



140
141
142
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 140

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.



117
118
119
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 117

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)


104
105
106
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 104

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)


83
84
85
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 83

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:



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

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:



190
191
192
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 190

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