diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-12-10 09:39:07 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-12-10 09:39:07 +0000 |
commit | 5a727a4d36674d02369f4ef8ed257ea9d17570e7 (patch) | |
tree | 29d2061b643bde9d3a8f5e448186bc191a10705d /db | |
parent | 853ba4b68a78e8cf39ae987d5e24af88b3d8a454 (diff) | |
parent | 4f6999fa26ea538084bf433dcc3a78cccafb3a54 (diff) | |
download | gitlab-ce-5a727a4d36674d02369f4ef8ed257ea9d17570e7.tar.gz |
Merge branch 'osw-update-mr-metrics-with-events-data' into 'master'
Populate MR metrics with events table information (migration)
Closes #41587
See merge request gitlab-org/gitlab-ce!23564
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20181204154019_populate_mr_metrics_with_events_data.rb | 38 | ||||
-rw-r--r-- | db/schema.rb | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/db/post_migrate/20181204154019_populate_mr_metrics_with_events_data.rb b/db/post_migrate/20181204154019_populate_mr_metrics_with_events_data.rb new file mode 100644 index 00000000000..1e43e3dd790 --- /dev/null +++ b/db/post_migrate/20181204154019_populate_mr_metrics_with_events_data.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class PopulateMrMetricsWithEventsData < ActiveRecord::Migration[4.2] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 10_000 + MIGRATION = 'PopulateMergeRequestMetricsWithEventsDataImproved' + PREVIOUS_MIGRATION = 'PopulateMergeRequestMetricsWithEventsData' + + disable_ddl_transaction! + + def up + # Perform any ongoing background migration that might still be running from + # previous try (see https://gitlab.com/gitlab-org/gitlab-ce/issues/47676). + Gitlab::BackgroundMigration.steal(PREVIOUS_MIGRATION) + + say 'Scheduling `PopulateMergeRequestMetricsWithEventsData` jobs' + # It will update around 4_000_000 records in batches of 10_000 merge + # requests (running between 5 minutes) and should take around 53 hours to complete. + # Apparently, production PostgreSQL is able to vacuum 10k-20k dead_tuples + # per minute. So this should give us enough space. + # + # More information about the updates in `PopulateMergeRequestMetricsWithEventsDataImproved` class. + # + MergeRequest.all.each_batch(of: BATCH_SIZE) do |relation, index| + range = relation.pluck('MIN(id)', 'MAX(id)').first + + BackgroundMigrationWorker.perform_in(index * 8.minutes, MIGRATION, range) + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index ff2dde3243c..e5e19eb7745 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20181203002526) do +ActiveRecord::Schema.define(version: 20181204154019) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" |