Commit 202c9728 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch 'mk/geo-sync-wiki-head-ref' into 'master'

Geo: Replicate wiki and design HEAD ref if needed

See merge request gitlab-org/gitlab!68324
parents 9d9c6930 7aaa1413
...@@ -1125,7 +1125,11 @@ class Repository ...@@ -1125,7 +1125,11 @@ class Repository
copy_gitattributes(branch) copy_gitattributes(branch)
after_change_head after_change_head
else else
container.errors.add(:base, _("Could not change HEAD: branch '%{branch}' does not exist") % { branch: branch }) # For example, `Wiki` does not have `errors` because it is not an `ActiveModel`
if container.respond_to?(:errors)
container.errors.add(:base, _("Could not change HEAD: branch '%{branch}' does not exist") % { branch: branch })
end
false false
end end
end end
......
...@@ -37,7 +37,6 @@ module Geo ...@@ -37,7 +37,6 @@ module Geo
def sync_repository def sync_repository
start_registry_sync! start_registry_sync!
fetch_repository fetch_repository
update_root_ref
mark_sync_as_successful mark_sync_as_successful
rescue Gitlab::Git::Repository::NoRepository => e rescue Gitlab::Git::Repository::NoRepository => e
log_info('Marking the repository for a forced re-download') log_info('Marking the repository for a forced re-download')
...@@ -83,6 +82,8 @@ module Geo ...@@ -83,6 +82,8 @@ module Geo
fetch_geo_mirror(repository) fetch_geo_mirror(repository)
@new_repository = true @new_repository = true
end end
update_root_ref
end end
def redownload_repository def redownload_repository
......
...@@ -63,6 +63,8 @@ module Geo ...@@ -63,6 +63,8 @@ module Geo
fetch_geo_mirror(repository) fetch_geo_mirror(repository)
@new_repository = true @new_repository = true
end end
update_root_ref
end end
def redownload? def redownload?
...@@ -270,5 +272,13 @@ module Geo ...@@ -270,5 +272,13 @@ module Geo
checksum = project.repository_state.public_send("#{type}_verification_checksum") # rubocop:disable GitlabSecurity/PublicSend checksum = project.repository_state.public_send("#{type}_verification_checksum") # rubocop:disable GitlabSecurity/PublicSend
checksum && checksum != Gitlab::Git::Repository::EMPTY_REPOSITORY_CHECKSUM checksum && checksum != Gitlab::Git::Repository::EMPTY_REPOSITORY_CHECKSUM
end end
def update_root_ref
authorization = ::Gitlab::Geo::RepoSyncRequest.new(
scope: repository.full_path
).authorization
repository.update_root_ref(remote_url, authorization)
end
end end
end end
...@@ -9,7 +9,6 @@ module Geo ...@@ -9,7 +9,6 @@ module Geo
def sync_repository def sync_repository
start_registry_sync! start_registry_sync!
fetch_repository fetch_repository
update_root_ref
mark_sync_as_successful mark_sync_as_successful
rescue Gitlab::Git::Repository::NoRepository => e rescue Gitlab::Git::Repository::NoRepository => e
log_info('Setting force_to_redownload flag') log_info('Setting force_to_redownload flag')
...@@ -49,14 +48,6 @@ module Geo ...@@ -49,14 +48,6 @@ module Geo
project.ensure_repository project.ensure_repository
end end
def update_root_ref
authorization = ::Gitlab::Geo::RepoSyncRequest.new(
scope: repository.full_path
).authorization
repository.update_root_ref(remote_url, authorization)
end
def execute_housekeeping def execute_housekeeping
Geo::ProjectHousekeepingService.new(project, new_repository: new_repository?).execute Geo::ProjectHousekeepingService.new(project, new_repository: new_repository?).execute
end end
......
...@@ -35,12 +35,11 @@ RSpec.describe Geo::DesignRepositorySyncService do ...@@ -35,12 +35,11 @@ RSpec.describe Geo::DesignRepositorySyncService do
stub_exclusive_lease(lease_key, lease_uuid) stub_exclusive_lease(lease_key, lease_uuid)
stub_exclusive_lease("geo_project_housekeeping:#{project.id}") stub_exclusive_lease("geo_project_housekeeping:#{project.id}")
allow_any_instance_of(Repository).to receive(:fetch_as_mirror) allow(repository).to receive(:fetch_as_mirror).and_return(true)
.and_return(true)
allow_any_instance_of(Repository) allow(repository)
.to receive(:find_remote_root_ref) .to receive(:find_remote_root_ref)
.with(url_to_repo) .with(url_to_repo, anything)
.and_return('master') .and_return('master')
allow_any_instance_of(Geo::ProjectHousekeepingService).to receive(:execute) allow_any_instance_of(Geo::ProjectHousekeepingService).to receive(:execute)
......
...@@ -34,7 +34,7 @@ RSpec.describe Geo::RepositorySyncService, :geo do ...@@ -34,7 +34,7 @@ RSpec.describe Geo::RepositorySyncService, :geo do
allow_any_instance_of(Repository).to receive(:fetch_as_mirror) allow_any_instance_of(Repository).to receive(:fetch_as_mirror)
.and_return(true) .and_return(true)
allow_any_instance_of(Repository) allow(repository)
.to receive(:find_remote_root_ref) .to receive(:find_remote_root_ref)
.with(url_to_repo, anything) .with(url_to_repo, anything)
.and_return('master') .and_return('master')
......
...@@ -45,6 +45,8 @@ RSpec.describe Geo::WikiSyncService, :geo do ...@@ -45,6 +45,8 @@ RSpec.describe Geo::WikiSyncService, :geo do
end end
it 'voids the failure message when it succeeds after an error' do it 'voids the failure message when it succeeds after an error' do
allow(repository).to receive(:update_root_ref)
registry = create(:geo_project_registry, project: project, last_wiki_sync_failure: 'error') registry = create(:geo_project_registry, project: project, last_wiki_sync_failure: 'error')
expect { subject.execute }.to change { registry.reload.last_wiki_sync_failure }.to(nil) expect { subject.execute }.to change { registry.reload.last_wiki_sync_failure }.to(nil)
...@@ -126,6 +128,8 @@ RSpec.describe Geo::WikiSyncService, :geo do ...@@ -126,6 +128,8 @@ RSpec.describe Geo::WikiSyncService, :geo do
end end
it 'marks primary_wiki_checksummed as true when wiki has been verified on primary' do it 'marks primary_wiki_checksummed as true when wiki has been verified on primary' do
allow(repository).to receive(:update_root_ref)
create(:repository_state, :wiki_verified, project: project) create(:repository_state, :wiki_verified, project: project)
registry = create(:geo_project_registry, project: project, primary_wiki_checksummed: false) registry = create(:geo_project_registry, project: project, primary_wiki_checksummed: false)
...@@ -133,6 +137,8 @@ RSpec.describe Geo::WikiSyncService, :geo do ...@@ -133,6 +137,8 @@ RSpec.describe Geo::WikiSyncService, :geo do
end end
it 'marks primary_wiki_checksummed as false when wiki has not been verified on primary' do it 'marks primary_wiki_checksummed as false when wiki has not been verified on primary' do
allow(repository).to receive(:update_root_ref)
create(:repository_state, :wiki_failed, project: project) create(:repository_state, :wiki_failed, project: project)
registry = create(:geo_project_registry, project: project, primary_wiki_checksummed: true) registry = create(:geo_project_registry, project: project, primary_wiki_checksummed: true)
...@@ -166,6 +172,8 @@ RSpec.describe Geo::WikiSyncService, :geo do ...@@ -166,6 +172,8 @@ RSpec.describe Geo::WikiSyncService, :geo do
end end
it 'sets last_wiki_successful_sync_at' do it 'sets last_wiki_successful_sync_at' do
allow(repository).to receive(:update_root_ref)
subject.execute subject.execute
expect(registry.last_wiki_successful_sync_at).not_to be_nil expect(registry.last_wiki_successful_sync_at).not_to be_nil
...@@ -190,7 +198,9 @@ RSpec.describe Geo::WikiSyncService, :geo do ...@@ -190,7 +198,9 @@ RSpec.describe Geo::WikiSyncService, :geo do
end end
it 'logs success with timings' do it 'logs success with timings' do
allow(repository).to receive(:update_root_ref)
allow(Gitlab::Geo::Logger).to receive(:info).and_call_original allow(Gitlab::Geo::Logger).to receive(:info).and_call_original
expect(Gitlab::Geo::Logger).to receive(:info).with(hash_including(:message, :update_delay_s, :download_time_s)).and_call_original expect(Gitlab::Geo::Logger).to receive(:info).with(hash_including(:message, :update_delay_s, :download_time_s)).and_call_original
subject.execute subject.execute
...@@ -232,6 +242,7 @@ RSpec.describe Geo::WikiSyncService, :geo do ...@@ -232,6 +242,7 @@ RSpec.describe Geo::WikiSyncService, :geo do
force_to_redownload_wiki: true force_to_redownload_wiki: true
) )
allow(project.wiki.repository).to receive(:update_root_ref)
expect(project.wiki.repository).to receive(:expire_exists_cache).exactly(3).times.and_call_original expect(project.wiki.repository).to receive(:expire_exists_cache).exactly(3).times.and_call_original
expect(subject).not_to receive(:fail_registry_sync!) expect(subject).not_to receive(:fail_registry_sync!)
......
...@@ -65,6 +65,7 @@ RSpec.shared_examples 'geo base sync fetch' do ...@@ -65,6 +65,7 @@ RSpec.shared_examples 'geo base sync fetch' do
before do before do
allow(subject).to receive(:fetch_geo_mirror).and_return(true) allow(subject).to receive(:fetch_geo_mirror).and_return(true)
allow(repository).to receive(:update_root_ref)
end end
it 'cleans up temporary repository' do it 'cleans up temporary repository' do
...@@ -79,6 +80,12 @@ RSpec.shared_examples 'geo base sync fetch' do ...@@ -79,6 +80,12 @@ RSpec.shared_examples 'geo base sync fetch' do
fetch_repository fetch_repository
end end
it 'syncs the HEAD ref' do
expect(repository).to receive(:update_root_ref)
fetch_repository
end
context 'repository does not exist' do context 'repository does not exist' do
before do before do
allow_any_instance_of(Repository).to receive(:exists?) { false } allow_any_instance_of(Repository).to receive(:exists?) { false }
......
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