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
cbe2afc1
Commit
cbe2afc1
authored
Feb 23, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up migrate! by splitting unsafe_migrate! and migrate!
parent
88984137
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
40 deletions
+47
-40
ee/app/uploaders/object_storage.rb
ee/app/uploaders/object_storage.rb
+43
-36
ee/spec/support/shared_examples/uploaders/object_storage_shared_examples.rb
...ared_examples/uploaders/object_storage_shared_examples.rb
+4
-4
No files found.
ee/app/uploaders/object_storage.rb
View file @
cbe2afc1
...
...
@@ -201,43 +201,12 @@ module ObjectStorage
# new_store: Enum (Store::LOCAL, Store::REMOTE)
#
def
migrate!
(
new_store
)
return
unless
object_store
!=
new_store
r
eturn
unless
file
uuid
=
Gitlab
::
ExclusiveLease
.
new
(
exclusive_lease_key
,
timeout:
1
.
hour
.
to_i
).
try_obtain
r
aise
'Already running'
unless
uuid
exclusive_lease_key
=
"object_storage_migrate:
#{
store_path
}
"
Gitlab
::
ExclusiveLease
.
new
(
exclusive_lease_key
,
timeout:
1
.
hour
.
to_i
)
.
try_obtain
.
tap
do
|
uuid
|
return
unless
uuid
# rubocop:disable Lint/NonLocalExitFromIterator
begin
new_file
=
nil
file_to_delete
=
file
from_object_store
=
object_store
self
.
object_store
=
new_store
# changes the storage and file
cache_stored_file!
if
file_storage?
with_callbacks
(
:migrate
,
file_to_delete
)
do
with_callbacks
(
:store
,
file_to_delete
)
do
# for #store_versions!
new_file
=
storage
.
store!
(
file
)
persist_object_store!
self
.
file
=
new_file
end
end
return
file
rescue
=>
e
# in case of failure delete new file
new_file
.
delete
unless
new_file
.
nil?
# revert back to the old file
self
.
object_store
=
from_object_store
self
.
file
=
file_to_delete
raise
e
ensure
Gitlab
::
ExclusiveLease
.
cancel
(
exclusive_lease_key
,
uuid
)
end
end
unsafe_migrate!
(
new_store
)
ensure
Gitlab
::
ExclusiveLease
.
cancel
(
exclusive_lease_key
,
uuid
)
end
def
schedule_background_upload
(
*
args
)
...
...
@@ -327,5 +296,43 @@ module ObjectStorage
raise
UnknownStoreError
end
end
def
exclusive_lease_key
"object_storage_migrate:
#{
model
.
class
}
:
#{
model
.
id
}
"
end
#
# Move the file to another store
#
# new_store: Enum (Store::LOCAL, Store::REMOTE)
#
def
unsafe_migrate!
(
new_store
)
return
unless
object_store
!=
new_store
return
unless
file
new_file
=
nil
file_to_delete
=
file
from_object_store
=
object_store
self
.
object_store
=
new_store
# changes the storage and file
cache_stored_file!
if
file_storage?
with_callbacks
(
:migrate
,
file_to_delete
)
do
with_callbacks
(
:store
,
file_to_delete
)
do
# for #store_versions!
new_file
=
storage
.
store!
(
file
)
persist_object_store!
self
.
file
=
new_file
end
end
file
rescue
=>
e
# in case of failure delete new file
new_file
.
delete
unless
new_file
.
nil?
# revert back to the old file
self
.
object_store
=
from_object_store
self
.
file
=
file_to_delete
raise
e
end
end
end
ee/spec/support/shared_examples/uploaders/object_storage_shared_examples.rb
View file @
cbe2afc1
...
...
@@ -29,7 +29,7 @@ shared_examples "migrates" do |to_store:, from_store: nil|
elsif
from
==
described_class
::
Store
::
LOCAL
expect
(
subject
.
file
).
to
be_a
(
CarrierWave
::
SanitizedFile
)
else
raise
'
E
nexpected file type'
raise
'
U
nexpected file type'
end
end
...
...
@@ -70,16 +70,16 @@ shared_examples "migrates" do |to_store:, from_store: nil|
end
context
'when migrate! is oqqupied by another process'
do
let
(
:exclusive_lease_key
)
{
"object_storage_migrate:
#{
subject
.
store_path
}
"
}
let
(
:exclusive_lease_key
)
{
"object_storage_migrate:
#{
subject
.
model
.
class
}
:
#{
subject
.
model
.
id
}
"
}
before
do
@uuid
=
Gitlab
::
ExclusiveLease
.
new
(
exclusive_lease_key
,
timeout:
1
.
hour
.
to_i
).
try_obtain
end
it
'does not execute migrate!'
do
expect
(
subject
).
not_to
receive
(
:
object_store
=
)
expect
(
subject
).
not_to
receive
(
:
unsafe_migrate!
)
migrate
(
to
)
expect
{
migrate
(
to
)
}.
to
raise_error
(
'Already running'
)
end
after
do
...
...
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