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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /db/post_migrate/20200805152108_migrate_null_external_diff_store_to_local_value.rb
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'db/post_migrate/20200805152108_migrate_null_external_diff_store_to_local_value.rb')
-rw-r--r--db/post_migrate/20200805152108_migrate_null_external_diff_store_to_local_value.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/db/post_migrate/20200805152108_migrate_null_external_diff_store_to_local_value.rb b/db/post_migrate/20200805152108_migrate_null_external_diff_store_to_local_value.rb
new file mode 100644
index 00000000000..e42f23d8fae
--- /dev/null
+++ b/db/post_migrate/20200805152108_migrate_null_external_diff_store_to_local_value.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+class MigrateNullExternalDiffStoreToLocalValue < ActiveRecord::Migration[6.0]
+ include Gitlab::Database::MigrationHelpers
+
+ DOWNTIME = false
+ JOB_INTERVAL = 2.minutes + 5.seconds
+ BATCH_SIZE = 5_000
+ MIGRATION = 'SetNullExternalDiffStoreToLocalValue'
+
+ disable_ddl_transaction!
+
+ class MergeRequestDiff < ActiveRecord::Base
+ self.table_name = 'merge_request_diffs'
+
+ include ::EachBatch
+ end
+
+ def up
+ # On GitLab.com, 19M of 93M rows have NULL external_diff_store.
+ #
+ # With batches of 5000 and a background migration job interval of 2m 5s,
+ # 3.8K jobs are scheduled over 5.5 days.
+ #
+ # The index `index_merge_request_diffs_external_diff_store_is_null` is
+ # expected to be used here and in the jobs.
+ #
+ # queue_background_migration_jobs_by_range_at_intervals is not used because
+ # it would enqueue 18.6K jobs and we have an index for getting these ranges.
+ MergeRequestDiff.where(external_diff_store: nil).each_batch(of: BATCH_SIZE) do |batch, index|
+ range = batch.pluck(Arel.sql("MIN(id)"), Arel.sql("MAX(id)")).first
+ delay = index * JOB_INTERVAL
+
+ migrate_in(delay.seconds, MIGRATION, [*range])
+ end
+ end
+
+ def down
+ # noop
+ end
+end