Ensure pool participants are linked before GC
In theory the case could happen that the initial linking of the pool fails and so do all the retries that Sidekiq performs. This could lead to data loss. To prevent that case, linking is done before Gits GC too. This makes sure that case doesn't happen.
This commit is contained in:
parent
94d05e3c5c
commit
e03602e09d
4 changed files with 21 additions and 6 deletions
|
@ -2039,6 +2039,10 @@ class Project < ActiveRecord::Base
|
||||||
pool_repository&.unlink_repository(repository) && update_column(:pool_repository_id, nil)
|
pool_repository&.unlink_repository(repository) && update_column(:pool_repository_id, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def link_pool_repository
|
||||||
|
pool_repository&.link_repository(repository)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def merge_requests_allowing_collaboration(source_branch = nil)
|
def merge_requests_allowing_collaboration(source_branch = nil)
|
||||||
|
|
|
@ -23,6 +23,7 @@ class GitGarbageCollectWorker
|
||||||
end
|
end
|
||||||
|
|
||||||
task = task.to_sym
|
task = task.to_sym
|
||||||
|
project.link_pool_repository
|
||||||
gitaly_call(task, project.repository.raw_repository)
|
gitaly_call(task, project.repository.raw_repository)
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
@ -5,14 +5,13 @@ module ObjectPool
|
||||||
include ApplicationWorker
|
include ApplicationWorker
|
||||||
include ObjectPoolQueue
|
include ObjectPoolQueue
|
||||||
|
|
||||||
def perform(pool_id, project_id)
|
# The use of pool id is deprecated. Keeping the argument allows old jobs to
|
||||||
pool = PoolRepository.find_by_id(pool_id)
|
# still be performed.
|
||||||
return unless pool&.joinable?
|
def perform(_pool_id, project_id)
|
||||||
|
|
||||||
project = Project.find_by_id(project_id)
|
project = Project.find_by_id(project_id)
|
||||||
return unless project
|
return unless project&.pool_repository&.joinable?
|
||||||
|
|
||||||
pool.link_repository(project.repository)
|
project.link_pool_repository
|
||||||
|
|
||||||
Projects::HousekeepingService.new(project).execute
|
Projects::HousekeepingService.new(project).execute
|
||||||
end
|
end
|
||||||
|
|
|
@ -71,6 +71,17 @@ describe GitGarbageCollectWorker do
|
||||||
|
|
||||||
subject.perform(project.id)
|
subject.perform(project.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the repository has joined a pool' do
|
||||||
|
let!(:pool) { create(:pool_repository, :ready) }
|
||||||
|
let(:project) { pool.source_project }
|
||||||
|
|
||||||
|
it 'ensures the repositories are linked' do
|
||||||
|
expect_any_instance_of(PoolRepository).to receive(:link_repository).once
|
||||||
|
|
||||||
|
subject.perform(project.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when no lease can be obtained' do
|
context 'when no lease can be obtained' do
|
||||||
|
|
Loading…
Reference in a new issue