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
1d8e8f3e
Commit
1d8e8f3e
authored
Oct 27, 2021
by
charlie ablett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests to reflect sub-batched query
parent
7f6ac436
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
21 deletions
+27
-21
lib/gitlab/background_migration/backfill_user_namespace.rb
lib/gitlab/background_migration/backfill_user_namespace.rb
+2
-10
spec/lib/gitlab/background_migration/backfill_user_namespace_spec.rb
...tlab/background_migration/backfill_user_namespace_spec.rb
+25
-11
No files found.
lib/gitlab/background_migration/backfill_user_namespace.rb
View file @
1d8e8f3e
...
@@ -7,23 +7,15 @@ module Gitlab
...
@@ -7,23 +7,15 @@ module Gitlab
class
BackfillUserNamespace
class
BackfillUserNamespace
include
Gitlab
::
Database
::
DynamicModelHelpers
include
Gitlab
::
Database
::
DynamicModelHelpers
def
perform
(
start_id
,
end_id
,
batch_table
,
batch_column
,
sub_batch_size
)
def
perform
(
start_id
,
end_id
,
batch_table
,
batch_column
,
sub_batch_size
,
pause_ms
)
parent_batch_relation
=
relation_scoped_to_range
(
batch_table
,
batch_column
,
start_id
,
end_id
)
parent_batch_relation
=
relation_scoped_to_range
(
batch_table
,
batch_column
,
start_id
,
end_id
)
parent_batch_relation
.
each_batch
(
column:
batch_column
,
of:
sub_batch_size
,
order_hint: :type
)
do
|
sub_batch
|
parent_batch_relation
.
each_batch
(
column:
batch_column
,
of:
sub_batch_size
)
do
|
sub_batch
|
batch_metrics
.
time_operation
(
:update_all
)
do
batch_metrics
.
time_operation
(
:update_all
)
do
sub_batch
.
update_all
(
type:
'User'
)
sub_batch
.
update_all
(
type:
'User'
)
end
end
pause_ms
=
0
if
pause_ms
<
0
pause_ms
=
0
if
pause_ms
<
0
sleep
(
pause_ms
*
0.001
)
sleep
(
pause_ms
*
0.001
)
end
end
# ActiveRecord::Base.connection.execute(<<~SQL)
# UPDATE namespaces SET type = 'User'
# WHERE id BETWEEN #{start_id} AND #{end_id}
# AND type IS NULL
# SQL
end
end
def
batch_metrics
def
batch_metrics
...
...
spec/lib/gitlab/background_migration/backfill_user_namespace_spec.rb
View file @
1d8e8f3e
...
@@ -2,24 +2,38 @@
...
@@ -2,24 +2,38 @@
require
'spec_helper'
require
'spec_helper'
RSpec
.
describe
Gitlab
::
BackgroundMigration
::
BackfillUserNamespace
do
RSpec
.
describe
Gitlab
::
BackgroundMigration
::
BackfillUserNamespace
,
:migration
,
schema:
20210930211936
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:migration
)
{
described_class
.
new
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:namespaces_table
)
{
table
(
:namespaces
)
}
let
(
:table_name
)
{
'namespaces'
}
let
(
:batch_column
)
{
:id
}
let
(
:sub_batch_size
)
{
100
}
let
(
:pause_ms
)
{
0
}
subject
(
:perform_migration
)
{
migration
.
perform
(
1
,
10
,
table_name
,
batch_column
,
sub_batch_size
,
pause_ms
)
}
before
do
before
do
namespaces
.
create!
(
id:
1
,
name:
'test1'
,
path:
'test1'
,
type:
nil
)
namespaces
_table
.
create!
(
id:
1
,
name:
'test1'
,
path:
'test1'
,
type:
nil
)
namespaces
.
create!
(
id:
2
,
name:
'test2'
,
path:
'test2'
,
type:
'User'
)
namespaces
_table
.
create!
(
id:
2
,
name:
'test2'
,
path:
'test2'
,
type:
'User'
)
namespaces
.
create!
(
id:
3
,
name:
'test3'
,
path:
'test3'
,
type:
'Group'
)
namespaces
_table
.
create!
(
id:
3
,
name:
'test3'
,
path:
'test3'
,
type:
'Group'
)
namespaces
.
create!
(
id:
4
,
name:
'test4'
,
path:
'test4'
,
type:
nil
)
namespaces
_table
.
create!
(
id:
4
,
name:
'test4'
,
path:
'test4'
,
type:
nil
)
namespaces
.
create!
(
id:
11
,
name:
'test11'
,
path:
'test11'
,
type:
nil
)
namespaces
_table
.
create!
(
id:
11
,
name:
'test11'
,
path:
'test11'
,
type:
nil
)
end
end
it
'backfills `type` for the selected records'
do
it
'backfills `type` for the selected records'
,
:aggregate_failures
do
queries
=
ActiveRecord
::
QueryRecorder
.
new
do
queries
=
ActiveRecord
::
QueryRecorder
.
new
do
migration
.
perform
(
1
,
10
)
perform_migration
end
end
expect
(
queries
.
count
).
to
be
(
1
)
expect
(
queries
.
count
).
to
eq
(
3
)
expect
(
Namespace
.
where
(
type:
'User'
).
count
).
to
eq
3
expect
(
namespaces_table
.
where
(
type:
'User'
).
count
).
to
eq
3
expect
(
namespaces_table
.
where
(
type:
'User'
).
pluck
(
:id
)).
to
match_array
([
1
,
2
,
4
])
end
it
'tracks timings of queries'
do
expect
(
migration
.
batch_metrics
.
timings
).
to
be_empty
expect
{
perform_migration
}.
to
change
{
migration
.
batch_metrics
.
timings
}
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