diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-05-31 20:46:19 +0000 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-05-31 20:46:19 +0000 |
commit | 3e4862ac6d492807a0b2a6ba3dde819716dbfae1 (patch) | |
tree | a07f2c9b4f40afd7ab3b17256001f61d63b43ab5 /db | |
parent | 523ed2e72962e97be2603ab78aa13b372da582fa (diff) | |
parent | f3efec202986f820eaa1dc76db34b095e73a99f6 (diff) | |
download | gitlab-ce-3e4862ac6d492807a0b2a6ba3dde819716dbfae1.tar.gz |
Merge branch 'osw-reset-merge-status-from-mergeable-mrs' into 'master'
Reset merge status from mergeable MRs
See merge request gitlab-org/gitlab-ce!28843
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20190530154715_add_index_to_merge_requests_state_and_merge_status.rb | 21 | ||||
-rw-r--r-- | db/post_migrate/20190528180441_enqueue_reset_merge_status.rb | 30 | ||||
-rw-r--r-- | db/schema.rb | 3 |
3 files changed, 53 insertions, 1 deletions
diff --git a/db/migrate/20190530154715_add_index_to_merge_requests_state_and_merge_status.rb b/db/migrate/20190530154715_add_index_to_merge_requests_state_and_merge_status.rb new file mode 100644 index 00000000000..e669f81ca35 --- /dev/null +++ b/db/migrate/20190530154715_add_index_to_merge_requests_state_and_merge_status.rb @@ -0,0 +1,21 @@ +# 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 AddIndexToMergeRequestsStateAndMergeStatus < ActiveRecord::Migration[5.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + disable_ddl_transaction! + + def up + add_concurrent_index :merge_requests, [:state, :merge_status], + where: "state = 'opened' AND merge_status = 'can_be_merged'" + end + + def down + remove_concurrent_index :merge_requests, [:state, :merge_status] + end +end diff --git a/db/post_migrate/20190528180441_enqueue_reset_merge_status.rb b/db/post_migrate/20190528180441_enqueue_reset_merge_status.rb new file mode 100644 index 00000000000..1b668d85bac --- /dev/null +++ b/db/post_migrate/20190528180441_enqueue_reset_merge_status.rb @@ -0,0 +1,30 @@ +# 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 EnqueueResetMergeStatus < ActiveRecord::Migration[5.1] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + BATCH_SIZE = 10_000 + MIGRATION = 'ResetMergeStatus' + DELAY_INTERVAL = 5.minutes.to_i + + disable_ddl_transaction! + + def up + say 'Scheduling `ResetMergeStatus` jobs' + + # We currently have around 135_000 opened, mergeable MRs in GitLab.com. This iteration + # will schedule around 13 batches of 10_000 MRs, which should take around 1 hour to + # complete. + relation = MergeRequest.where(state: 'opened', merge_status: 'can_be_merged') + + relation.each_batch(of: BATCH_SIZE) do |batch, index| + range = batch.pluck('MIN(id)', 'MAX(id)').first + + BackgroundMigrationWorker.perform_in(index * DELAY_INTERVAL, MIGRATION, range) + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 378cb9c65d0..923b19893ef 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: 20190527194900) do +ActiveRecord::Schema.define(version: 20190530154715) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1361,6 +1361,7 @@ ActiveRecord::Schema.define(version: 20190527194900) do t.index ["source_branch"], name: "index_merge_requests_on_source_branch", using: :btree t.index ["source_project_id", "source_branch"], name: "index_merge_requests_on_source_project_and_branch_state_opened", where: "((state)::text = 'opened'::text)", using: :btree t.index ["source_project_id", "source_branch"], name: "index_merge_requests_on_source_project_id_and_source_branch", using: :btree + t.index ["state", "merge_status"], name: "index_merge_requests_on_state_and_merge_status", where: "(((state)::text = 'opened'::text) AND ((merge_status)::text = 'can_be_merged'::text))", using: :btree t.index ["target_branch"], name: "index_merge_requests_on_target_branch", using: :btree t.index ["target_project_id", "iid"], name: "index_merge_requests_on_target_project_id_and_iid", unique: true, using: :btree t.index ["target_project_id", "iid"], name: "index_merge_requests_on_target_project_id_and_iid_opened", where: "((state)::text = 'opened'::text)", using: :btree |