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 @@ module Projects ...@@ -9,7 +9,7 @@ module Projects
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 @@ module Projects ...@@ -18,8 +18,9 @@ module Projects
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 @@ module Projects ...@@ -69,6 +70,8 @@ module Projects
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
author:
type: performance
...@@ -13,7 +13,7 @@ describe Projects::AfterImportService do ...@@ -13,7 +13,7 @@ describe Projects::AfterImportService do
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 @@ describe Projects::HousekeepingService do ...@@ -88,6 +88,19 @@ describe Projects::HousekeepingService do
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
housekeeping.execute
end
end
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