Commit 57cba4d1 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'sh-force-gc-after-import' into 'master'

Force a full GC after importing a project

Closes #59477

See merge request gitlab-org/gitlab-ce!26803
parents 90614929 d4c6a3af
...@@ -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