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