BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
7082530d
Commit
7082530d
authored
Jul 10, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Schedule stages statuses bg migrations in batches
parent
6120dc26
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
12 deletions
+16
-12
20170630111158_migrate_stages_statuses.rb
db/post_migrate/20170630111158_migrate_stages_statuses.rb
+8
-7
migrate_stage_status.rb
lib/gitlab/background_migration/migrate_stage_status.rb
+3
-2
migrate_stages_statuses_spec.rb
spec/migrations/migrate_stages_statuses_spec.rb
+5
-3
No files found.
db/post_migrate/20170630111158_migrate_stages_statuses.rb
View file @
7082530d
...
@@ -6,21 +6,22 @@ class MigrateStagesStatuses < ActiveRecord::Migration
...
@@ -6,21 +6,22 @@ class MigrateStagesStatuses < ActiveRecord::Migration
disable_ddl_transaction!
disable_ddl_transaction!
BATCH_SIZE
=
10000
BATCH_SIZE
=
10000
RANGE_SIZE
=
1000
MIGRATION
=
'MigrateStageStatus'
.
freeze
MIGRATION
=
'MigrateStageStatus'
.
freeze
class
Stage
<
ActiveRecord
::
Base
class
Stage
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_stages'
self
.
table_name
=
'ci_stages'
include
::
EachBatch
end
end
def
up
def
up
index
=
1
Stage
.
where
(
status:
nil
).
each_batch
(
of:
BATCH_SIZE
)
do
|
relation
,
index
|
relation
.
each_batch
(
of:
RANGE_SIZE
)
do
|
batch
|
range
=
relation
.
pluck
(
'MIN(id)'
,
'MAX(id)'
).
first
schedule
=
index
*
5
.
minutes
Stage
.
where
(
status:
nil
).
in_batches
(
of:
BATCH_SIZE
)
do
|
relation
|
BackgroundMigrationWorker
.
perform_in
(
schedule
,
MIGRATION
,
range
)
jobs
=
relation
.
pluck
(
:id
).
map
{
|
id
|
[
MIGRATION
,
[
id
]]
}
end
schedule
=
index
*
5
.
minutes
index
+=
1
BackgroundMigrationWorker
.
perform_bulk_in
(
schedule
,
jobs
)
end
end
end
end
...
...
lib/gitlab/background_migration/migrate_stage_status.rb
View file @
7082530d
...
@@ -58,7 +58,7 @@ module Gitlab
...
@@ -58,7 +58,7 @@ module Gitlab
end
end
end
end
def
perform
(
id
)
def
perform
(
start_id
,
stop_
id
)
status_sql
=
Build
status_sql
=
Build
.
where
(
'ci_builds.commit_id = ci_stages.pipeline_id'
)
.
where
(
'ci_builds.commit_id = ci_stages.pipeline_id'
)
.
where
(
'ci_builds.stage = ci_stages.name'
)
.
where
(
'ci_builds.stage = ci_stages.name'
)
...
@@ -66,7 +66,8 @@ module Gitlab
...
@@ -66,7 +66,8 @@ module Gitlab
sql
=
<<-
SQL
sql
=
<<-
SQL
UPDATE ci_stages SET status = (
#{
status_sql
}
)
UPDATE ci_stages SET status = (
#{
status_sql
}
)
WHERE ci_stages.id =
#{
id
.
to_i
}
WHERE ci_stages.status IS NULL
AND ci_stages.id BETWEEN
#{
start_id
.
to_i
}
AND
#{
stop_id
.
to_i
}
SQL
SQL
ActiveRecord
::
Base
.
connection
.
execute
(
sql
)
ActiveRecord
::
Base
.
connection
.
execute
(
sql
)
...
...
spec/migrations/migrate_stages_statuses_spec.rb
View file @
7082530d
...
@@ -12,6 +12,7 @@ describe MigrateStagesStatuses, :migration do
...
@@ -12,6 +12,7 @@ describe MigrateStagesStatuses, :migration do
before
do
before
do
stub_const
(
"
#{
described_class
.
name
}
::BATCH_SIZE"
,
2
)
stub_const
(
"
#{
described_class
.
name
}
::BATCH_SIZE"
,
2
)
stub_const
(
"
#{
described_class
.
name
}
::RANGE_SIZE"
,
1
)
projects
.
create!
(
id:
1
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
1
,
name:
'gitlab1'
,
path:
'gitlab1'
)
projects
.
create!
(
id:
2
,
name:
'gitlab2'
,
path:
'gitlab2'
)
projects
.
create!
(
id:
2
,
name:
'gitlab2'
,
path:
'gitlab2'
)
...
@@ -49,9 +50,10 @@ describe MigrateStagesStatuses, :migration do
...
@@ -49,9 +50,10 @@ describe MigrateStagesStatuses, :migration do
Timecop
.
freeze
do
Timecop
.
freeze
do
migrate!
migrate!
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
5
.
minutes
,
1
)
puts
BackgroundMigrationWorker
.
jobs
.
inspect
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
5
.
minutes
,
2
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
5
.
minutes
,
1
,
1
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
10
.
minutes
,
3
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
5
.
minutes
,
2
,
2
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
10
.
minutes
,
3
,
3
)
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
3
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
3
end
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