Commit 7e911edc authored by Michael Kozono's avatar Michael Kozono

Stop passing around `redownload` unnecessarily

parent e10c719d
......@@ -136,10 +136,10 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
Gitlab::Redis::SharedState.with { |redis| redis.set(fetches_since_gc_redis_key, value) }
end
def should_be_retried?(type)
return false if public_send("force_to_redownload_#{type}") # rubocop:disable GitlabSecurity/PublicSend
def should_be_redownloaded?(type)
return true if public_send("force_to_redownload_#{type}") # rubocop:disable GitlabSecurity/PublicSend
retry_count(type) <= RETRIES_BEFORE_REDOWNLOAD
retry_count(type) > RETRIES_BEFORE_REDOWNLOAD
end
private
......
......@@ -25,11 +25,7 @@ module Geo
try_obtain_lease do
log_info("Started #{type} sync")
if registry.should_be_retried?(type)
sync_repository
else
sync_repository(true)
end
sync_repository
log_info("Finished #{type} sync")
end
......@@ -45,7 +41,7 @@ module Geo
private
def fetch_repository(redownload)
def fetch_repository
log_info("Trying to fetch #{type}")
clean_up_temporary_repository
......@@ -53,9 +49,8 @@ module Geo
registry.start_sync!(type)
if redownload
if redownload?
redownload_repository
set_temp_repository_as_main
schedule_repack
elsif repository.exists?
fetch_geo_mirror(repository)
......@@ -66,6 +61,10 @@ module Geo
end
end
def redownload?
registry.should_be_redownloaded?(type)
end
def schedule_repack
raise NotImplementedError
end
......@@ -83,6 +82,10 @@ module Geo
end
fetch_geo_mirror(temp_repo)
set_temp_repository_as_main
ensure
clean_up_temporary_repository
end
def current_node
......
......@@ -4,8 +4,8 @@ module Geo
private
def sync_repository(redownload = false)
fetch_repository(redownload)
def sync_repository
fetch_repository
update_gitattributes
......@@ -27,7 +27,6 @@ module Geo
log_info('Expiring caches')
project.repository.after_create
ensure
clean_up_temporary_repository if redownload
expire_repository_caches
execute_housekeeping
end
......
......@@ -4,8 +4,8 @@ module Geo
private
def sync_repository(redownload = false)
fetch_repository(redownload)
def sync_repository
fetch_repository
mark_sync_as_successful
rescue Gitlab::Git::RepositoryMirroring::RemoteError,
......@@ -23,7 +23,6 @@ module Geo
log_info('Setting force_to_redownload flag')
fail_registry!('Invalid wiki', e, force_to_redownload_wiki: true)
ensure
clean_up_temporary_repository if redownload
expire_repository_caches
end
......
......@@ -253,7 +253,7 @@ describe Geo::RepositorySyncService do
it 'tries to fetch repo' do
create(:geo_project_registry, project: project, repository_retry_count: Geo::ProjectRegistry::RETRIES_BEFORE_REDOWNLOAD - 1)
expect(subject).to receive(:sync_repository).with(no_args)
expect(subject).to receive(:sync_repository)
subject.execute
end
......@@ -269,7 +269,7 @@ describe Geo::RepositorySyncService do
it 'tries to redownload repo' do
create(:geo_project_registry, project: project, repository_retry_count: Geo::ProjectRegistry::RETRIES_BEFORE_REDOWNLOAD + 1)
expect(subject).to receive(:sync_repository).with(true).and_call_original
expect(subject).to receive(:sync_repository).and_call_original
expect(subject.gitlab_shell).to receive(:mv_repository).exactly(2).times.and_call_original
expect(subject.gitlab_shell).to receive(:add_namespace).with(
......@@ -297,7 +297,7 @@ describe Geo::RepositorySyncService do
force_to_redownload_repository: true
)
expect(subject).to receive(:sync_repository).with(true)
expect(subject).to receive(:sync_repository)
subject.execute
end
......
......@@ -50,7 +50,7 @@ end
shared_examples 'geo base sync fetch and repack' do
describe '#fetch_repository' do
let(:fetch_repository) { subject.send(:fetch_repository, false) }
let(:fetch_repository) { subject.send(:fetch_repository) }
before do
allow(subject).to receive(:fetch_geo_mirror).and_return(true)
......
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