Cloud Bigtable API - Class Google::Cloud::Bigtable::GcRule (v2.8.0)

Reference documentation and code samples for the Cloud Bigtable API class Google::Cloud::Bigtable::GcRule.

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.

Inherits

  • Object

Example

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

Methods

.intersection

def self.intersection(*rules) -> Google::Cloud::Bigtable::GcRule

Creates a intersection GCRule instance.

Parameter
Example
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

.max_age

def self.max_age(age) -> Google::Cloud::Bigtable::GcRule

Creates a GcRule instance with max age.

Parameter
  • age (Integer) — Max age in seconds.
Example
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

.max_versions

def self.max_versions(versions) -> Google::Cloud::Bigtable::GcRule

Creates a GcRule instance with max number of versions.

Parameter
  • versions (Integer) — Max number of versions
Example
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

.union

def self.union(*rules) -> Google::Cloud::Bigtable::GcRule

Creates a union GcRule instance.

Parameter
Example
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

#intersection

def intersection() -> Array<Google::Cloud::Bigtable::GcRule>, nil

Gets the intersection rules collection for this GcRule.

Returns
Example
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

#intersection=

def intersection=(rules)

Sets the intersection rules collection for this GcRule.

Parameter

#max_age

def max_age() -> Numeric, nil

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.

Returns
  • (Numeric, nil) — Max age in seconds.
Example
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

#max_age=

def max_age=(age)

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.

Parameter
  • age (Numeric) — Max age in seconds. Values must be at least one millisecond, and will be truncated to microsecond granularity.

#max_versions

def max_versions() -> Integer, nil

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

Returns
  • (Integer, nil)
Example
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

#max_versions=

def max_versions=(versions)

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

Parameter
  • versions (Integer)

#union

def union() -> Array<Google::Cloud::Bigtable::GcRule>, nil

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.

Returns
Example
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

#union=

def union=(rules)

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.

Parameter