Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
cb8f648c
Commit
cb8f648c
authored
May 09, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tmp index to ci_builds to optimize stages migration
parent
3d93ad10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
1 deletion
+34
-1
db/migrate/20180420010616_cleanup_build_stage_migration.rb
db/migrate/20180420010616_cleanup_build_stage_migration.rb
+34
-1
No files found.
db/migrate/20180420010616_cleanup_build_stage_migration.rb
View file @
cb8f648c
...
...
@@ -2,6 +2,7 @@ class CleanupBuildStageMigration < ActiveRecord::Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
TMP_INDEX
=
'tmp_id_stage_partial_null_index'
.
freeze
disable_ddl_transaction!
...
...
@@ -13,16 +14,48 @@ class CleanupBuildStageMigration < ActiveRecord::Migration
end
def
up
disable_statement_timeout
##
# We steal from the background migrations queue to catch up with the
# scheduled migrations set.
#
Gitlab
::
BackgroundMigration
.
steal
(
'MigrateBuildStage'
)
##
# We add temporary index, to make iteration over batches more performant.
# Conditional here is to avoid the need of doing that in a separate
# migration file to make this operation idempotent.
#
unless
index_exists_by_name?
(
:ci_builds
,
TMP_INDEX
)
add_concurrent_index
(
:ci_builds
,
:id
,
where:
'stage_id IS NULL'
,
name:
TMP_INDEX
)
end
##
# We check if there are remaining rows that should be migrated (for example
# if Sidekiq / Redis fails / is restarted, what could result in not all
# background migrations being executed correctly.
#
# We migrate remaining rows synchronously in a blocking way, to make sure
# that when this migration is done we are confident that all rows are
# already migrated.
#
Build
.
where
(
'stage_id IS NULL'
).
each_batch
(
of:
50
)
do
|
batch
|
range
=
batch
.
pluck
(
'MIN(id)'
,
'MAX(id)'
).
first
Gitlab
::
BackgroundMigration
::
MigrateBuildStage
.
new
.
perform
(
*
range
)
end
##
# We remove temporary index, because it is not required during standard
# operations and runtime.
#
remove_concurrent_index_by_name
(
:ci_builds
,
TMP_INDEX
)
end
def
down
# noop
if
index_exists_by_name?
(
:ci_builds
,
TMP_INDEX
)
remove_concurrent_index_by_name
(
:ci_builds
,
TMP_INDEX
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment