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
05f90b86
Commit
05f90b86
authored
Jul 19, 2017
by
Kim "BKC" Carlbäcker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate GitGarbageCollectWorker to Gitaly
parent
0c563225
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
97 additions
and
12 deletions
+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
No files found.
app/workers/git_garbage_collect_worker.rb
View file @
05f90b86
...
@@ -5,6 +5,12 @@ class GitGarbageCollectWorker
...
@@ -5,6 +5,12 @@ class GitGarbageCollectWorker
sidekiq_options
retry:
false
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
)
def
perform
(
project_id
,
task
=
:gc
,
lease_key
=
nil
,
lease_uuid
=
nil
)
project
=
Project
.
find
(
project_id
)
project
=
Project
.
find
(
project_id
)
task
=
task
.
to_sym
task
=
task
.
to_sym
...
@@ -15,8 +21,14 @@ class GitGarbageCollectWorker
...
@@ -15,8 +21,14 @@ class GitGarbageCollectWorker
Gitlab
::
GitLogger
.
info
(
description
)
Gitlab
::
GitLogger
.
info
(
description
)
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
)
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
,
repo_path
)
Gitlab
::
GitLogger
.
error
(
"
#{
description
}
failed:
\n
#{
output
}
"
)
unless
status
.
zero?
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
# Refresh the branch cache in case garbage collection caused a ref lookup to fail
flush_ref_caches
(
project
)
if
task
==
:gc
flush_ref_caches
(
project
)
if
task
==
:gc
...
@@ -26,6 +38,19 @@ class GitGarbageCollectWorker
...
@@ -26,6 +38,19 @@ class GitGarbageCollectWorker
private
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
)
def
command
(
task
)
case
task
case
task
when
:gc
when
:gc
...
@@ -55,4 +80,14 @@ class GitGarbageCollectWorker
...
@@ -55,4 +80,14 @@ class GitGarbageCollectWorker
config_value
=
write_bitmaps
?
'true'
:
'false'
config_value
=
write_bitmaps
?
'true'
:
'false'
%W[git -c repack.writeBitmaps=
#{
config_value
}
]
%W[git -c repack.writeBitmaps=
#{
config_value
}
]
end
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
end
lib/gitlab/gitaly_client/repository_service.rb
View file @
05f90b86
...
@@ -4,12 +4,28 @@ module Gitlab
...
@@ -4,12 +4,28 @@ module Gitlab
def
initialize
(
repository
)
def
initialize
(
repository
)
@repository
=
repository
@repository
=
repository
@gitaly_repo
=
repository
.
gitaly_repository
@gitaly_repo
=
repository
.
gitaly_repository
@storage
=
repository
.
storage
end
end
def
exists?
def
exists?
request
=
Gitaly
::
RepositoryExistsRequest
.
new
(
repository:
@gitaly_repo
)
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
end
end
end
...
...
spec/workers/git_garbage_collect_worker_spec.rb
View file @
05f90b86
...
@@ -9,10 +9,17 @@ describe GitGarbageCollectWorker do
...
@@ -9,10 +9,17 @@ describe GitGarbageCollectWorker do
subject
{
described_class
.
new
}
subject
{
described_class
.
new
}
describe
"#perform"
do
describe
"#perform"
do
it
"flushes ref caches when the task is 'gc'"
do
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
])
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
)
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen
)
.
with
([
:the
,
:command
],
project
.
repository
.
path_to_repo
).
and_return
([
""
,
0
])
.
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
(
: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_names
).
and_call_original
...
@@ -21,6 +28,33 @@ describe GitGarbageCollectWorker do
...
@@ -21,6 +28,33 @@ describe GitGarbageCollectWorker do
subject
.
perform
(
project
.
id
)
subject
.
perform
(
project
.
id
)
end
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
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
,
: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
shared_examples
'gc tasks'
do
before
do
before
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