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
end
def pruning_old_partitions?
retain_for.present?
Feature.enabled?(:partition_pruning_dry_run) && retain_for.present?
end
def oldest_active_date
......
......@@ -46,6 +46,8 @@ module Gitlab
end
def detach_partitions
return unless Feature.enabled?(:partition_pruning_dry_run)
models.each do |model|
next if extra_partitions(model).empty?
......
......@@ -237,6 +237,16 @@ RSpec.describe Gitlab::Database::Partitioning::MonthlyStrategy do
expect(subject).to contain_exactly(min_value_to_may)
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
context 'with a time retention policy of 2 months' 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')
)
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
......
......@@ -118,25 +118,41 @@ RSpec.describe Gitlab::Database::Partitioning::PartitionManager do
]
end
it 'detaches each extra partition' do
extra_partitions.each { |p| expect(manager).to receive(:detach_one_partition).with(p) }
subject
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
extra_partitions.each { |p| expect(manager).to receive(:detach_one_partition).with(p) }
context 'error handling' do
let(:models) do
[
double(partitioning_strategy: error_strategy, table_name: table),
model
]
subject
end
let(:error_strategy) { double }
context 'error handling' do
let(:models) do
[
double(partitioning_strategy: error_strategy, table_name: table),
model
]
end
it 'still drops partitions for the other model' do
expect(error_strategy).to receive(:extra_partitions).and_raise('injected error!')
extra_partitions.each { |p| expect(manager).to receive(:detach_one_partition).with(p) }
let(:error_strategy) { double }
it 'still drops partitions for the other model' do
expect(error_strategy).to receive(:extra_partitions).and_raise('injected error!')
extra_partitions.each { |p| expect(manager).to receive(:detach_one_partition).with(p) }
subject
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
......
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