Fix bugs when splitting batched migration jobs
What does this MR do?
-
Fetch last migration job by
max_value
.When we split failed jobs, the job with the highest ID will no longer be the one with the highest
max_value
. These caused new migration jobs to be created for succeeding IDs even though we already have jobs for those. -
Make sure jobs are picked up after being split
The migration runner only picks up existing jobs that are failed with attempts less than the max, or jobs that are stuck in pending or running for an hour.
We keep the split jobs in the failed state so that they can be picked up immediately.
Migration output
== 20210709085759 IndexBatchedMigrationJobsByMaxValue: migrating ==============
-- transaction_open?()
-> 0.0000s
-- index_exists?(:batched_background_migration_jobs, [:batched_background_migration_id, :max_value], {:name=>"index_migration_jobs_on_migration_id_and_max_value", :algorithm=>:concurrently})
-> 0.0047s
-- add_index(:batched_background_migration_jobs, [:batched_background_migration_id, :max_value], {:name=>"index_migration_jobs_on_migration_id_and_max_value", :algorithm=>:concurrently})
-> 0.0095s
== 20210709085759 IndexBatchedMigrationJobsByMaxValue: migrated (0.0155s) =====
== 20210709085759 IndexBatchedMigrationJobsByMaxValue: reverting ==============
-- transaction_open?()
-> 0.0000s
-- indexes(:batched_background_migration_jobs)
-> 0.0043s
-- remove_index(:batched_background_migration_jobs, {:algorithm=>:concurrently, :name=>"index_migration_jobs_on_migration_id_and_max_value"})
-> 0.0036s
== 20210709085759 IndexBatchedMigrationJobsByMaxValue: reverted (0.0093s) =====
Screenshots or Screencasts (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Related to #332613 (closed)