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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
0e257722
Commit
0e257722
authored
Jun 13, 2018
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move GC RPCs to mandatory
Closes
https://gitlab.com/gitlab-org/gitaly/issues/354
parent
1175e23b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
123 deletions
+52
-123
app/workers/git_garbage_collect_worker.rb
app/workers/git_garbage_collect_worker.rb
+7
-51
spec/workers/git_garbage_collect_worker_spec.rb
spec/workers/git_garbage_collect_worker_spec.rb
+45
-72
No files found.
app/workers/git_garbage_collect_worker.rb
View file @
0e257722
...
...
@@ -6,12 +6,6 @@ class GitGarbageCollectWorker
# Timeout set to 24h
LEASE_TIMEOUT
=
86400
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
)
active_uuid
=
get_lease_uuid
(
lease_key
)
...
...
@@ -27,21 +21,7 @@ class GitGarbageCollectWorker
end
task
=
task
.
to_sym
cmd
=
command
(
task
)
gitaly_migrate
(
GITALY_MIGRATED_TASKS
[
task
],
status:
Gitlab
::
GitalyClient
::
MigrationStatus
::
OPT_OUT
)
do
|
is_enabled
|
if
is_enabled
gitaly_call
(
task
,
project
.
repository
.
raw_repository
)
else
repo_path
=
project
.
repository
.
path_to_repo
description
=
"'
#{
cmd
.
join
(
' '
)
}
' in
#{
repo_path
}
"
Gitlab
::
GitLogger
.
info
(
description
)
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
,
repo_path
)
Gitlab
::
GitLogger
.
error
(
"
#{
description
}
failed:
\n
#{
output
}
"
)
unless
status
.
zero?
end
end
gitaly_call
(
task
,
project
.
repository
.
raw_repository
)
# Refresh the branch cache in case garbage collection caused a ref lookup to fail
flush_ref_caches
(
project
)
if
task
==
:gc
...
...
@@ -82,21 +62,12 @@ class GitGarbageCollectWorker
when
:incremental_repack
client
.
repack_incremental
end
end
def
command
(
task
)
case
task
when
:gc
git
(
write_bitmaps:
bitmaps_enabled?
)
+
%w[gc]
when
:full_repack
git
(
write_bitmaps:
bitmaps_enabled?
)
+
%w[repack -A -d --pack-kept-objects]
when
:incremental_repack
# Normal git repack fails when bitmaps are enabled. It is impossible to
# create a bitmap here anyway.
git
(
write_bitmaps:
false
)
+
%w[repack -d]
else
raise
"Invalid gc task:
#{
task
.
inspect
}
"
end
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
def
flush_ref_caches
(
project
)
...
...
@@ -108,19 +79,4 @@ class GitGarbageCollectWorker
def
bitmaps_enabled?
Gitlab
::
CurrentSettings
.
housekeeping_bitmaps_enabled
end
def
git
(
write_bitmaps
:)
config_value
=
write_bitmaps
?
'true'
:
'false'
%W[git -c repack.writeBitmaps=
#{
config_value
}
]
end
def
gitaly_migrate
(
method
,
status:
Gitlab
::
GitalyClient
::
MigrationStatus
::
OPT_IN
,
&
block
)
Gitlab
::
GitalyClient
.
migrate
(
method
,
status:
status
,
&
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
spec/workers/git_garbage_collect_worker_spec.rb
View file @
0e257722
...
...
@@ -11,36 +11,63 @@ describe GitGarbageCollectWorker do
subject
{
described_class
.
new
}
describe
"#perform"
do
shared_examples
'flushing ref caches'
do
|
gitaly
|
context
'with active lease_uuid'
do
context
'with active lease_uuid'
do
before
do
allow
(
subject
).
to
receive
(
:get_lease_uuid
).
and_return
(
lease_uuid
)
end
it
"flushes ref caches when the task if 'gc'"
do
expect
(
subject
).
to
receive
(
:renew_lease
).
with
(
lease_key
,
lease_uuid
).
and_call_original
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
RepositoryService
).
to
receive
(
:garbage_collect
)
.
and_return
(
nil
)
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
(
:has_visible_content?
).
and_call_original
expect_any_instance_of
(
Gitlab
::
Git
::
Repository
).
to
receive
(
:has_visible_content?
).
and_call_original
subject
.
perform
(
project
.
id
,
:gc
,
lease_key
,
lease_uuid
)
end
end
context
'with different lease than the active one'
do
before
do
allow
(
subject
).
to
receive
(
:get_lease_uuid
).
and_return
(
SecureRandom
.
uuid
)
end
it
'returns silently'
do
expect_any_instance_of
(
Repository
).
not_to
receive
(
:after_create_branch
).
and_call_original
expect_any_instance_of
(
Repository
).
not_to
receive
(
:branch_names
).
and_call_original
expect_any_instance_of
(
Repository
).
not_to
receive
(
:has_visible_content?
).
and_call_original
subject
.
perform
(
project
.
id
,
:gc
,
lease_key
,
lease_uuid
)
end
end
context
'with no active lease'
do
before
do
allow
(
subject
).
to
receive
(
:get_lease_uuid
).
and_return
(
false
)
end
context
'when is able to get the lease'
do
before
do
allow
(
subject
).
to
receive
(
:
get_lease_uuid
).
and_return
(
lease_
uuid
)
allow
(
subject
).
to
receive
(
:
try_obtain_lease
).
and_return
(
SecureRandom
.
uuid
)
end
it
"flushes ref caches when the task if 'gc'"
do
expect
(
subject
).
to
receive
(
:renew_lease
).
with
(
lease_key
,
lease_uuid
).
and_call_original
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
(
Gitlab
::
GitalyClient
::
RepositoryService
).
to
receive
(
:garbage_collect
)
.
and_return
(
nil
)
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
(
:has_visible_content?
).
and_call_original
expect_any_instance_of
(
Gitlab
::
Git
::
Repository
).
to
receive
(
:has_visible_content?
).
and_call_original
subject
.
perform
(
project
.
id
,
:gc
,
lease_key
,
lease_uuid
)
subject
.
perform
(
project
.
id
)
end
end
context
'w
ith different lease than the active one
'
do
context
'w
hen no lease can be obtained
'
do
before
do
allow
(
subject
).
to
receive
(
:get_lease_uuid
).
and_return
(
SecureRandom
.
uuid
)
expect
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
false
)
end
it
'returns silently'
do
...
...
@@ -49,63 +76,9 @@ describe GitGarbageCollectWorker do
expect_any_instance_of
(
Repository
).
not_to
receive
(
:branch_names
).
and_call_original
expect_any_instance_of
(
Repository
).
not_to
receive
(
:has_visible_content?
).
and_call_original
subject
.
perform
(
project
.
id
,
:gc
,
lease_key
,
lease_uuid
)
subject
.
perform
(
project
.
id
)
end
end
context
'with no active lease'
do
before
do
allow
(
subject
).
to
receive
(
:get_lease_uuid
).
and_return
(
false
)
end
context
'when is able to get the lease'
do
before
do
allow
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
SecureRandom
.
uuid
)
end
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
(
:has_visible_content?
).
and_call_original
expect_any_instance_of
(
Gitlab
::
Git
::
Repository
).
to
receive
(
:has_visible_content?
).
and_call_original
subject
.
perform
(
project
.
id
)
end
end
context
'when no lease can be obtained'
do
before
do
expect
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
false
)
end
it
'returns silently'
do
expect
(
subject
).
not_to
receive
(
:command
)
expect_any_instance_of
(
Repository
).
not_to
receive
(
:after_create_branch
).
and_call_original
expect_any_instance_of
(
Repository
).
not_to
receive
(
:branch_names
).
and_call_original
expect_any_instance_of
(
Repository
).
not_to
receive
(
:has_visible_content?
).
and_call_original
subject
.
perform
(
project
.
id
)
end
end
end
end
context
"with Gitaly turned on"
do
it_should_behave_like
'flushing ref caches'
,
true
end
context
"with Gitaly turned off"
,
:disable_gitaly
do
it_should_behave_like
'flushing ref caches'
,
false
end
context
"repack_full"
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