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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
b41b4d2e
Commit
b41b4d2e
authored
Jul 07, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new `each_batch` helper instead of custom one
In stage_id backgrond migration.
parent
b7b3aef4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
11 deletions
+13
-11
app/models/concerns/each_batch.rb
app/models/concerns/each_batch.rb
+2
-2
db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
...0170628080858_migrate_stage_id_reference_in_background.rb
+8
-6
spec/migrations/migrate_stage_id_reference_in_background_spec.rb
...grations/migrate_stage_id_reference_in_background_spec.rb
+3
-3
No files found.
app/models/concerns/each_batch.rb
View file @
b41b4d2e
...
@@ -35,7 +35,7 @@ module EachBatch
...
@@ -35,7 +35,7 @@ module EachBatch
start_id
=
start
[
primary_key
]
start_id
=
start
[
primary_key
]
arel_table
=
self
.
arel_table
arel_table
=
self
.
arel_table
loop
do
1
.
step
do
|
index
|
stop
=
except
(
:select
)
stop
=
except
(
:select
)
.
select
(
primary_key
)
.
select
(
primary_key
)
.
where
(
arel_table
[
primary_key
].
gteq
(
start_id
))
.
where
(
arel_table
[
primary_key
].
gteq
(
start_id
))
...
@@ -54,7 +54,7 @@ module EachBatch
...
@@ -54,7 +54,7 @@ module EachBatch
# Any ORDER BYs are useless for this relation and can lead to less
# Any ORDER BYs are useless for this relation and can lead to less
# efficient UPDATE queries, hence we get rid of it.
# efficient UPDATE queries, hence we get rid of it.
yield
relation
.
except
(
:order
)
yield
relation
.
except
(
:order
)
,
index
break
unless
stop
break
unless
stop
end
end
...
...
db/post_migrate/20170628080858_migrate_stage_id_reference_in_background.rb
View file @
b41b4d2e
...
@@ -7,18 +7,20 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
...
@@ -7,18 +7,20 @@ class MigrateStageIdReferenceInBackground < ActiveRecord::Migration
disable_ddl_transaction!
disable_ddl_transaction!
class
Build
<
ActiveRecord
::
Base
self
.
table_name
=
'ci_builds'
include
::
EachBatch
end
##
##
# It will take around 3 days to process 20M ci_builds.
# It will take around 3 days to process 20M ci_builds.
#
#
def
up
def
up
opts
=
{
scope:
->
(
table
,
query
)
{
query
.
where
(
table
[
:stage_id
].
eq
(
nil
))
},
Build
.
all
.
each_batch
(
of:
BATCH_SIZE
)
do
|
relation
,
index
|
of:
BATCH_SIZE
}
range
=
relation
.
pluck
(
'MIN(id)'
,
'MAX(id)'
).
first
walk_table_in_batches
(
:ci_builds
,
**
opts
)
do
|
index
,
start_id
,
stop_id
|
schedule
=
index
*
2
.
minutes
schedule
=
index
*
2
.
minutes
BackgroundMigrationWorker
BackgroundMigrationWorker
.
perform_in
(
schedule
,
MIGRATION
,
range
)
.
perform_in
(
schedule
,
MIGRATION
,
[
start_id
,
stop_id
])
end
end
end
end
...
...
spec/migrations/migrate_stage_id_reference_in_background_spec.rb
View file @
b41b4d2e
...
@@ -47,9 +47,9 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
...
@@ -47,9 +47,9 @@ describe MigrateStageIdReferenceInBackground, :migration, :sidekiq do
Timecop
.
freeze
do
Timecop
.
freeze
do
migrate!
migrate!
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
2
.
minutes
,
1
,
3
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
2
.
minutes
,
1
,
2
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
4
.
minutes
,
3
,
5
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
4
.
minutes
,
3
,
4
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
6
.
minutes
,
5
,
0
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_migration
(
6
.
minutes
,
5
,
6
)
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