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

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

Overview

GcRule

Rule for determining which cells to delete during garbage collection. Garbage collection executes opportunistically in the background, and so it's possible for reads to return a cell even if it matches the active GC expression for its family.

NOTE: GC Rule can hold only one type at a time. GC Rule types:

  • max_num_versions - Delete all cells in a column except the most recent N
  • max_age - Delete cells in a column older than the given age.
  • union - Delete cells that would be deleted by every nested rule. It can have mutiple chainable GC Rules.
  • intersection - Delete cells that would be deleted by any nested rule. It can have mutiple chainable GC Rules.

Examples:

Create GC rule instance with max version.


gc_rule = Google::Cloud::Bigtable::GcRule.max_versions(3)

# Change max verions
gc_rule.max_versions = 5

Create GC rule instance with max age.


gc_rule = Google::Cloud::Bigtable::GcRule.max_age(3)

# Change max age
gc_rule.max_age = 600 # 10 minutes

Create GC rule instance with union.


max_age_gc_rule = Google::Cloud::Bigtable::GcRule.max_age(180)
union_gc_rule = Google::Cloud::Bigtable::GcRule.union(max_age_gc_rule)

# Change union GC rule
gc_rule.union = Google::Cloud::Bigtable::GcRule.max_age(600)

Create GC rule instance with intersection.


max_versions_gc_rule = Google::Cloud::Bigtable::GcRule.max_versions(3)
gc_rule = Google::Cloud::Bigtable::GcRule.intersection(max_versions_gc_rule)

# Change intersection GC rule
gc_rule.intersection = Google::Cloud::Bigtable::GcRule.max_age(600)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.intersection(*rules) ⇒ Google::Bigtable::Admin::V2::GcRule

Create intersection GCRule instance.

Parameters:

Returns:



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

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

.max_age(age) ⇒ Google::Bigtable::Admin::V2::GcRule

Create GcRule instance with max age.

Parameters:

  • age (Integer)

    Max age in seconds.

Returns:



166
167
168
169
170
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 166

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

.max_versions(versions) ⇒ Google::Bigtable::Admin::V2::GcRule

Create GcRule instance with max number of versions.

Parameters:

  • versions (Integer)

    Max number of versions

Returns:



155
156
157
158
159
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 155

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

.union(*rules) ⇒ Google::Bigtable::Admin::V2::GcRule

Create union GcRule instance.

Parameters:

Returns:



178
179
180
181
182
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 178

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

Instance Method Details

#intersectionGoogle::Bigtable::Admin::V2::GcRule::Intersection?

Get intersection GC rules



127
128
129
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 127

def intersection
  @grpc.intersection
end

#intersection=(rules) ⇒ Object

Delete cells that would be deleted by every nested rule.

Parameters:



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

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

#max_ageInteger?

Max age in seconds, if max age is set.

Returns:

  • (Integer, nil)

    Max age in seconds.



107
108
109
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 107

def max_age
  @grpc.max_age.seconds if @grpc.max_age
end

#max_age=(age) ⇒ Object

Delete cells in a column older than the given age. Values must be at least one millisecond, and will be truncated to microsecond granularity.

Parameters:

  • age (Integer)

    age in seconds



99
100
101
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 99

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

#max_versionsInteger?

Get max versions.

Returns:

  • (Integer, nil)


89
90
91
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 89

def max_versions
  @grpc.max_num_versions
end

#max_versions=(versions) ⇒ Object

Delete all cells in a column except the most recent N.

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

#unionGoogle::Bigtable::Admin::V2::GcRule::Union?

Get union GC rules



146
147
148
# File 'lib/google/cloud/bigtable/gc_rule.rb', line 146

def union
  @grpc.union
end

#union=(rules) ⇒ Object

Delete cells that would be deleted by any nested rule.

Parameters:



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

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