Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ae27a47b
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
ae27a47b
编写于
3月 28, 2018
作者:
A
Alessio Caiazza
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Gitlab::ExclusiveLease to ObjectStorage#use_file
上级
cb94afc5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
72 addition
and
18 deletion
+72
-18
app/uploaders/object_storage.rb
app/uploaders/object_storage.rb
+29
-16
changelogs/unreleased/ac-fix-use_file-race.yml
changelogs/unreleased/ac-fix-use_file-race.yml
+5
-0
spec/support/shared_examples/uploaders/object_storage_shared_examples.rb
...ared_examples/uploaders/object_storage_shared_examples.rb
+14
-2
spec/uploaders/object_storage_spec.rb
spec/uploaders/object_storage_spec.rb
+24
-0
未找到文件。
app/uploaders/object_storage.rb
浏览文件 @
ae27a47b
...
...
@@ -228,16 +228,9 @@ module ObjectStorage
raise
'Failed to update object store'
unless
updated
end
def
use_file
if
file_storage?
return
yield
path
end
begin
cache_stored_file!
yield
cache_path
ensure
cache_storage
.
delete_dir!
(
cache_path
(
nil
))
def
use_file
(
&
blk
)
with_exclusive_lease
do
unsafe_use_file
(
&
blk
)
end
end
...
...
@@ -247,12 +240,9 @@ module ObjectStorage
# new_store: Enum (Store::LOCAL, Store::REMOTE)
#
def
migrate!
(
new_store
)
uuid
=
Gitlab
::
ExclusiveLease
.
new
(
exclusive_lease_key
,
timeout:
1
.
hour
.
to_i
).
try_obtain
raise
'Already running'
unless
uuid
unsafe_migrate!
(
new_store
)
ensure
Gitlab
::
ExclusiveLease
.
cancel
(
exclusive_lease_key
,
uuid
)
with_exclusive_lease
do
unsafe_migrate!
(
new_store
)
end
end
def
schedule_background_upload
(
*
args
)
...
...
@@ -384,6 +374,15 @@ module ObjectStorage
"object_storage_migrate:
#{
model
.
class
}
:
#{
model
.
id
}
"
end
def
with_exclusive_lease
uuid
=
Gitlab
::
ExclusiveLease
.
new
(
exclusive_lease_key
,
timeout:
1
.
hour
.
to_i
).
try_obtain
raise
'exclusive lease already taken'
unless
uuid
yield
uuid
ensure
Gitlab
::
ExclusiveLease
.
cancel
(
exclusive_lease_key
,
uuid
)
end
#
# Move the file to another store
#
...
...
@@ -418,4 +417,18 @@ module ObjectStorage
raise
e
end
end
def
unsafe_use_file
if
file_storage?
return
yield
path
end
begin
cache_stored_file!
yield
cache_path
ensure
FileUtils
.
rm_f
(
cache_path
)
cache_storage
.
delete_dir!
(
cache_path
(
nil
))
end
end
end
changelogs/unreleased/ac-fix-use_file-race.yml
0 → 100644
浏览文件 @
ae27a47b
---
title
:
Fix data race between ObjectStorage background_upload and Pages publishing
merge_request
:
author
:
type
:
fixed
spec/support/shared_examples/uploaders/object_storage_shared_examples.rb
浏览文件 @
ae27a47b
...
...
@@ -61,12 +61,18 @@ shared_examples "migrates" do |to_store:, from_store: nil|
expect
{
migrate
(
to
)
}.
not_to
change
{
file
.
exists?
}
end
context
'when migrate! is not o
qq
upied by another process'
do
context
'when migrate! is not o
cc
upied by another process'
do
it
'executes migrate!'
do
expect
(
subject
).
to
receive
(
:object_store
=
).
at_least
(
1
)
migrate
(
to
)
end
it
'executes use_file'
do
expect
(
subject
).
to
receive
(
:unsafe_use_file
).
once
subject
.
use_file
end
end
context
'when migrate! is occupied by another process'
do
...
...
@@ -79,7 +85,13 @@ shared_examples "migrates" do |to_store:, from_store: nil|
it
'does not execute migrate!'
do
expect
(
subject
).
not_to
receive
(
:unsafe_migrate!
)
expect
{
migrate
(
to
)
}.
to
raise_error
(
'Already running'
)
expect
{
migrate
(
to
)
}.
to
raise_error
(
'exclusive lease already taken'
)
end
it
'does not execute use_file'
do
expect
(
subject
).
not_to
receive
(
:unsafe_use_file
)
expect
{
subject
.
use_file
}.
to
raise_error
(
'exclusive lease already taken'
)
end
after
do
...
...
spec/uploaders/object_storage_spec.rb
浏览文件 @
ae27a47b
...
...
@@ -308,6 +308,30 @@ describe ObjectStorage do
it
{
is_expected
.
to
eq
(
remote_directory
)
}
end
context
'when file is in use'
do
def
when_file_is_in_use
uploader
.
use_file
do
yield
end
end
it
'cannot migrate'
do
when_file_is_in_use
do
expect
(
uploader
).
not_to
receive
(
:unsafe_migrate!
)
expect
{
uploader
.
migrate!
(
described_class
::
Store
::
REMOTE
)
}.
to
raise_error
(
'exclusive lease already taken'
)
end
end
it
'cannot use_file'
do
when_file_is_in_use
do
expect
(
uploader
).
not_to
receive
(
:unsafe_use_file
)
expect
{
uploader
.
use_file
}.
to
raise_error
(
'exclusive lease already taken'
)
end
end
end
describe
'#fog_credentials'
do
let
(
:connection
)
{
Settingslogic
.
new
(
"provider"
=>
"AWS"
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录