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
Boxiang Sun
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
Show 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
...
@@ -6,12 +6,6 @@ class GitGarbageCollectWorker
# Timeout set to 24h
# Timeout set to 24h
LEASE_TIMEOUT
=
86400
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
)
def
perform
(
project_id
,
task
=
:gc
,
lease_key
=
nil
,
lease_uuid
=
nil
)
project
=
Project
.
find
(
project_id
)
project
=
Project
.
find
(
project_id
)
active_uuid
=
get_lease_uuid
(
lease_key
)
active_uuid
=
get_lease_uuid
(
lease_key
)
...
@@ -27,21 +21,7 @@ class GitGarbageCollectWorker
...
@@ -27,21 +21,7 @@ class GitGarbageCollectWorker
end
end
task
=
task
.
to_sym
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
)
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
# 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
...
@@ -82,21 +62,12 @@ class GitGarbageCollectWorker
...
@@ -82,21 +62,12 @@ class GitGarbageCollectWorker
when
:incremental_repack
when
:incremental_repack
client
.
repack_incremental
client
.
repack_incremental
end
end
end
rescue
GRPC
::
NotFound
=>
e
Gitlab
::
GitLogger
.
error
(
"
#{
method
}
failed:
\n
Repository not found"
)
def
command
(
task
)
raise
Gitlab
::
Git
::
Repository
::
NoRepository
.
new
(
e
)
case
task
rescue
GRPC
::
BadStatus
=>
e
when
:gc
Gitlab
::
GitLogger
.
error
(
"
#{
method
}
failed:
\n
#{
e
}
"
)
git
(
write_bitmaps:
bitmaps_enabled?
)
+
%w[gc]
raise
Gitlab
::
Git
::
CommandError
.
new
(
e
)
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
end
end
def
flush_ref_caches
(
project
)
def
flush_ref_caches
(
project
)
...
@@ -108,19 +79,4 @@ class GitGarbageCollectWorker
...
@@ -108,19 +79,4 @@ class GitGarbageCollectWorker
def
bitmaps_enabled?
def
bitmaps_enabled?
Gitlab
::
CurrentSettings
.
housekeeping_bitmaps_enabled
Gitlab
::
CurrentSettings
.
housekeeping_bitmaps_enabled
end
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
end
spec/workers/git_garbage_collect_worker_spec.rb
View file @
0e257722
...
@@ -11,7 +11,6 @@ describe GitGarbageCollectWorker do
...
@@ -11,7 +11,6 @@ describe GitGarbageCollectWorker do
subject
{
described_class
.
new
}
subject
{
described_class
.
new
}
describe
"#perform"
do
describe
"#perform"
do
shared_examples
'flushing ref caches'
do
|
gitaly
|
context
'with active lease_uuid'
do
context
'with active lease_uuid'
do
before
do
before
do
allow
(
subject
).
to
receive
(
:get_lease_uuid
).
and_return
(
lease_uuid
)
allow
(
subject
).
to
receive
(
:get_lease_uuid
).
and_return
(
lease_uuid
)
...
@@ -19,16 +18,8 @@ describe GitGarbageCollectWorker do
...
@@ -19,16 +18,8 @@ describe GitGarbageCollectWorker do
it
"flushes ref caches when the task if 'gc'"
do
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
(
: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
)
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
RepositoryService
).
to
receive
(
:garbage_collect
)
.
and_return
(
nil
)
.
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
(
: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
expect_any_instance_of
(
Repository
).
to
receive
(
:has_visible_content?
).
and_call_original
expect_any_instance_of
(
Repository
).
to
receive
(
:has_visible_content?
).
and_call_original
...
@@ -44,7 +35,6 @@ describe GitGarbageCollectWorker do
...
@@ -44,7 +35,6 @@ describe GitGarbageCollectWorker do
end
end
it
'returns silently'
do
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
(
: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
(
:branch_names
).
and_call_original
expect_any_instance_of
(
Repository
).
not_to
receive
(
:has_visible_content?
).
and_call_original
expect_any_instance_of
(
Repository
).
not_to
receive
(
:has_visible_content?
).
and_call_original
...
@@ -64,16 +54,8 @@ describe GitGarbageCollectWorker do
...
@@ -64,16 +54,8 @@ describe GitGarbageCollectWorker do
end
end
it
"flushes ref caches when the task if 'gc'"
do
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
)
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
RepositoryService
).
to
receive
(
:garbage_collect
)
.
and_return
(
nil
)
.
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
(
: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
expect_any_instance_of
(
Repository
).
to
receive
(
:has_visible_content?
).
and_call_original
expect_any_instance_of
(
Repository
).
to
receive
(
:has_visible_content?
).
and_call_original
...
@@ -98,15 +80,6 @@ describe GitGarbageCollectWorker do
...
@@ -98,15 +80,6 @@ describe GitGarbageCollectWorker do
end
end
end
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
context
"repack_full"
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