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
fa18853c
Commit
fa18853c
authored
Jul 11, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
d2e74fe7
06b8fe56
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
57 deletions
+118
-57
changelogs/unreleased/63667-hashed-storage-migration-count-correctly.yml
...leased/63667-hashed-storage-migration-count-correctly.yml
+5
-0
lib/gitlab/hashed_storage/rake_helper.rb
lib/gitlab/hashed_storage/rake_helper.rb
+5
-1
lib/tasks/gitlab/storage.rake
lib/tasks/gitlab/storage.rake
+36
-48
spec/support/matchers/abort_matcher.rb
spec/support/matchers/abort_matcher.rb
+46
-0
spec/tasks/gitlab/storage_rake_spec.rb
spec/tasks/gitlab/storage_rake_spec.rb
+26
-8
No files found.
changelogs/unreleased/63667-hashed-storage-migration-count-correctly.yml
0 → 100644
View file @
fa18853c
---
title
:
Display the correct amount of projects being migrated/rolled-back to Hashed Storage when specifying ranges
merge_request
:
29996
author
:
type
:
fixed
lib/gitlab/hashed_storage/rake_helper.rb
View file @
fa18853c
...
@@ -19,8 +19,12 @@ module Gitlab
...
@@ -19,8 +19,12 @@ module Gitlab
ENV
[
'ID_TO'
]
ENV
[
'ID_TO'
]
end
end
def
self
.
using_ranges?
!
range_from
.
nil?
&&
!
range_to
.
nil?
end
def
self
.
range_single_item?
def
self
.
range_single_item?
!
range_from
.
nil
?
&&
range_from
==
range_to
using_ranges
?
&&
range_from
==
range_to
end
end
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
...
...
lib/tasks/gitlab/storage.rake
View file @
fa18853c
...
@@ -3,42 +3,35 @@ namespace :gitlab do
...
@@ -3,42 +3,35 @@ namespace :gitlab do
desc
'GitLab | Storage | Migrate existing projects to Hashed Storage'
desc
'GitLab | Storage | Migrate existing projects to Hashed Storage'
task
migrate_to_hashed: :environment
do
task
migrate_to_hashed: :environment
do
if
Gitlab
::
Database
.
read_only?
if
Gitlab
::
Database
.
read_only?
warn
'This task requires database write access. Exiting.'
abort
'This task requires database write access. Exiting.'
next
end
end
storage_migrator
=
Gitlab
::
HashedStorage
::
Migrator
.
new
storage_migrator
=
Gitlab
::
HashedStorage
::
Migrator
.
new
helper
=
Gitlab
::
HashedStorage
::
RakeHelper
helper
=
Gitlab
::
HashedStorage
::
RakeHelper
if
storage_migrator
.
rollback_pending?
if
storage_migrator
.
rollback_pending?
warn
"There is already a rollback operation in progress, "
\
abort
"There is already a rollback operation in progress, "
\
"running a migration at the same time may have unexpected consequences."
"running a migration at the same time may have unexpected consequences."
next
end
end
if
helper
.
range_single_item?
if
helper
.
range_single_item?
project
=
Project
.
with_unmigrated_storage
.
find_by
(
id:
helper
.
range_from
)
project
=
Project
.
with_unmigrated_storage
.
find_by
(
id:
helper
.
range_from
)
unless
project
unless
project
warn
"There are no projects requiring storage migration with ID=
#{
helper
.
range_from
}
"
abort
"There are no projects requiring storage migration with ID=
#{
helper
.
range_from
}
"
next
end
end
puts
"Enqueueing storage migration of
#{
project
.
full_path
}
(ID=
#{
project
.
id
}
)..."
puts
"Enqueueing storage migration of
#{
project
.
full_path
}
(ID=
#{
project
.
id
}
)..."
storage_migrator
.
migrate
(
project
)
storage_migrator
.
migrate
(
project
)
else
next
legacy_projects_count
=
if
helper
.
using_ranges?
Project
.
with_unmigrated_storage
.
id_in
(
helper
.
range_from
..
helper
.
range_to
).
count
else
Project
.
with_unmigrated_storage
.
count
end
end
legacy_projects_count
=
Project
.
with_unmigrated_storage
.
count
if
legacy_projects_count
==
0
if
legacy_projects_count
==
0
warn
'There are no projects requiring storage migration. Nothing to do!'
abort
'There are no projects requiring storage migration. Nothing to do!'
next
end
end
print
"Enqueuing migration of
#{
legacy_projects_count
}
projects in batches of
#{
helper
.
batch_size
}
"
print
"Enqueuing migration of
#{
legacy_projects_count
}
projects in batches of
#{
helper
.
batch_size
}
"
...
@@ -48,6 +41,7 @@ namespace :gitlab do
...
@@ -48,6 +41,7 @@ namespace :gitlab do
print
'.'
print
'.'
end
end
end
puts
' Done!'
puts
' Done!'
end
end
...
@@ -55,42 +49,35 @@ namespace :gitlab do
...
@@ -55,42 +49,35 @@ namespace :gitlab do
desc
'GitLab | Storage | Rollback existing projects to Legacy Storage'
desc
'GitLab | Storage | Rollback existing projects to Legacy Storage'
task
rollback_to_legacy: :environment
do
task
rollback_to_legacy: :environment
do
if
Gitlab
::
Database
.
read_only?
if
Gitlab
::
Database
.
read_only?
warn
'This task requires database write access. Exiting.'
abort
'This task requires database write access. Exiting.'
next
end
end
storage_migrator
=
Gitlab
::
HashedStorage
::
Migrator
.
new
storage_migrator
=
Gitlab
::
HashedStorage
::
Migrator
.
new
helper
=
Gitlab
::
HashedStorage
::
RakeHelper
helper
=
Gitlab
::
HashedStorage
::
RakeHelper
if
storage_migrator
.
migration_pending?
if
storage_migrator
.
migration_pending?
warn
"There is already a migration operation in progress, "
\
abort
"There is already a migration operation in progress, "
\
"running a rollback at the same time may have unexpected consequences."
"running a rollback at the same time may have unexpected consequences."
next
end
end
if
helper
.
range_single_item?
if
helper
.
range_single_item?
project
=
Project
.
with_storage_feature
(
:repository
).
find_by
(
id:
helper
.
range_from
)
project
=
Project
.
with_storage_feature
(
:repository
).
find_by
(
id:
helper
.
range_from
)
unless
project
unless
project
warn
"There are no projects that can be rolledback with ID=
#{
helper
.
range_from
}
"
abort
"There are no projects that can be rolledback with ID=
#{
helper
.
range_from
}
"
next
end
end
puts
"Enqueueing storage rollback of
#{
project
.
full_path
}
(ID=
#{
project
.
id
}
)..."
puts
"Enqueueing storage rollback of
#{
project
.
full_path
}
(ID=
#{
project
.
id
}
)..."
storage_migrator
.
rollback
(
project
)
storage_migrator
.
rollback
(
project
)
else
next
hashed_projects_count
=
if
helper
.
using_ranges?
Project
.
with_storage_feature
(
:repository
).
id_in
(
helper
.
range_from
..
helper
.
range_to
).
count
else
Project
.
with_storage_feature
(
:repository
).
count
end
end
hashed_projects_count
=
Project
.
with_storage_feature
(
:repository
).
count
if
hashed_projects_count
==
0
if
hashed_projects_count
==
0
warn
'There are no projects that can have storage rolledback. Nothing to do!'
abort
'There are no projects that can have storage rolledback. Nothing to do!'
next
end
end
print
"Enqueuing rollback of
#{
hashed_projects_count
}
projects in batches of
#{
helper
.
batch_size
}
"
print
"Enqueuing rollback of
#{
hashed_projects_count
}
projects in batches of
#{
helper
.
batch_size
}
"
...
@@ -100,6 +87,7 @@ namespace :gitlab do
...
@@ -100,6 +87,7 @@ namespace :gitlab do
print
'.'
print
'.'
end
end
end
puts
' Done!'
puts
' Done!'
end
end
...
...
spec/support/matchers/abort_matcher.rb
0 → 100644
View file @
fa18853c
RSpec
::
Matchers
.
define
:abort_execution
do
match
do
|
code_block
|
@captured_stderr
=
StringIO
.
new
original_stderr
=
$stderr
$stderr
=
@captured_stderr
code_block
.
call
false
rescue
SystemExit
=>
e
captured
=
@captured_stderr
.
string
.
chomp
@actual_exit_code
=
e
.
status
break
false
unless
e
.
status
==
1
if
@message
if
@message
.
is_a?
String
@message
==
captured
elsif
@message
.
is_a?
Regexp
@message
.
match?
(
captured
)
else
raise
ArgumentError
,
'with_message must be either a String or a Regular Expression'
end
end
ensure
$stderr
=
original_stderr
end
chain
:with_message
do
|
message
|
@message
=
message
end
failure_message
do
|
block
|
unless
@actual_exit_code
break
"expected
#{
block
}
to abort with '
#{
@message
}
' but didnt call abort."
end
if
@actual_exit_code
!=
1
break
"expected
#{
block
}
to abort with: '
#{
@message
}
' but exited with success instead."
end
"expected
#{
block
}
to abort with: '
#{
@message
}
'
\n
but received: '
#{
@captured_stderr
.
string
.
chomp
}
' instead."
end
supports_block_expectations
end
spec/tasks/gitlab/storage_rake_spec.rb
View file @
fa18853c
...
@@ -50,7 +50,7 @@ describe 'rake gitlab:storage:*', :sidekiq do
...
@@ -50,7 +50,7 @@ describe 'rake gitlab:storage:*', :sidekiq do
expect
(
Project
).
not_to
receive
(
:with_unmigrated_storage
)
expect
(
Project
).
not_to
receive
(
:with_unmigrated_storage
)
expect
{
run_rake_task
(
task
)
}.
to
output
(
/This task requires database write access. Exiting./
).
to_stderr
expect
{
run_rake_task
(
task
)
}.
to
abort_execution
.
with_message
(
/This task requires database write access. Exiting./
)
end
end
end
end
end
end
...
@@ -96,7 +96,7 @@ describe 'rake gitlab:storage:*', :sidekiq do
...
@@ -96,7 +96,7 @@ describe 'rake gitlab:storage:*', :sidekiq do
expect
(
Project
).
not_to
receive
(
:with_unmigrated_storage
)
expect
(
Project
).
not_to
receive
(
:with_unmigrated_storage
)
expect
{
run_rake_task
(
task
)
}.
to
output
(
/There is already a rollback operation in progress/
).
to_stderr
expect
{
run_rake_task
(
task
)
}.
to
abort_execution
.
with_message
(
/There is already a rollback operation in progress/
)
end
end
end
end
end
end
...
@@ -105,14 +105,23 @@ describe 'rake gitlab:storage:*', :sidekiq do
...
@@ -105,14 +105,23 @@ describe 'rake gitlab:storage:*', :sidekiq do
it
'does nothing'
do
it
'does nothing'
do
expect
(
::
HashedStorage
::
MigratorWorker
).
not_to
receive
(
:perform_async
)
expect
(
::
HashedStorage
::
MigratorWorker
).
not_to
receive
(
:perform_async
)
run_rake_task
(
task
)
expect
{
run_rake_task
(
task
)
}.
to
abort_execution
.
with_message
(
'There are no projects requiring storage migration. Nothing to do!'
)
end
end
end
end
context
'with 3 legacy projects'
do
context
'with 3 legacy projects'
do
let
(
:projects
)
{
create_list
(
:project
,
3
,
:legacy_storage
)
}
let
(
:projects
)
{
create_list
(
:project
,
3
,
:legacy_storage
)
}
it_behaves_like
"handles custom BATCH env var"
,
::
HashedStorage
::
MigratorWorker
it
'enqueues migrations and count projects correctly'
do
projects
.
map
(
&
:id
).
sort
.
tap
do
|
ids
|
stub_env
(
'ID_FROM'
,
ids
[
0
])
stub_env
(
'ID_TO'
,
ids
[
1
])
end
expect
{
run_rake_task
(
task
)
}.
to
output
(
/Enqueuing migration of 2 projects in batches/
).
to_stdout
end
it_behaves_like
'handles custom BATCH env var'
,
::
HashedStorage
::
MigratorWorker
end
end
context
'with same id in range'
do
context
'with same id in range'
do
...
@@ -120,7 +129,7 @@ describe 'rake gitlab:storage:*', :sidekiq do
...
@@ -120,7 +129,7 @@ describe 'rake gitlab:storage:*', :sidekiq do
stub_env
(
'ID_FROM'
,
99999
)
stub_env
(
'ID_FROM'
,
99999
)
stub_env
(
'ID_TO'
,
99999
)
stub_env
(
'ID_TO'
,
99999
)
expect
{
run_rake_task
(
task
)
}.
to
output
(
/There are no projects requiring storage migration with ID=99999/
).
to_stderr
expect
{
run_rake_task
(
task
)
}.
to
abort_execution
.
with_message
(
/There are no projects requiring storage migration with ID=99999/
)
end
end
it
'displays a message when project exists but its already migrated'
do
it
'displays a message when project exists but its already migrated'
do
...
@@ -128,7 +137,7 @@ describe 'rake gitlab:storage:*', :sidekiq do
...
@@ -128,7 +137,7 @@ describe 'rake gitlab:storage:*', :sidekiq do
stub_env
(
'ID_FROM'
,
project
.
id
)
stub_env
(
'ID_FROM'
,
project
.
id
)
stub_env
(
'ID_TO'
,
project
.
id
)
stub_env
(
'ID_TO'
,
project
.
id
)
expect
{
run_rake_task
(
task
)
}.
to
output
(
/There are no projects requiring storage migration with ID=
#{
project
.
id
}
/
).
to_stderr
expect
{
run_rake_task
(
task
)
}.
to
abort_execution
.
with_message
(
/There are no projects requiring storage migration with ID=
#{
project
.
id
}
/
)
end
end
it
'enqueues migration when project can be found'
do
it
'enqueues migration when project can be found'
do
...
@@ -153,7 +162,7 @@ describe 'rake gitlab:storage:*', :sidekiq do
...
@@ -153,7 +162,7 @@ describe 'rake gitlab:storage:*', :sidekiq do
expect
(
Project
).
not_to
receive
(
:with_unmigrated_storage
)
expect
(
Project
).
not_to
receive
(
:with_unmigrated_storage
)
expect
{
run_rake_task
(
task
)
}.
to
output
(
/There is already a migration operation in progress/
).
to_stderr
expect
{
run_rake_task
(
task
)
}.
to
abort_execution
.
with_message
(
/There is already a migration operation in progress/
)
end
end
end
end
end
end
...
@@ -162,13 +171,22 @@ describe 'rake gitlab:storage:*', :sidekiq do
...
@@ -162,13 +171,22 @@ describe 'rake gitlab:storage:*', :sidekiq do
it
'does nothing'
do
it
'does nothing'
do
expect
(
::
HashedStorage
::
RollbackerWorker
).
not_to
receive
(
:perform_async
)
expect
(
::
HashedStorage
::
RollbackerWorker
).
not_to
receive
(
:perform_async
)
run_rake_task
(
task
)
expect
{
run_rake_task
(
task
)
}.
to
abort_execution
.
with_message
(
'There are no projects that can have storage rolledback. Nothing to do!'
)
end
end
end
end
context
'with 3 hashed projects'
do
context
'with 3 hashed projects'
do
let
(
:projects
)
{
create_list
(
:project
,
3
)
}
let
(
:projects
)
{
create_list
(
:project
,
3
)
}
it
'enqueues migrations and count projects correctly'
do
projects
.
map
(
&
:id
).
sort
.
tap
do
|
ids
|
stub_env
(
'ID_FROM'
,
ids
[
0
])
stub_env
(
'ID_TO'
,
ids
[
1
])
end
expect
{
run_rake_task
(
task
)
}.
to
output
(
/Enqueuing rollback of 2 projects in batches/
).
to_stdout
end
it_behaves_like
"handles custom BATCH env var"
,
::
HashedStorage
::
RollbackerWorker
it_behaves_like
"handles custom BATCH env var"
,
::
HashedStorage
::
RollbackerWorker
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