Unverified Commit d4c6a3af authored by Stan Hu's avatar Stan Hu Committed by Douglas Barbosa Alexandre

Force a full GC after importing a project

During a project import, it's possible that new branches are created by
the importer to handle pull requests that have been created from forked
projects, which would increment the `pushes_since_gc` value via
`HousekeepingService.increment!` before a full garbage collection gets
to run. This causes HousekeepingService to skip the full `git gc` and
move to the incremental repack mode. To ensure that a garbage collection
is run to pack refs and objects, explicitly execute the task.

Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59477
parent 8813447c
...@@ -9,7 +9,7 @@ def initialize(project) ...@@ -9,7 +9,7 @@ def initialize(project)
end end
def execute def execute
Projects::HousekeepingService.new(@project).execute do Projects::HousekeepingService.new(@project, :gc).execute do
repository.delete_all_refs_except(RESERVED_REF_PREFIXES) repository.delete_all_refs_except(RESERVED_REF_PREFIXES)
end end
rescue Projects::HousekeepingService::LeaseTaken => e rescue Projects::HousekeepingService::LeaseTaken => e
...@@ -18,8 +18,9 @@ def to_s ...@@ -18,8 +18,9 @@ def to_s
end end
end end
def initialize(project) def initialize(project, task = nil)
@project = project @project = project
@task = task
end end
def execute def execute
...@@ -69,6 +70,8 @@ def pushes_since_gc ...@@ -69,6 +70,8 @@ def pushes_since_gc
end end
def task def task
return @task if @task
if pushes_since_gc % gc_period == 0 if pushes_since_gc % gc_period == 0
:gc :gc
elsif pushes_since_gc % full_repack_period == 0 elsif pushes_since_gc % full_repack_period == 0
title: Force a full GC after importing a project
merge_request: 26803
type: performance
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
describe '#execute' do describe '#execute' do
before do before do
allow(Projects::HousekeepingService) allow(Projects::HousekeepingService)
.to receive(:new).with(project).and_return(housekeeping_service) .to receive(:new).with(project, :gc).and_return(housekeeping_service)
allow(housekeeping_service) allow(housekeeping_service)
.to receive(:execute).and_yield .to receive(:execute).and_yield
...@@ -88,6 +88,19 @@ ...@@ -88,6 +88,19 @@
expect(project.pushes_since_gc).to eq(1) expect(project.pushes_since_gc).to eq(1)
end end
end end
it 'runs the task specifically requested' do
housekeeping = described_class.new(project, :gc)
allow(housekeeping).to receive(:try_obtain_lease).and_return(:gc_uuid)
allow(housekeeping).to receive(:lease_key).and_return(:gc_lease_key)
expect(GitGarbageCollectWorker).to receive(:perform_async).with(project.id, :gc, :gc_lease_key, :gc_uuid).twice
2.times do
end end
describe '#needed?' do describe '#needed?' do
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment