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
Jérome Perrin
gitlab-ce
Commits
6cb5b7c8
Commit
6cb5b7c8
authored
6 years ago
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Recover from unique constraint violation in stages migration
parent
378b2bad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
10 deletions
+21
-10
db/post_migrate/20180212101928_schedule_build_stage_migration.rb
..._migrate/20180212101928_schedule_build_stage_migration.rb
+1
-1
lib/gitlab/background_migration/migrate_build_stage.rb
lib/gitlab/background_migration/migrate_build_stage.rb
+9
-9
spec/lib/gitlab/background_migration/migrate_build_stage_spec.rb
...b/gitlab/background_migration/migrate_build_stage_spec.rb
+11
-0
No files found.
db/post_migrate/20180212101928_schedule_build_stage_migration.rb
View file @
6cb5b7c8
...
...
@@ -3,7 +3,7 @@ class ScheduleBuildStageMigration < ActiveRecord::Migration
DOWNTIME
=
false
MIGRATION
=
'MigrateBuildStage'
.
freeze
BATCH_SIZE
=
5
00
BATCH_SIZE
=
8
00
disable_ddl_transaction!
...
...
This diff is collapsed.
Click to expand it.
lib/gitlab/background_migration/migrate_build_stage.rb
View file @
6cb5b7c8
...
...
@@ -13,19 +13,20 @@ module Gitlab
class
Build
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_builds'
def
ensure_stage!
find
||
creat
e!
def
ensure_stage!
(
attempts:
2
)
find
_stage
||
create_stag
e!
rescue
ActiveRecord
::
RecordNotUnique
# TODO
retry
if
(
attempts
-=
1
)
>
0
raise
end
def
find
Stage
.
find_by
(
name:
self
.
stage
,
def
find
_stage
Stage
.
find_by
(
name:
self
.
stage
||
'test'
,
pipeline_id:
self
.
commit_id
,
project_id:
self
.
project_id
)
end
def
create!
def
create
_stage
!
Stage
.
create!
(
name:
self
.
stage
||
'test'
,
pipeline_id:
self
.
commit_id
,
project_id:
self
.
project_id
)
...
...
@@ -34,11 +35,10 @@ module Gitlab
end
def
perform
(
start_id
,
stop_id
)
# TODO, should we disable_statement_timeout?
# TODO, use plain SQL query?
# TODO, statement timeout?
stages
=
Migratable
::
Build
.
where
(
'stage_id IS NULL'
)
.
where
(
"id BETWEEN
#{
start_id
.
to_i
}
AND
#{
stop_id
.
to_i
}
"
)
.
where
(
'id BETWEEN ? AND ?'
,
start_id
,
stop_id
)
.
map
{
|
build
|
build
.
ensure_stage!
}
.
compact
.
map
(
&
:id
)
...
...
This diff is collapsed.
Click to expand it.
spec/lib/gitlab/background_migration/migrate_build_stage_spec.rb
View file @
6cb5b7c8
...
...
@@ -40,4 +40,15 @@ describe Gitlab::BackgroundMigration::MigrateBuildStage, :migration, schema: 201
STATUSES
[
:failed
],
STATUSES
[
:pending
]]
end
it
'recovers from unique constraint violation only twice'
do
allow
(
described_class
::
Migratable
::
Stage
)
.
to
receive
(
:find_by
).
and_return
(
nil
)
expect
(
described_class
::
Migratable
::
Stage
)
.
to
receive
(
:find_by
).
exactly
(
3
).
times
expect
{
described_class
.
new
.
perform
(
1
,
6
)
}
.
to
raise_error
ActiveRecord
::
RecordNotUnique
end
end
This diff is collapsed.
Click to expand it.
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