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
c2c34eba
Commit
c2c34eba
authored
Dec 22, 2018
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prepare rake task for storage rollback
We are keeping compatibility with existing scheduled jobs.
parent
07a196be
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
20 deletions
+37
-20
app/workers/storage_migrator_worker.rb
app/workers/storage_migrator_worker.rb
+8
-2
lib/gitlab/hashed_storage/migrator.rb
lib/gitlab/hashed_storage/migrator.rb
+20
-9
lib/tasks/gitlab/storage.rake
lib/tasks/gitlab/storage.rake
+1
-1
spec/lib/gitlab/hashed_storage/migrator_spec.rb
spec/lib/gitlab/hashed_storage/migrator_spec.rb
+5
-5
spec/tasks/gitlab/storage_rake_spec.rb
spec/tasks/gitlab/storage_rake_spec.rb
+2
-2
spec/workers/storage_migrator_worker_spec.rb
spec/workers/storage_migrator_worker_spec.rb
+1
-1
No files found.
app/workers/storage_migrator_worker.rb
View file @
c2c34eba
...
...
@@ -3,8 +3,14 @@
class
StorageMigratorWorker
include
ApplicationWorker
def
perform
(
start
,
finish
)
# @param [Integer] start initial ID of the batch
# @param [Integer] finish last ID of the batch
# @param [String] operation the operation to be performed: ['migrate', 'rollback']
def
perform
(
start
,
finish
,
operation
=
:migrate
)
# when scheduling a job symbols are converted to string, we need to convert back
operation
=
operation
.
to_sym
if
operation
migrator
=
Gitlab
::
HashedStorage
::
Migrator
.
new
migrator
.
bulk_migrate
(
start
,
finish
)
migrator
.
bulk_migrate
(
start
:
start
,
finish:
finish
,
operation:
operation
)
end
end
lib/gitlab/hashed_storage/migrator.rb
View file @
c2c34eba
...
...
@@ -11,10 +11,11 @@ module Gitlab
# Schedule a range of projects to be bulk migrated with #bulk_migrate asynchronously
#
# @param [Object] start first project id for the range
# @param [Object] finish last project id for the range
def
bulk_schedule
(
start
,
finish
)
StorageMigratorWorker
.
perform_async
(
start
,
finish
)
# @param [Integer] start first project id for the range
# @param [Integer] finish last project id for the range
# @param [Symbol] operation [:migrate, :rollback]
def
bulk_schedule
(
start
:,
finish
:,
operation: :migrate
)
StorageMigratorWorker
.
perform_async
(
start
,
finish
,
operation
)
end
# Start migration of projects from specified range
...
...
@@ -22,21 +23,27 @@ module Gitlab
# Flagging a project to be migrated is a synchronous action,
# but the migration runs through async jobs
#
# @param [Object] start first project id for the range
# @param [Object] finish last project id for the range
# @param [Integer] start first project id for the range
# @param [Integer] finish last project id for the range
# @param [Symbol] operation [:migrate, :rollback]
# rubocop: disable CodeReuse/ActiveRecord
def
bulk_migrate
(
start
,
finish
)
def
bulk_migrate
(
start
:,
finish
:,
operation: :migrate
)
projects
=
build_relation
(
start
,
finish
)
projects
.
with_route
.
find_each
(
batch_size:
BATCH_SIZE
)
do
|
project
|
migrate
(
project
)
case
operation
when
:migrate
migrate
(
project
)
when
:rollback
rollback
(
project
)
end
end
end
# rubocop: enable CodeReuse/ActiveRecord
# Flag a project to be migrated
#
# @param [
Ob
ject] project that will be migrated
# @param [
Pro
ject] project that will be migrated
def
migrate
(
project
)
Rails
.
logger
.
info
"Starting storage migration of
#{
project
.
full_path
}
(ID=
#{
project
.
id
}
)..."
...
...
@@ -45,6 +52,10 @@ module Gitlab
Rails
.
logger
.
error
(
"
#{
err
.
message
}
migrating storage of
#{
project
.
full_path
}
(ID=
#{
project
.
id
}
), trace -
#{
err
.
backtrace
}
"
)
end
def
rollback
(
project
)
# TODO: implement rollback strategy
end
private
# rubocop: disable CodeReuse/ActiveRecord
...
...
lib/tasks/gitlab/storage.rake
View file @
c2c34eba
...
...
@@ -37,7 +37,7 @@ namespace :gitlab do
print
"Enqueuing migration of
#{
legacy_projects_count
}
projects in batches of
#{
helper
.
batch_size
}
"
helper
.
project_id_batches
do
|
start
,
finish
|
storage_migrator
.
bulk_schedule
(
start
,
finish
)
storage_migrator
.
bulk_schedule
(
start
:
start
,
finish:
finish
,
operation: :migrate
)
print
'.'
end
...
...
spec/lib/gitlab/hashed_storage/migrator_spec.rb
View file @
c2c34eba
...
...
@@ -4,7 +4,7 @@ describe Gitlab::HashedStorage::Migrator do
describe
'#bulk_schedule'
do
it
'schedules job to StorageMigratorWorker'
do
Sidekiq
::
Testing
.
fake!
do
expect
{
subject
.
bulk_schedule
(
1
,
5
)
}.
to
change
(
StorageMigratorWorker
.
jobs
,
:size
).
by
(
1
)
expect
{
subject
.
bulk_schedule
(
start:
1
,
finish:
5
)
}.
to
change
(
StorageMigratorWorker
.
jobs
,
:size
).
by
(
1
)
end
end
end
...
...
@@ -15,13 +15,13 @@ describe Gitlab::HashedStorage::Migrator do
it
'enqueue jobs to ProjectMigrateHashedStorageWorker'
do
Sidekiq
::
Testing
.
fake!
do
expect
{
subject
.
bulk_migrate
(
ids
.
min
,
ids
.
max
)
}.
to
change
(
ProjectMigrateHashedStorageWorker
.
jobs
,
:size
).
by
(
2
)
expect
{
subject
.
bulk_migrate
(
start:
ids
.
min
,
finish:
ids
.
max
)
}.
to
change
(
ProjectMigrateHashedStorageWorker
.
jobs
,
:size
).
by
(
2
)
end
end
it
'rescues and log exceptions'
do
allow_any_instance_of
(
Project
).
to
receive
(
:migrate_to_hashed_storage!
).
and_raise
(
StandardError
)
expect
{
subject
.
bulk_migrate
(
ids
.
min
,
ids
.
max
)
}.
not_to
raise_error
expect
{
subject
.
bulk_migrate
(
start:
ids
.
min
,
finish:
ids
.
max
)
}.
not_to
raise_error
end
it
'delegates each project in specified range to #migrate'
do
...
...
@@ -29,12 +29,12 @@ describe Gitlab::HashedStorage::Migrator do
expect
(
subject
).
to
receive
(
:migrate
).
with
(
project
)
end
subject
.
bulk_migrate
(
ids
.
min
,
ids
.
max
)
subject
.
bulk_migrate
(
start:
ids
.
min
,
finish:
ids
.
max
)
end
it
'has migrated projects set as writable'
do
perform_enqueued_jobs
do
subject
.
bulk_migrate
(
ids
.
min
,
ids
.
max
)
subject
.
bulk_migrate
(
start:
ids
.
min
,
finish:
ids
.
max
)
end
projects
.
each
do
|
project
|
...
...
spec/tasks/gitlab/storage_rake_spec.rb
View file @
c2c34eba
...
...
@@ -74,7 +74,7 @@ describe 'rake gitlab:storage:*' do
it
'enqueues one StorageMigratorWorker per project'
do
projects
.
each
do
|
project
|
expect
(
StorageMigratorWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
project
.
id
)
expect
(
StorageMigratorWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
project
.
id
,
:migrate
)
end
run_rake_task
(
task
)
...
...
@@ -89,7 +89,7 @@ describe 'rake gitlab:storage:*' do
it
'enqueues one StorageMigratorWorker per 2 projects'
do
projects
.
map
(
&
:id
).
sort
.
each_slice
(
2
)
do
|
first
,
last
|
last
||=
first
expect
(
StorageMigratorWorker
).
to
receive
(
:perform_async
).
with
(
first
,
last
)
expect
(
StorageMigratorWorker
).
to
receive
(
:perform_async
).
with
(
first
,
last
,
:migrate
)
end
run_rake_task
(
task
)
...
...
spec/workers/storage_migrator_worker_spec.rb
View file @
c2c34eba
...
...
@@ -7,7 +7,7 @@ describe StorageMigratorWorker do
describe
'#perform'
do
it
'delegates to MigratorService'
do
expect_any_instance_of
(
Gitlab
::
HashedStorage
::
Migrator
).
to
receive
(
:bulk_migrate
).
with
(
5
,
10
)
expect_any_instance_of
(
Gitlab
::
HashedStorage
::
Migrator
).
to
receive
(
:bulk_migrate
).
with
(
start:
5
,
finish:
10
,
operation: :migrate
)
worker
.
perform
(
5
,
10
)
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