Commit 76d4449e authored by Andreas Brandl's avatar Andreas Brandl

Base job order on finished_at time

parent da5e21b3
---
title: Add index to support execution time order for batched migration jobs
merge_request: 60133
author:
type: other
# frozen_string_literal: true
class AddExecutionOrderIndexToBatchedBackgroundMigrationJobs < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
INDEX_NAME = 'index_migration_jobs_on_migration_id_and_finished_at'
def up
add_concurrent_index :batched_background_migration_jobs, %i(batched_background_migration_id finished_at), name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :batched_background_migration_jobs, INDEX_NAME
end
end
aa0ae491a7f94d99ea0c42250434245a4f23b0084657b709b0aaad0317dfd6b1
\ No newline at end of file
......@@ -23263,6 +23263,8 @@ CREATE INDEX index_metrics_dashboard_annotations_on_timespan_end ON metrics_dash
CREATE INDEX index_metrics_users_starred_dashboards_on_project_id ON metrics_users_starred_dashboards USING btree (project_id);
CREATE INDEX index_migration_jobs_on_migration_id_and_finished_at ON batched_background_migration_jobs USING btree (batched_background_migration_id, finished_at);
CREATE INDEX index_milestone_releases_on_release_id ON milestone_releases USING btree (release_id);
CREATE INDEX index_milestones_on_description_trigram ON milestones USING gin (description gin_trgm_ops);
......@@ -15,6 +15,8 @@ module Gitlab
succeeded: 3
}
scope :successful_in_execution_order, -> { where.not(finished_at: nil).succeeded.order(:finished_at) }
delegate :aborted?, :job_class, :table_name, :column_name, :job_arguments,
to: :batched_migration, prefix: :migration
......
......@@ -13,9 +13,6 @@ module Gitlab
has_one :last_job, -> { order(id: :desc) },
class_name: 'Gitlab::Database::BackgroundMigration::BatchedJob',
foreign_key: :batched_background_migration_id
has_many :last_jobs, -> { order(id: :desc) },
class_name: 'Gitlab::Database::BackgroundMigration::BatchedJob',
foreign_key: :batched_background_migration_id
scope :queue_order, -> { order(id: :asc) }
......@@ -81,7 +78,7 @@ module Gitlab
end
def smoothed_time_efficiency(number_of_jobs: 10, alpha: 0.2)
jobs = last_jobs.succeeded.limit(number_of_jobs)
jobs = batched_jobs.successful_in_execution_order.reverse_order.limit(number_of_jobs)
return if jobs.size < number_of_jobs
......
......@@ -268,7 +268,7 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigration, type: :m
let(:number_of_jobs) { 10 }
before do
expect(migration).to receive_message_chain(:last_jobs, :succeeded, :limit).with(no_args).with(no_args).with(number_of_jobs).and_return(jobs)
expect(migration).to receive_message_chain(:batched_jobs, :successful_in_execution_order, :reverse_order, :limit).with(no_args).with(no_args).with(number_of_jobs).and_return(jobs)
end
def mock_efficiencies(*effs)
......
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