Commit 22e6683b authored by James Lopez's avatar James Lopez Committed by Nick Thomas

Fix in-progress repository syncs counting as failed

parent 1f95183f
...@@ -6,11 +6,8 @@ class Geo::ProjectRegistry < Geo::BaseRegistry ...@@ -6,11 +6,8 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
scope :dirty, -> { where(arel_table[:resync_repository].eq(true).or(arel_table[:resync_wiki].eq(true))) } scope :dirty, -> { where(arel_table[:resync_repository].eq(true).or(arel_table[:resync_wiki].eq(true))) }
def self.failed def self.failed
repository_sync_failed = arel_table[:last_repository_synced_at].not_eq(nil) repository_sync_failed = arel_table[:repository_retry_count].gt(0)
.and(arel_table[:last_repository_successful_sync_at].eq(nil)) wiki_sync_failed = arel_table[:wiki_retry_count].gt(0)
wiki_sync_failed = arel_table[:last_wiki_synced_at].not_eq(nil)
.and(arel_table[:last_wiki_successful_sync_at].eq(nil))
where(repository_sync_failed.or(wiki_sync_failed)) where(repository_sync_failed.or(wiki_sync_failed))
end end
......
...@@ -30,10 +30,12 @@ module Geo ...@@ -30,10 +30,12 @@ module Geo
Gitlab::Git::RepositoryMirroring::RemoteError, Gitlab::Git::RepositoryMirroring::RemoteError,
Geo::EmptyCloneUrlPrefixError => e Geo::EmptyCloneUrlPrefixError => e
log_error('Error syncing repository', e) log_error('Error syncing repository', e)
registry.increment!(:repository_retry_count)
rescue Gitlab::Git::Repository::NoRepository => e rescue Gitlab::Git::Repository::NoRepository => e
log_error('Invalid repository', e) log_error('Invalid repository', e)
log_info('Setting force_to_redownload flag') log_info('Setting force_to_redownload flag')
registry.update(force_to_redownload_repository: true) registry.update(force_to_redownload_repository: true,
repository_retry_count: retry_count + 1)
log_info('Expiring caches') log_info('Expiring caches')
project.repository.after_create project.repository.after_create
ensure ensure
...@@ -52,5 +54,9 @@ module Geo ...@@ -52,5 +54,9 @@ module Geo
def repository def repository
project.repository project.repository
end end
def retry_count
registry.public_send("#{type}_retry_count") || -1 # rubocop:disable GitlabSecurity/PublicSend
end
end end
end end
...@@ -33,9 +33,11 @@ module Geo ...@@ -33,9 +33,11 @@ module Geo
ProjectWiki::CouldNotCreateWikiError, ProjectWiki::CouldNotCreateWikiError,
Geo::EmptyCloneUrlPrefixError => e Geo::EmptyCloneUrlPrefixError => e
log_error('Error syncing wiki repository', e) log_error('Error syncing wiki repository', e)
registry.increment!(:wiki_retry_count)
rescue Gitlab::Git::Repository::NoRepository => e rescue Gitlab::Git::Repository::NoRepository => e
log_error('Invalid wiki', e) log_error('Invalid wiki', e)
registry.update(force_to_redownload_wiki: true) registry.update(force_to_redownload_wiki: true,
repository_retry_count: retry_count + 1)
ensure ensure
clean_up_temporary_repository if redownload clean_up_temporary_repository if redownload
end end
...@@ -47,5 +49,9 @@ module Geo ...@@ -47,5 +49,9 @@ module Geo
def repository def repository
project.wiki.repository project.wiki.repository
end end
def retry_count
registry.public_send("#{type}_retry_count") || -1 # rubocop:disable GitlabSecurity/PublicSend
end
end end
end end
---
title: Fix in-progress repository syncs counting as failed
merge_request: 3424
author:
type: fixed
...@@ -39,6 +39,7 @@ FactoryGirl.define do ...@@ -39,6 +39,7 @@ FactoryGirl.define do
last_wiki_successful_sync_at nil last_wiki_successful_sync_at nil
resync_repository true resync_repository true
resync_wiki true resync_wiki true
repository_retry_count 1
end end
trait :repository_sync_failed do trait :repository_sync_failed do
...@@ -48,6 +49,12 @@ FactoryGirl.define do ...@@ -48,6 +49,12 @@ FactoryGirl.define do
last_wiki_successful_sync_at { 5.days.ago } last_wiki_successful_sync_at { 5.days.ago }
resync_repository true resync_repository true
resync_wiki false resync_wiki false
repository_retry_count 1
end
trait :repository_syncing do
repository_sync_failed
repository_retry_count 0
end end
trait :wiki_sync_failed do trait :wiki_sync_failed do
...@@ -57,6 +64,12 @@ FactoryGirl.define do ...@@ -57,6 +64,12 @@ FactoryGirl.define do
last_wiki_successful_sync_at nil last_wiki_successful_sync_at nil
resync_repository false resync_repository false
resync_wiki true resync_wiki true
wiki_retry_count 2
end
trait :wiki_syncing do
wiki_sync_failed
wiki_retry_count 0
end end
end end
end end
...@@ -21,6 +21,9 @@ describe Geo::ProjectRegistry do ...@@ -21,6 +21,9 @@ describe Geo::ProjectRegistry do
it 'returns projects where last attempt to sync failed' do it 'returns projects where last attempt to sync failed' do
create(:geo_project_registry, :synced) create(:geo_project_registry, :synced)
create(:geo_project_registry, :synced, :dirty) create(:geo_project_registry, :synced, :dirty)
create(:geo_project_registry, :repository_syncing)
create(:geo_project_registry, :wiki_syncing)
repository_sync_failed = create(:geo_project_registry, :repository_sync_failed) repository_sync_failed = create(:geo_project_registry, :repository_sync_failed)
wiki_sync_failed = create(:geo_project_registry, :wiki_sync_failed) wiki_sync_failed = create(:geo_project_registry, :wiki_sync_failed)
......
...@@ -200,6 +200,8 @@ describe GeoNodeStatus, :geo do ...@@ -200,6 +200,8 @@ describe GeoNodeStatus, :geo do
before do before do
create(:geo_project_registry, :sync_failed, project: project_1) create(:geo_project_registry, :sync_failed, project: project_1)
create(:geo_project_registry, :sync_failed, project: project_3) create(:geo_project_registry, :sync_failed, project: project_3)
create(:geo_project_registry, :repository_syncing, project: project_4)
create(:geo_project_registry, :wiki_syncing)
end end
it 'returns the right number of failed repos with no group restrictions' do it 'returns the right number of failed repos with no group restrictions' do
......
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