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
cc8ad1bf
Commit
cc8ad1bf
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
ff462603
Changes
3
Show 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 @
cc8ad1bf
...
@@ -33,7 +33,7 @@ module Projects
...
@@ -33,7 +33,7 @@ module Projects
end
end
# Create hashed storage base path folder
# 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
)
FileUtils
.
mv
(
old_path
,
new_path
)
logger
.
info
(
"Migrated project attachments from '
#{
old_path
}
' to '
#{
new_path
}
' (PROJECT_ID=
#{
project
.
id
}
)"
)
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 @
cc8ad1bf
...
@@ -2,10 +2,34 @@ class ProjectMigrateHashedStorageWorker
...
@@ -2,10 +2,34 @@ class ProjectMigrateHashedStorageWorker
include
Sidekiq
::
Worker
include
Sidekiq
::
Worker
include
DedicatedSidekiqQueue
include
DedicatedSidekiqQueue
LEASE_TIMEOUT
=
30
.
seconds
.
to_i
def
perform
(
project_id
)
def
perform
(
project_id
)
project
=
Project
.
find_by
(
id:
project_id
)
project
=
Project
.
find_by
(
id:
project_id
)
return
if
project
.
nil?
||
project
.
pending_delete?
return
if
project
.
nil?
||
project
.
pending_delete?
uuid
=
try_obtain_lease_for
(
project_id
)
if
uuid
::
Projects
::
HashedStorageMigrationService
.
new
(
project
,
logger
).
execute
::
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
end
end
spec/workers/project_migrate_hashed_storage_worker_spec.rb
View file @
cc8ad1bf
...
@@ -5,6 +5,11 @@ describe ProjectMigrateHashedStorageWorker do
...
@@ -5,6 +5,11 @@ describe ProjectMigrateHashedStorageWorker do
let
(
:project
)
{
create
(
:project
,
:empty_repo
)
}
let
(
:project
)
{
create
(
:project
,
:empty_repo
)
}
let
(
:pending_delete_project
)
{
create
(
:project
,
:empty_repo
,
pending_delete:
true
)
}
let
(
:pending_delete_project
)
{
create
(
:project
,
:empty_repo
,
pending_delete:
true
)
}
context
'when have exclusive lease'
do
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
).
and_return
(
true
)
end
it
'skips when project no longer exists'
do
it
'skips when project no longer exists'
do
nonexistent_id
=
999999999999
nonexistent_id
=
999999999999
...
@@ -26,4 +31,17 @@ describe ProjectMigrateHashedStorageWorker do
...
@@ -26,4 +31,17 @@ describe ProjectMigrateHashedStorageWorker do
subject
.
perform
(
project
.
id
)
subject
.
perform
(
project
.
id
)
end
end
end
end
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
)
end
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