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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
65bd6868
Commit
65bd6868
authored
Nov 22, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Codestyle changes and Added Exclusive Lease to hashed storage migration
parent
4b87c1af
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
15 deletions
+57
-15
app/services/projects/hashed_storage/migrate_attachments_service.rb
...es/projects/hashed_storage/migrate_attachments_service.rb
+1
-1
app/workers/project_migrate_hashed_storage_worker.rb
app/workers/project_migrate_hashed_storage_worker.rb
+25
-1
spec/workers/project_migrate_hashed_storage_worker_spec.rb
spec/workers/project_migrate_hashed_storage_worker_spec.rb
+31
-13
No files found.
app/services/projects/hashed_storage/migrate_attachments_service.rb
View file @
65bd6868
...
...
@@ -33,7 +33,7 @@ module Projects
end
# Create hashed storage base path folder
FileUtils
.
mkdir_p
(
File
.
expand_path
(
'..'
,
new_path
))
FileUtils
.
mkdir_p
(
File
.
dirname
(
new_path
))
FileUtils
.
mv
(
old_path
,
new_path
)
logger
.
info
(
"Migrated project attachments from '
#{
old_path
}
' to '
#{
new_path
}
' (PROJECT_ID=
#{
project
.
id
}
)"
)
...
...
app/workers/project_migrate_hashed_storage_worker.rb
View file @
65bd6868
...
...
@@ -2,10 +2,34 @@ class ProjectMigrateHashedStorageWorker
include
Sidekiq
::
Worker
include
DedicatedSidekiqQueue
LEASE_TIMEOUT
=
30
.
seconds
.
to_i
def
perform
(
project_id
)
project
=
Project
.
find_by
(
id:
project_id
)
return
if
project
.
nil?
||
project
.
pending_delete?
::
Projects
::
HashedStorageMigrationService
.
new
(
project
,
logger
).
execute
uuid
=
try_obtain_lease_for
(
project_id
)
if
uuid
::
Projects
::
HashedStorageMigrationService
.
new
(
project
,
logger
).
execute
else
false
end
rescue
=>
ex
cancel_lease_for
(
project_id
,
uuid
)
raise
ex
end
private
def
try_obtain_lease_for
(
project_id
)
Gitlab
::
ExclusiveLease
.
new
(
lease_key
(
project_id
),
timeout:
LEASE_TIMEOUT
).
try_obtain
end
def
lease_key
(
project_id
)
"project_migrate_hashed_storage_worker:
#{
project_id
}
"
end
def
cancel_lease_for
(
project_id
,
uuid
)
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
(
project_id
),
uuid
)
end
end
spec/workers/project_migrate_hashed_storage_worker_spec.rb
View file @
65bd6868
...
...
@@ -5,25 +5,43 @@ describe ProjectMigrateHashedStorageWorker do
let
(
:project
)
{
create
(
:project
,
:empty_repo
)
}
let
(
:pending_delete_project
)
{
create
(
:project
,
:empty_repo
,
pending_delete:
true
)
}
it
'skips when project no longer exists'
do
nonexistent_id
=
999999999999
context
'when have exclusive lease'
do
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
true
)
end
expect
(
::
Projects
::
HashedStorageMigrationService
).
not_to
receive
(
:new
)
subject
.
perform
(
nonexistent_id
)
end
it
'skips when project no longer exists'
do
nonexistent_id
=
999999999999
expect
(
::
Projects
::
HashedStorageMigrationService
).
not_to
receive
(
:new
)
subject
.
perform
(
nonexistent_id
)
end
it
'skips when project is pending delete'
do
expect
(
::
Projects
::
HashedStorageMigrationService
).
not_to
receive
(
:new
)
it
'skips when project is pending delete'
do
e
xpect
(
::
Projects
::
HashedStorageMigrationService
).
not_to
receive
(
:new
)
subject
.
perform
(
pending_delete_project
.
id
)
e
nd
subject
.
perform
(
pending_delete_project
.
id
)
it
'delegates removal to service class'
do
service
=
double
(
'service'
)
expect
(
::
Projects
::
HashedStorageMigrationService
).
to
receive
(
:new
).
with
(
project
,
subject
.
logger
).
and_return
(
service
)
expect
(
service
).
to
receive
(
:execute
)
subject
.
perform
(
project
.
id
)
end
end
it
'delegates removal to service class'
do
service
=
double
(
'service'
)
expect
(
::
Projects
::
HashedStorageMigrationService
).
to
receive
(
:new
).
with
(
project
,
subject
.
logger
).
and_return
(
service
)
expect
(
service
).
to
receive
(
:execute
)
context
'when dont have exclusive lease'
do
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
false
)
end
it
'skips when dont have lease'
do
expect
(
::
Projects
::
HashedStorageMigrationService
).
not_to
receive
(
:new
)
subject
.
perform
(
project
.
id
)
subject
.
perform
(
project
.
id
)
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