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
copy_gitattributes(branch)
after_change_head
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
end
end
......
......@@ -37,7 +37,6 @@ module Geo
def sync_repository
start_registry_sync!
fetch_repository
update_root_ref
mark_sync_as_successful
rescue Gitlab::Git::Repository::NoRepository => e
log_info('Marking the repository for a forced re-download')
......@@ -83,6 +82,8 @@ module Geo
fetch_geo_mirror(repository)
@new_repository = true
end
update_root_ref
end
def redownload_repository
......
......@@ -63,6 +63,8 @@ module Geo
fetch_geo_mirror(repository)
@new_repository = true
end
update_root_ref
end
def redownload?
......@@ -270,5 +272,13 @@ module Geo
checksum = project.repository_state.public_send("#{type}_verification_checksum") # rubocop:disable GitlabSecurity/PublicSend
checksum && checksum != Gitlab::Git::Repository::EMPTY_REPOSITORY_CHECKSUM
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
......@@ -9,7 +9,6 @@ module Geo
def sync_repository
start_registry_sync!
fetch_repository
update_root_ref
mark_sync_as_successful
rescue Gitlab::Git::Repository::NoRepository => e
log_info('Setting force_to_redownload flag')
......@@ -49,14 +48,6 @@ module Geo
project.ensure_repository
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
Geo::ProjectHousekeepingService.new(project, new_repository: new_repository?).execute
end
......
......@@ -35,12 +35,11 @@ RSpec.describe Geo::DesignRepositorySyncService do
stub_exclusive_lease(lease_key, lease_uuid)
stub_exclusive_lease("geo_project_housekeeping:#{project.id}")
allow_any_instance_of(Repository).to receive(:fetch_as_mirror)
.and_return(true)
allow(repository).to receive(:fetch_as_mirror).and_return(true)
allow_any_instance_of(Repository)
allow(repository)
.to receive(:find_remote_root_ref)
.with(url_to_repo)
.with(url_to_repo, anything)
.and_return('master')
allow_any_instance_of(Geo::ProjectHousekeepingService).to receive(:execute)
......
......@@ -34,7 +34,7 @@ RSpec.describe Geo::RepositorySyncService, :geo do
allow_any_instance_of(Repository).to receive(:fetch_as_mirror)
.and_return(true)
allow_any_instance_of(Repository)
allow(repository)
.to receive(:find_remote_root_ref)
.with(url_to_repo, anything)
.and_return('master')
......
......@@ -45,6 +45,8 @@ RSpec.describe Geo::WikiSyncService, :geo do
end
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')
expect { subject.execute }.to change { registry.reload.last_wiki_sync_failure }.to(nil)
......@@ -126,6 +128,8 @@ RSpec.describe Geo::WikiSyncService, :geo do
end
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)
registry = create(:geo_project_registry, project: project, primary_wiki_checksummed: false)
......@@ -133,6 +137,8 @@ RSpec.describe Geo::WikiSyncService, :geo do
end
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)
registry = create(:geo_project_registry, project: project, primary_wiki_checksummed: true)
......@@ -166,6 +172,8 @@ RSpec.describe Geo::WikiSyncService, :geo do
end
it 'sets last_wiki_successful_sync_at' do
allow(repository).to receive(:update_root_ref)
subject.execute
expect(registry.last_wiki_successful_sync_at).not_to be_nil
......@@ -190,7 +198,9 @@ RSpec.describe Geo::WikiSyncService, :geo do
end
it 'logs success with timings' do
allow(repository).to receive(:update_root_ref)
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
subject.execute
......@@ -232,6 +242,7 @@ RSpec.describe Geo::WikiSyncService, :geo do
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(subject).not_to receive(:fail_registry_sync!)
......
......@@ -65,6 +65,7 @@ RSpec.shared_examples 'geo base sync fetch' do
before do
allow(subject).to receive(:fetch_geo_mirror).and_return(true)
allow(repository).to receive(:update_root_ref)
end
it 'cleans up temporary repository' do
......@@ -79,6 +80,12 @@ RSpec.shared_examples 'geo base sync fetch' do
fetch_repository
end
it 'syncs the HEAD ref' do
expect(repository).to receive(:update_root_ref)
fetch_repository
end
context 'repository does not exist' do
before do
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