Resync project repositories on secondaries nodes when import finishes

Project imports may not be synced if repository takes some time to
fetch. We also need to invalidate the checksum, otherwise we can
have stale checksums on the primary node.
parent 3fd62a46
......@@ -503,6 +503,12 @@ module EE
end
request_cache(:any_path_locks?) { self.id }
override :after_import
def after_import
super
log_geo_events
end
private
def set_override_pull_mirror_available
......@@ -538,5 +544,12 @@ module EE
def validate_board_limit(board)
# Board limits are disabled in EE, so this method is just a no-op.
end
def log_geo_events
return unless ::Gitlab::Geo.primary?
::Geo::RepositoryUpdatedService.new(self, source: ::Geo::RepositoryUpdatedEvent::REPOSITORY).execute
::Geo::RepositoryUpdatedService.new(self, source: ::Geo::RepositoryUpdatedEvent::WIKI).execute
end
end
end
......@@ -1481,4 +1481,40 @@ describe Project do
expect(project.latest_pipeline_with_security_reports).to eq(pipeline_2)
end
end
describe '#after_import' do
let(:project) { create(:project) }
let(:repository_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
let(:wiki_updated_service) { instance_double('::Geo::RepositoryUpdatedService') }
before do
allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project, source: Geo::RepositoryUpdatedEvent::REPOSITORY)
.and_return(repository_updated_service)
allow(::Geo::RepositoryUpdatedService)
.to receive(:new)
.with(project, source: Geo::RepositoryUpdatedEvent::WIKI)
.and_return(wiki_updated_service)
end
it 'calls Geo::RepositoryUpdatedService when running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?).and_return(true)
expect(repository_updated_service).to receive(:execute).once
expect(wiki_updated_service).to receive(:execute).once
project.after_import
end
it 'does not call Geo::RepositoryUpdatedService when not running on a Geo primary node' do
allow(Gitlab::Geo).to receive(:primary?).and_return(false)
expect(repository_updated_service).not_to receive(:execute)
expect(wiki_updated_service).not_to receive(:execute)
project.after_import
end
end
end
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