Commit 1b0648b1 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch 'fix-batched-migration-retry-button' into 'master'

Fix retrying of batched background migrations

See merge request gitlab-org/gitlab!82387
parents 571badda 80c517ff
......@@ -92,7 +92,8 @@ module Gitlab
batched_migration.table_name,
batched_migration.column_name,
batch_min_value: min_value,
batch_size: new_batch_size
batch_size: new_batch_size,
job_arguments: batched_migration.job_arguments
)
midpoint = next_batch_bounds.last
......
......@@ -56,7 +56,13 @@ RSpec.describe "Admin > Admin sees background migrations" do
context 'when there are failed migrations' do
before do
allow_next_instance_of(Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy) do |batch_class|
allow(batch_class).to receive(:next_batch).with(anything, anything, batch_min_value: 6, batch_size: 5).and_return([6, 10])
allow(batch_class).to receive(:next_batch).with(
anything,
anything,
batch_min_value: 6,
batch_size: 5,
job_arguments: failed_migration.job_arguments
).and_return([6, 10])
end
end
......
......@@ -199,15 +199,17 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedJob, type: :model d
end
describe '#split_and_retry!' do
let!(:job) { create(:batched_background_migration_job, :failed, batch_size: 10, min_value: 6, max_value: 15, attempts: 3) }
let_it_be(:migration) { create(:batched_background_migration, table_name: :events) }
let_it_be(:job) { create(:batched_background_migration_job, :failed, batched_migration: migration, batch_size: 10, min_value: 6, max_value: 15, attempts: 3) }
let_it_be(:project) { create(:project) }
context 'when job can be split' do
before do
allow_next_instance_of(Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy) do |batch_class|
allow(batch_class).to receive(:next_batch).with(anything, anything, batch_min_value: 6, batch_size: 5).and_return([6, 10])
end
before_all do
(6..16).each do |id|
create(:event, id: id, project: project)
end
end
context 'when job can be split' do
it 'sets the correct attributes' do
expect { job.split_and_retry! }.to change { described_class.count }.by(1)
......@@ -263,9 +265,7 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedJob, type: :model d
context 'when computed midpoint is larger than the max value of the batch' do
before do
allow_next_instance_of(Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy) do |batch_class|
allow(batch_class).to receive(:next_batch).with(anything, anything, batch_min_value: 6, batch_size: 5).and_return([6, 16])
end
Event.where(id: 6..12).delete_all
end
it 'lowers the batch size and resets the number of attempts' do
......
......@@ -274,7 +274,13 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigration, type: :m
before do
allow_next_instance_of(Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy) do |batch_class|
allow(batch_class).to receive(:next_batch).with(anything, anything, batch_min_value: 6, batch_size: 5).and_return([6, 10])
allow(batch_class).to receive(:next_batch).with(
anything,
anything,
batch_min_value: 6,
batch_size: 5,
job_arguments: batched_migration.job_arguments
).and_return([6, 10])
end
end
......
......@@ -16,7 +16,13 @@ RSpec.describe Admin::BackgroundMigrationsController, :enable_admin_mode do
create(:batched_background_migration_job, :failed, batched_migration: migration, batch_size: 10, min_value: 6, max_value: 15, attempts: 3)
allow_next_instance_of(Gitlab::BackgroundMigration::BatchingStrategies::PrimaryKeyBatchingStrategy) do |batch_class|
allow(batch_class).to receive(:next_batch).with(anything, anything, batch_min_value: 6, batch_size: 5).and_return([6, 10])
allow(batch_class).to receive(:next_batch).with(
anything,
anything,
batch_min_value: 6,
batch_size: 5,
job_arguments: migration.job_arguments
).and_return([6, 10])
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