Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
05f90b86
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,发现更多精彩内容 >>
提交
05f90b86
编写于
7月 19, 2017
作者:
K
Kim "BKC" Carlbäcker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Migrate GitGarbageCollectWorker to Gitaly
上级
0c563225
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
97 addition
and
12 deletion
+97
-12
app/workers/git_garbage_collect_worker.rb
app/workers/git_garbage_collect_worker.rb
+37
-2
lib/gitlab/gitaly_client/repository_service.rb
lib/gitlab/gitaly_client/repository_service.rb
+17
-1
spec/workers/git_garbage_collect_worker_spec.rb
spec/workers/git_garbage_collect_worker_spec.rb
+43
-9
未找到文件。
app/workers/git_garbage_collect_worker.rb
浏览文件 @
05f90b86
...
...
@@ -5,6 +5,12 @@ class GitGarbageCollectWorker
sidekiq_options
retry:
false
GITALY_MIGRATED_TASKS
=
{
gc: :garbage_collect
,
full_repack: :repack_full
,
incremental_repack: :repack_incremental
}.
freeze
def
perform
(
project_id
,
task
=
:gc
,
lease_key
=
nil
,
lease_uuid
=
nil
)
project
=
Project
.
find
(
project_id
)
task
=
task
.
to_sym
...
...
@@ -15,8 +21,14 @@ class GitGarbageCollectWorker
Gitlab
::
GitLogger
.
info
(
description
)
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
,
repo_path
)
Gitlab
::
GitLogger
.
error
(
"
#{
description
}
failed:
\n
#{
output
}
"
)
unless
status
.
zero?
gitaly_migrate
(
GITALY_MIGRATED_TASKS
[
task
])
do
|
is_enabled
|
if
is_enabled
gitaly_call
(
task
,
project
.
repository
.
raw_repository
)
else
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
,
repo_path
)
Gitlab
::
GitLogger
.
error
(
"
#{
description
}
failed:
\n
#{
output
}
"
)
unless
status
.
zero?
end
end
# Refresh the branch cache in case garbage collection caused a ref lookup to fail
flush_ref_caches
(
project
)
if
task
==
:gc
...
...
@@ -26,6 +38,19 @@ class GitGarbageCollectWorker
private
## `repository` has to be a Gitlab::Git::Repository
def
gitaly_call
(
task
,
repository
)
client
=
Gitlab
::
GitalyClient
::
RepositoryService
.
new
(
repository
)
case
task
when
:gc
client
.
garbage_collect
(
bitmaps_enabled?
)
when
:full_repack
client
.
repack_full
(
bitmaps_enabled?
)
when
:incremental_repack
client
.
repack_incremental
end
end
def
command
(
task
)
case
task
when
:gc
...
...
@@ -55,4 +80,14 @@ class GitGarbageCollectWorker
config_value
=
write_bitmaps
?
'true'
:
'false'
%W[git -c repack.writeBitmaps=
#{
config_value
}
]
end
def
gitaly_migrate
(
method
,
&
block
)
Gitlab
::
GitalyClient
.
migrate
(
method
,
&
block
)
rescue
GRPC
::
NotFound
=>
e
Gitlab
::
GitLogger
.
error
(
"
#{
method
}
failed:
\n
Repository not found"
)
raise
Gitlab
::
Git
::
Repository
::
NoRepository
.
new
(
e
)
rescue
GRPC
::
BadStatus
=>
e
Gitlab
::
GitLogger
.
error
(
"
#{
method
}
failed:
\n
#{
e
}
"
)
raise
Gitlab
::
Git
::
CommandError
.
new
(
e
)
end
end
lib/gitlab/gitaly_client/repository_service.rb
浏览文件 @
05f90b86
...
...
@@ -4,12 +4,28 @@ module Gitlab
def
initialize
(
repository
)
@repository
=
repository
@gitaly_repo
=
repository
.
gitaly_repository
@storage
=
repository
.
storage
end
def
exists?
request
=
Gitaly
::
RepositoryExistsRequest
.
new
(
repository:
@gitaly_repo
)
GitalyClient
.
call
(
@repository
.
storage
,
:repository_service
,
:exists
,
request
).
exists
GitalyClient
.
call
(
@storage
,
:repository_service
,
:exists
,
request
).
exists
end
def
garbage_collect
(
create_bitmap
)
request
=
Gitaly
::
GarbageCollectRequest
.
new
(
repository:
@gitaly_repo
,
create_bitmap:
create_bitmap
)
GitalyClient
.
call
(
@storage
,
:repository_service
,
:garbage_collect
,
request
)
end
def
repack_full
(
create_bitmap
)
request
=
Gitaly
::
RepackFullRequest
.
new
(
repository:
@gitaly_repo
,
create_bitmap:
create_bitmap
)
GitalyClient
.
call
(
@storage
,
:repository_service
,
:repack_full
,
request
)
end
def
repack_incremental
request
=
Gitaly
::
RepackIncrementalRequest
.
new
(
repository:
@gitaly_repo
)
GitalyClient
.
call
(
@storage
,
:repository_service
,
:repack_incremental
,
request
)
end
end
end
...
...
spec/workers/git_garbage_collect_worker_spec.rb
浏览文件 @
05f90b86
...
...
@@ -9,17 +9,51 @@ describe GitGarbageCollectWorker do
subject
{
described_class
.
new
}
describe
"#perform"
do
it
"flushes ref caches when the task is 'gc'"
do
expect
(
subject
).
to
receive
(
:command
).
with
(
:gc
).
and_return
([
:the
,
:command
])
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen
)
.
with
([
:the
,
:command
],
project
.
repository
.
path_to_repo
).
and_return
([
""
,
0
])
shared_examples
'flushing ref caches'
do
|
gitaly
|
it
"flushes ref caches when the task if 'gc'"
do
expect
(
subject
).
to
receive
(
:command
).
with
(
:gc
).
and_return
([
:the
,
:command
])
if
gitaly
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
RepositoryService
).
to
receive
(
:garbage_collect
)
.
and_return
(
nil
)
else
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen
)
.
with
([
:the
,
:command
],
project
.
repository
.
path_to_repo
).
and_return
([
""
,
0
])
end
expect_any_instance_of
(
Repository
).
to
receive
(
:after_create_branch
).
and_call_original
expect_any_instance_of
(
Repository
).
to
receive
(
:branch_names
).
and_call_original
expect_any_instance_of
(
Repository
).
to
receive
(
:branch_count
).
and_call_original
expect_any_instance_of
(
Repository
).
to
receive
(
:has_visible_content?
).
and_call_original
subject
.
perform
(
project
.
id
)
end
end
context
"with Gitaly turned on"
do
it_should_behave_like
'flushing ref caches'
,
true
end
context
"with Gitaly turned off"
,
skip_gitaly_mock:
true
do
it_should_behave_like
'flushing ref caches'
,
false
end
expect_any_instance_of
(
Repository
).
to
receive
(
:after_create_branch
).
and_call_original
expect_any_instance_of
(
Repository
).
to
receive
(
:branch_names
).
and_call_original
expect_any_instance_of
(
Repository
).
to
receive
(
:branch_count
).
and_call_original
expect_any_instance_of
(
Repository
).
to
receive
(
:has_visible_content?
).
and_call_original
context
"repack_full"
do
it
"calls Gitaly"
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
RepositoryService
).
to
receive
(
:repack_full
)
.
and_return
(
nil
)
subject
.
perform
(
project
.
id
)
subject
.
perform
(
project
.
id
,
:full_repack
)
end
end
context
"repack_incremental"
do
it
"calls Gitaly"
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
RepositoryService
).
to
receive
(
:repack_incremental
)
.
and_return
(
nil
)
subject
.
perform
(
project
.
id
,
:incremental_repack
)
end
end
shared_examples
'gc tasks'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录