summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/copy_column_using_background_migration_job.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /lib/gitlab/background_migration/copy_column_using_background_migration_job.rb
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'lib/gitlab/background_migration/copy_column_using_background_migration_job.rb')
-rw-r--r--lib/gitlab/background_migration/copy_column_using_background_migration_job.rb28
1 files changed, 9 insertions, 19 deletions
diff --git a/lib/gitlab/background_migration/copy_column_using_background_migration_job.rb b/lib/gitlab/background_migration/copy_column_using_background_migration_job.rb
index 16c0de39a3b..60682bd2ec1 100644
--- a/lib/gitlab/background_migration/copy_column_using_background_migration_job.rb
+++ b/lib/gitlab/background_migration/copy_column_using_background_migration_job.rb
@@ -2,13 +2,11 @@
module Gitlab
module BackgroundMigration
- # Background migration that extends CopyColumn to update the value of a
+ # Background migration that updates the value of a
# column using the value of another column in the same table.
#
# - The {start_id, end_id} arguments are at the start so that it can be used
- # with `queue_background_migration_jobs_by_range_at_intervals`
- # - Provides support for background job tracking through the use of
- # Gitlab::Database::BackgroundMigrationJob
+ # with `queue_batched_background_migration`
# - Uses sub-batching so that we can keep each update's execution time at
# low 100s ms, while being able to update more records per 2 minutes
# that we allow background migration jobs to be scheduled one after the other
@@ -22,28 +20,24 @@ module Gitlab
# start_id - The start ID of the range of rows to update.
# end_id - The end ID of the range of rows to update.
- # table - The name of the table that contains the columns.
- # primary_key - The primary key column of the table.
- # copy_from - The column containing the data to copy.
- # copy_to - The column to copy the data to.
+ # batch_table - The name of the table that contains the columns.
+ # batch_column - The name of the column we use to batch over the table.
# sub_batch_size - We don't want updates to take more than ~100ms
# This allows us to run multiple smaller batches during
# the minimum 2.minute interval that we can schedule jobs
- def perform(start_id, end_id, table, primary_key, copy_from, copy_to, sub_batch_size)
+ # copy_from - The column containing the data to copy.
+ # copy_to - The column to copy the data to.
+ def perform(start_id, end_id, batch_table, batch_column, sub_batch_size, copy_from, copy_to)
quoted_copy_from = connection.quote_column_name(copy_from)
quoted_copy_to = connection.quote_column_name(copy_to)
- parent_batch_relation = relation_scoped_to_range(table, primary_key, start_id, end_id)
+ parent_batch_relation = relation_scoped_to_range(batch_table, batch_column, start_id, end_id)
- parent_batch_relation.each_batch(column: primary_key, of: sub_batch_size) do |sub_batch|
+ parent_batch_relation.each_batch(column: batch_column, of: sub_batch_size) do |sub_batch|
sub_batch.update_all("#{quoted_copy_to}=#{quoted_copy_from}")
sleep(PAUSE_SECONDS)
end
-
- # We have to add all arguments when marking a job as succeeded as they
- # are all used to track the job by `queue_background_migration_jobs_by_range_at_intervals`
- mark_job_as_succeeded(start_id, end_id, table, primary_key, copy_from, copy_to, sub_batch_size)
end
private
@@ -52,10 +46,6 @@ module Gitlab
ActiveRecord::Base.connection
end
- def mark_job_as_succeeded(*arguments)
- Gitlab::Database::BackgroundMigrationJob.mark_all_as_succeeded(self.class.name, arguments)
- end
-
def relation_scoped_to_range(source_table, source_key_column, start_id, stop_id)
define_batchable_model(source_table).where(source_key_column => start_id..stop_id)
end