Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-21 12:09:01 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-21 12:09:01 +0300
commita53d2c37c4934f564caa94543dd4cf5af1703e2d (patch)
treea028dc39771a4612a9845ab700a73af2d6f3f51b /lib
parent18b8435318887d3fc6e9f9d305967a953cdd7d3f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb32
-rw-r--r--lib/gitlab/database/migration_helpers.rb5
2 files changed, 35 insertions, 2 deletions
diff --git a/lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb b/lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb
new file mode 100644
index 00000000000..3aa1ebb49f9
--- /dev/null
+++ b/lib/gitlab/background_migration/cleanup_optimistic_locking_nulls.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+# rubocop:disable Style/Documentation
+
+module Gitlab
+ module BackgroundMigration
+ class CleanupOptimisticLockingNulls
+ QUERY_ITEM_SIZE = 1_000
+
+ # table - The name of the table the migration is performed for.
+ # start_id - The ID of the object to start at
+ # stop_id - The ID of the object to end at
+ def perform(start_id, stop_id, table)
+ model = define_model_for(table)
+
+ # After analysis done, a batch size of 1,000 items per query was found to be
+ # the most optimal. Discussion in https://gitlab.com/gitlab-org/gitlab/-/merge_requests/18418#note_282285336
+ (start_id..stop_id).each_slice(QUERY_ITEM_SIZE).each do |range|
+ model
+ .where(lock_version: nil)
+ .where(id: range)
+ .update_all(lock_version: 0)
+ end
+ end
+
+ def define_model_for(table)
+ Class.new(ActiveRecord::Base) do
+ self.table_name = table
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index 6317e034cfb..95a562ca1f3 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -1042,6 +1042,7 @@ into similar problems in the future (e.g. when new tables are created).
# job_class_name - The background migration job class as a string
# delay_interval - The duration between each job's scheduled time (must respond to `to_f`)
# batch_size - The maximum number of rows per job
+ # other_arguments - Other arguments to send to the job
#
# Example:
#
@@ -1059,7 +1060,7 @@ into similar problems in the future (e.g. when new tables are created).
# # do something
# end
# end
- def queue_background_migration_jobs_by_range_at_intervals(model_class, job_class_name, delay_interval, batch_size: BACKGROUND_MIGRATION_BATCH_SIZE)
+ def queue_background_migration_jobs_by_range_at_intervals(model_class, job_class_name, delay_interval, batch_size: BACKGROUND_MIGRATION_BATCH_SIZE, other_arguments: [])
raise "#{model_class} does not have an ID to use for batch ranges" unless model_class.column_names.include?('id')
# To not overload the worker too much we enforce a minimum interval both
@@ -1074,7 +1075,7 @@ into similar problems in the future (e.g. when new tables are created).
# `BackgroundMigrationWorker.bulk_perform_in` schedules all jobs for
# the same time, which is not helpful in most cases where we wish to
# spread the work over time.
- migrate_in(delay_interval * index, job_class_name, [start_id, end_id])
+ migrate_in(delay_interval * index, job_class_name, [start_id, end_id] + other_arguments)
end
end