Class: Gitlab::Database::Partitioning::MonthlyStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/database/partitioning/monthly_strategy.rb

Constant Summary collapse

HEADROOM =

We create this many partitions in the future

6.months

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, partitioning_key, retain_for: nil, retain_non_empty_partitions: false) ⇒ MonthlyStrategy

Returns a new instance of MonthlyStrategy.


14
15
16
17
18
19
# File 'lib/gitlab/database/partitioning/monthly_strategy.rb', line 14

def initialize(model, partitioning_key, retain_for: nil, retain_non_empty_partitions: false)
  @model = model
  @partitioning_key = partitioning_key
  @retain_for = retain_for
  @retain_non_empty_partitions = retain_non_empty_partitions
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.


7
8
9
# File 'lib/gitlab/database/partitioning/monthly_strategy.rb', line 7

def model
  @model
end

#partitioning_keyObject (readonly)

Returns the value of attribute partitioning_key.


7
8
9
# File 'lib/gitlab/database/partitioning/monthly_strategy.rb', line 7

def partitioning_key
  @partitioning_key
end

#retain_forObject (readonly)

Returns the value of attribute retain_for.


7
8
9
# File 'lib/gitlab/database/partitioning/monthly_strategy.rb', line 7

def retain_for
  @retain_for
end

#retain_non_empty_partitionsObject (readonly)

Returns the value of attribute retain_non_empty_partitions.


7
8
9
# File 'lib/gitlab/database/partitioning/monthly_strategy.rb', line 7

def retain_non_empty_partitions
  @retain_non_empty_partitions
end

Instance Method Details

#after_adding_partitionsObject


39
40
41
# File 'lib/gitlab/database/partitioning/monthly_strategy.rb', line 39

def after_adding_partitions
  # No-op, required by the partition manager
end

#current_partitionsObject


21
22
23
24
25
# File 'lib/gitlab/database/partitioning/monthly_strategy.rb', line 21

def current_partitions
  Gitlab::Database::PostgresPartition.for_parent_table(table_name).map do |partition|
    TimePartition.from_sql(table_name, partition.name, partition.condition)
  end
end

#extra_partitionsObject


32
33
34
35
36
37
# File 'lib/gitlab/database/partitioning/monthly_strategy.rb', line 32

def extra_partitions
  partitions = current_partitions - desired_partitions
  partitions.reject!(&:holds_data?) if retain_non_empty_partitions

  partitions
end

#missing_partitionsObject

Check the currently existing partitions and determine which ones are missing


28
29
30
# File 'lib/gitlab/database/partitioning/monthly_strategy.rb', line 28

def missing_partitions
  desired_partitions - current_partitions
end