Commit 2d02f294 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch '296892-fj-add-housekeeping-service-to-wikis' into 'master'

Add housekeeping to wiki repository after git push operation

See merge request gitlab-org/gitlab!51576
parents 1b3ab330 13e40f61
......@@ -16,6 +16,7 @@ module Git
wiki.after_post_receive
process_changes
perform_housekeeping if Feature.enabled?(:wiki_housekeeping, wiki.container)
end
private
......@@ -72,6 +73,14 @@ module Git
def default_branch_changes
@default_branch_changes ||= changes.select { |change| on_default_branch?(change) }
end
def perform_housekeeping
housekeeping = Repositories::HousekeepingService.new(wiki)
housekeeping.increment!
housekeeping.execute if housekeeping.needed?
rescue Repositories::HousekeepingService::LeaseTaken
# no-op
end
end
end
......
......@@ -7,6 +7,17 @@ module Projects
private
# At the moment this was added, the default key was like this.
# With the addition of wikis to housekeeping, this will bring a
# problem because the wiki for project 1 will have the same
# lease key as project 1.
#
# In the `GitGarbageCollectMethods` we namespaced the resource,
# giving us the option to have different resources. Nevertheless,
# we kept this override in order for backward compatibility and avoid
# starting all projects from scratch.
#
# See https://gitlab.com/gitlab-org/gitlab/-/issues/299903
override :default_lease_key
def default_lease_key(task, resource)
"git_gc:#{task}:#{resource.id}"
......
---
name: wiki_housekeeping
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/51576
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/299343
milestone: '13.9'
type: development
group: group::editor
default_enabled: false
......@@ -257,6 +257,56 @@ RSpec.describe Git::WikiPushService, services: true do
end
end
describe '#perform_housekeeping', :clean_gitlab_redis_shared_state do
let(:housekeeping) { Repositories::HousekeepingService.new(wiki) }
subject { create_service(current_sha).execute }
before do
allow(Repositories::HousekeepingService).to receive(:new).and_return(housekeeping)
end
it 'does not perform housekeeping when not needed' do
expect(housekeeping).not_to receive(:execute)
subject
end
context 'when housekeeping is needed' do
before do
allow(housekeeping).to receive(:needed?).and_return(true)
end
it 'performs housekeeping' do
expect(housekeeping).to receive(:execute)
subject
end
it 'does not raise an exception' do
allow(housekeeping).to receive(:try_obtain_lease).and_return(false)
expect { subject }.not_to raise_error
end
context 'when feature flag :wiki_housekeeping is disabled' do
it 'does not perform housekeeping' do
stub_feature_flags(wiki_housekeeping: false)
expect(housekeeping).not_to receive(:execute)
subject
end
end
end
it 'increments the push counter' do
expect(housekeeping).to receive(:increment!)
subject
end
end
# In order to construct the correct GitPostReceive object that represents the
# changes we are applying, we need to describe the changes between old-ref and
# new-ref. Old ref (the base sha) we have to capture before we perform any
......
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