Skip to content

Accept multiple values for list partitioning

Marius Bobin requested to merge mb-ci-list-partition-multiple-values into master

What does this MR do and why?

ci_pipeline_variables is a partition of p_ci_pipeline_variables for values in 100 and 101, but the current strategy works with single value partitions. We need a new partition definition that's able to work with multiple values.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Register Ci::PipelineVariable as partitioned:
diff --git a/app/models/ci/pipeline_variable.rb b/app/models/ci/pipeline_variable.rb
index d83bb29ff80d..7079d16f1759 100644
--- a/app/models/ci/pipeline_variable.rb
+++ b/app/models/ci/pipeline_variable.rb
@@ -10,8 +10,9 @@ class PipelineVariable < Ci::ApplicationRecord

     self.primary_key = :id
     self.sequence_name = :ci_pipeline_variables_id_seq
+    self.table_name = :p_ci_pipeline_variables

-    partitionable scope: :pipeline
+    partitionable scope: :pipeline, partitioned: true

     alias_attribute :secret_value, :value

diff --git a/config/initializers/postgres_partitioning.rb b/config/initializers/postgres_partitioning.rb
index 5086f6f7da29..6c1bd093b625 100644
--- a/config/initializers/postgres_partitioning.rb
+++ b/config/initializers/postgres_partitioning.rb
@@ -13,7 +13,8 @@
     BatchedGitRefUpdates::Deletion,
     Users::ProjectVisit,
     Users::GroupVisit,
-    Ci::Catalog::Resources::SyncEvent
+    Ci::Catalog::Resources::SyncEvent,
+    Ci::PipelineVariable
   ])

 if Gitlab.ee?
  1. In the console:
[5] pry(main)> CommitStatus.partitioning_strategy.current_partitions
=> [#<Gitlab::Database::Partitioning::MultipleNumericListPartition:0x000000011365c868 @partition_name="ci_builds", @table="p_ci_builds", @values=[100]>, #<Gitlab::Database::Partitioning::MultipleNumericListPartition:0x000000011365c728 @partition_name="ci_builds_101", @table="p_ci_builds", @values=[101]>]
[6] pry(main)> Ci::PipelineVariable.partitioning_strategy.current_partitions
=> [#<Gitlab::Database::Partitioning::MultipleNumericListPartition:0x0000000112955200 @partition_name="ci_pipeline_variables", @table="p_ci_pipeline_variables", @values=[100, 101]>]
Edited by Marius Bobin

Merge request reports