From 7b3fcf900bdfc3136780cf7a7f80c71ac266c21b Mon Sep 17 00:00:00 2001 From: Maxime Orefice Date: Thu, 9 Feb 2023 10:16:17 +0100 Subject: [PATCH 1/2] Fix partition_id for ci_build_report_results Changelog: fixed --- ...artition_ids_for_ci_build_report_result.rb | 30 ++++++++++ db/schema_migrations/20230209090702 | 1 + ...ion_ids_for_ci_build_report_result_spec.rb | 60 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb create mode 100644 db/schema_migrations/20230209090702 create mode 100644 spec/migrations/20230209090702_fix_partition_ids_for_ci_build_report_result_spec.rb diff --git a/db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb b/db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb new file mode 100644 index 00000000000000..d21d986ee31e25 --- /dev/null +++ b/db/post_migrate/20230209090702_fix_partition_ids_for_ci_build_report_result.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +class FixPartitionIdsForCiBuildReportResult < Gitlab::Database::Migration[2.1] + MIGRATION = 'RebalancePartitionId' + DELAY_INTERVAL = 2.minutes.freeze + TABLE = :ci_build_report_results + BATCH_SIZE = 2_000 + SUB_BATCH_SIZE = 200 + + restrict_gitlab_migration gitlab_schema: :gitlab_ci + + def up + return unless Gitlab.com? + + queue_batched_background_migration( + MIGRATION, + TABLE, + :build_id, + job_interval: DELAY_INTERVAL, + batch_size: BATCH_SIZE, + sub_batch_size: SUB_BATCH_SIZE + ) + end + + def down + return unless Gitlab.com? + + delete_batched_background_migration(MIGRATION, TABLE, :build_id, []) + end +end diff --git a/db/schema_migrations/20230209090702 b/db/schema_migrations/20230209090702 new file mode 100644 index 00000000000000..9eb84a3b5d058d --- /dev/null +++ b/db/schema_migrations/20230209090702 @@ -0,0 +1 @@ +f3f0611b503bf2be35a201541826a33dd0ff58a0b41c6588303317f2b171d567 \ No newline at end of file diff --git a/spec/migrations/20230209090702_fix_partition_ids_for_ci_build_report_result_spec.rb b/spec/migrations/20230209090702_fix_partition_ids_for_ci_build_report_result_spec.rb new file mode 100644 index 00000000000000..cf8eaf70db6b88 --- /dev/null +++ b/spec/migrations/20230209090702_fix_partition_ids_for_ci_build_report_result_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe FixPartitionIdsForCiBuildReportResult, + migration: :gitlab_ci, + feature_category: :continuous_integration do + let(:migration) { described_class::MIGRATION } + + context 'when on saas' do + before do + allow(Gitlab).to receive(:com?).and_return(true) + end + + describe '#up' do + it 'schedules background jobs for each batch of ci_stages' do + migrate! + + expect(migration).to have_scheduled_batched_migration( + gitlab_schema: :gitlab_ci, + table_name: :ci_build_report_results, + column_name: :build_id, + interval: described_class::DELAY_INTERVAL, + batch_size: described_class::BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE + ) + end + end + + describe '#down' do + it 'deletes all batched migration records' do + migrate! + schema_migrate_down! + + expect(migration).not_to have_scheduled_batched_migration + end + end + end + + context 'when on self-managed instance' do + let(:migration) { described_class.new } + + describe '#up' do + it 'does not schedule background job' do + expect(migration).not_to receive(:queue_batched_background_migration) + + migration.up + end + end + + describe '#down' do + it 'does not delete background job' do + expect(migration).not_to receive(:delete_batched_background_migration) + + migration.down + end + end + end +end -- GitLab From d4520d55a5e4e43f7c205611b15e989b2c449c6d Mon Sep 17 00:00:00 2001 From: Maxime Orefice Date: Tue, 14 Feb 2023 14:54:01 +0100 Subject: [PATCH 2/2] Apply code review feedback --- ...9090702_fix_partition_ids_for_ci_build_report_result_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/migrations/20230209090702_fix_partition_ids_for_ci_build_report_result_spec.rb b/spec/migrations/20230209090702_fix_partition_ids_for_ci_build_report_result_spec.rb index cf8eaf70db6b88..f0ac8239f58100 100644 --- a/spec/migrations/20230209090702_fix_partition_ids_for_ci_build_report_result_spec.rb +++ b/spec/migrations/20230209090702_fix_partition_ids_for_ci_build_report_result_spec.rb @@ -14,7 +14,7 @@ end describe '#up' do - it 'schedules background jobs for each batch of ci_stages' do + it 'schedules background jobs for each batch of ci_build_report_results' do migrate! expect(migration).to have_scheduled_batched_migration( -- GitLab