Commit 6bb48b5f authored by Simon Tomlinson's avatar Simon Tomlinson Committed by Andreas Brandl

Hide dry run partition pruning behind feature flag

Adds the partition_pruning_dry_run feature flag.

Even though the partition manager does not actually detach any
partitions yet, putting the logic for determining the set of partitions
to detach behind a flag makes rolling out this code safer, because the
logic changed touches the logic for creating new partitions.

Feature flag issue: https://gitlab.com/gitlab-org/gitlab/-/issues/335315
parent eb50ab6e
---
name: partition_pruning_dry_run
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65093
rollout_issue_url:
milestone: '14.1'
type: development
group: group::database
default_enabled: false
...@@ -86,7 +86,7 @@ module Gitlab ...@@ -86,7 +86,7 @@ module Gitlab
end end
def pruning_old_partitions? def pruning_old_partitions?
retain_for.present? Feature.enabled?(:partition_pruning_dry_run) && retain_for.present?
end end
def oldest_active_date def oldest_active_date
......
...@@ -46,6 +46,8 @@ module Gitlab ...@@ -46,6 +46,8 @@ module Gitlab
end end
def detach_partitions def detach_partitions
return unless Feature.enabled?(:partition_pruning_dry_run)
models.each do |model| models.each do |model|
next if extra_partitions(model).empty? next if extra_partitions(model).empty?
......
...@@ -237,6 +237,16 @@ RSpec.describe Gitlab::Database::Partitioning::MonthlyStrategy do ...@@ -237,6 +237,16 @@ RSpec.describe Gitlab::Database::Partitioning::MonthlyStrategy do
expect(subject).to contain_exactly(min_value_to_may) expect(subject).to contain_exactly(min_value_to_may)
end end
context 'when the feature flag is toggled off' do
before do
stub_feature_flags(partition_pruning_dry_run: false)
end
it 'is empty' do
expect(subject).to eq([])
end
end
end end
context 'with a time retention policy of 2 months' do context 'with a time retention policy of 2 months' do
...@@ -248,6 +258,16 @@ RSpec.describe Gitlab::Database::Partitioning::MonthlyStrategy do ...@@ -248,6 +258,16 @@ RSpec.describe Gitlab::Database::Partitioning::MonthlyStrategy do
Gitlab::Database::Partitioning::TimePartition.new(model.table_name, '2020-05-01', '2020-06-01', partition_name: 'partitioned_test_202005') Gitlab::Database::Partitioning::TimePartition.new(model.table_name, '2020-05-01', '2020-06-01', partition_name: 'partitioned_test_202005')
) )
end end
context 'when the feature flag is toggled off' do
before do
stub_feature_flags(partition_pruning_dry_run: false)
end
it 'is empty' do
expect(subject).to eq([])
end
end
end end
end end
end end
......
...@@ -118,6 +118,10 @@ RSpec.describe Gitlab::Database::Partitioning::PartitionManager do ...@@ -118,6 +118,10 @@ RSpec.describe Gitlab::Database::Partitioning::PartitionManager do
] ]
end end
context 'with the partition_pruning_dry_run feature flag enabled' do
before do
stub_feature_flags(partition_pruning_dry_run: true)
end
it 'detaches each extra partition' do it 'detaches each extra partition' do
extra_partitions.each { |p| expect(manager).to receive(:detach_one_partition).with(p) } extra_partitions.each { |p| expect(manager).to receive(:detach_one_partition).with(p) }
...@@ -142,4 +146,16 @@ RSpec.describe Gitlab::Database::Partitioning::PartitionManager do ...@@ -142,4 +146,16 @@ RSpec.describe Gitlab::Database::Partitioning::PartitionManager do
end end
end end
end end
context 'with the partition_pruning_dry_run feature flag disabled' do
before do
stub_feature_flags(partition_pruning_dry_run: false)
end
it 'returns immediately' do
expect(manager).not_to receive(:detach)
subject
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment