diff --git a/ee/app/models/geo/project_registry.rb b/ee/app/models/geo/project_registry.rb index 9d1c5ec1d4f376c7897f987ed9e8aec9d3a4e31c..3071beb84375a3a996cfb0bc3f9b52ea9c450838 100644 --- a/ee/app/models/geo/project_registry.rb +++ b/ee/app/models/geo/project_registry.rb @@ -71,7 +71,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry "#{type}_retry_at" => next_retry_time(new_count)) end - def finish_sync!(type) + def finish_sync!(type, missing_on_primary = false) update!( # Indicate that the sync succeeded (but separately mark as synced atomically) "last_#{type}_successful_sync_at" => Time.now, @@ -79,6 +79,7 @@ class Geo::ProjectRegistry < Geo::BaseRegistry "#{type}_retry_at" => nil, "force_to_redownload_#{type}" => false, "last_#{type}_sync_failure" => nil, + "#{type}_missing_on_primary" => missing_on_primary, # Indicate that repository verification needs to be done again "#{type}_verification_checksum_sha" => nil, diff --git a/ee/app/services/geo/base_sync_service.rb b/ee/app/services/geo/base_sync_service.rb index 7a03640c7a983e40accfb243c5f31c652c858fa2..6436da01eb103d0808d11851d2db1573fc8c9d7b 100644 --- a/ee/app/services/geo/base_sync_service.rb +++ b/ee/app/services/geo/base_sync_service.rb @@ -126,10 +126,10 @@ module Geo @registry ||= Geo::ProjectRegistry.find_or_initialize_by(project_id: project.id) end - def mark_sync_as_successful + def mark_sync_as_successful(missing_on_primary: false) log_info("Marking #{type} sync as successful") - persisted = registry.finish_sync!(type) + persisted = registry.finish_sync!(type, missing_on_primary) reschedule_sync unless persisted diff --git a/ee/app/services/geo/repository_sync_service.rb b/ee/app/services/geo/repository_sync_service.rb index eb0c1e451e6f0144eac486b490772878822f7e3f..83f9413a7eebb216442220b44b059b7a38e82b55 100644 --- a/ee/app/services/geo/repository_sync_service.rb +++ b/ee/app/services/geo/repository_sync_service.rb @@ -15,7 +15,7 @@ module Geo # If it does not exist we should consider it as successfully downloaded. if e.message.include? Gitlab::GitAccess::ERROR_MESSAGES[:no_repo] log_info('Repository is not found, marking it as successfully synced') - mark_sync_as_successful + mark_sync_as_successful(missing_on_primary: true) else fail_registry!('Error syncing repository', e) end diff --git a/ee/app/services/geo/wiki_sync_service.rb b/ee/app/services/geo/wiki_sync_service.rb index 85df3b6bc7d90516c982630dc7735cb8f81c6851..287411156880ca8a6f84f6059797083343273770 100644 --- a/ee/app/services/geo/wiki_sync_service.rb +++ b/ee/app/services/geo/wiki_sync_service.rb @@ -13,7 +13,7 @@ module Geo # If it does not exist we should consider it as successfully downloaded. if e.message.include? Gitlab::GitAccess::ERROR_MESSAGES[:no_repo] log_info('Wiki repository is not found, marking it as successfully synced') - mark_sync_as_successful + mark_sync_as_successful(missing_on_primary: true) else fail_registry!('Error syncing wiki repository', e) end diff --git a/ee/changelogs/unreleased/da-track-registries-marked-as-synced.yml b/ee/changelogs/unreleased/da-track-registries-marked-as-synced.yml new file mode 100644 index 0000000000000000000000000000000000000000..a3b3bd329a635ff79a47fe5e19b2039c26d5cfe2 --- /dev/null +++ b/ee/changelogs/unreleased/da-track-registries-marked-as-synced.yml @@ -0,0 +1,5 @@ +--- +title: Track registries marked as synced when repository does not found +merge_request: 6694 +author: +type: other diff --git a/ee/db/geo/migrate/20180727221937_add_missing_on_primary_to_project_registry.rb b/ee/db/geo/migrate/20180727221937_add_missing_on_primary_to_project_registry.rb new file mode 100644 index 0000000000000000000000000000000000000000..b89c9dd82ce996fe5f924e2bf52139d9c5765feb --- /dev/null +++ b/ee/db/geo/migrate/20180727221937_add_missing_on_primary_to_project_registry.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddMissingOnPrimaryToProjectRegistry < ActiveRecord::Migration + def change + add_column :project_registry, :repository_missing_on_primary, :boolean + add_column :project_registry, :wiki_missing_on_primary, :boolean + end +end diff --git a/ee/db/geo/schema.rb b/ee/db/geo/schema.rb index 0431c54503249ec652f3f413bf90f1facf88eef0..504458a5d65407ba9522edd8b8a3b4e3e28261cc 100644 --- a/ee/db/geo/schema.rb +++ b/ee/db/geo/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180613184349) do +ActiveRecord::Schema.define(version: 20180727221937) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -78,6 +78,8 @@ ActiveRecord::Schema.define(version: 20180613184349) do t.datetime_with_timezone "last_repository_check_at" t.datetime_with_timezone "resync_repository_was_scheduled_at" t.datetime_with_timezone "resync_wiki_was_scheduled_at" + t.boolean "repository_missing_on_primary" + t.boolean "wiki_missing_on_primary" end add_index "project_registry", ["last_repository_successful_sync_at"], name: "index_project_registry_on_last_repository_successful_sync_at", using: :btree diff --git a/ee/spec/models/geo/project_registry_spec.rb b/ee/spec/models/geo/project_registry_spec.rb index abb8cda7896c7fa6aa7fbc190f6a6c25db869dd1..a3463b5b45b9cfa1d8b79667f490a6ad3f8c4c49 100644 --- a/ee/spec/models/geo/project_registry_spec.rb +++ b/ee/spec/models/geo/project_registry_spec.rb @@ -406,11 +406,14 @@ describe Geo::ProjectRegistry do it 'resets sync state' do subject.finish_sync!(type) - expect(subject.reload.resync_repository).to be false - expect(subject.reload.repository_retry_count).to be_nil - expect(subject.reload.repository_retry_at).to be_nil - expect(subject.reload.force_to_redownload_repository).to be false - expect(subject.reload.last_repository_sync_failure).to be_nil + expect(subject.reload).to have_attributes( + resync_repository: false, + repository_retry_count: be_nil, + repository_retry_at: be_nil, + force_to_redownload_repository: false, + last_repository_sync_failure: be_nil, + repository_missing_on_primary: false + ) end it 'resets verification state' do @@ -421,6 +424,14 @@ describe Geo::ProjectRegistry do expect(subject.reload.last_repository_verification_failure).to be_nil end + context 'when a repository was missing on primary' do + it 'sets repository_missing_on_primary as true' do + subject.finish_sync!(type, true) + + expect(subject.reload.repository_missing_on_primary).to be true + end + end + context 'when a repository sync was scheduled after the last sync began' do before do subject.update!(resync_repository_was_scheduled_at: subject.last_repository_synced_at + 1.minute) @@ -470,11 +481,14 @@ describe Geo::ProjectRegistry do it 'resets sync state' do subject.finish_sync!(type) - expect(subject.reload.resync_wiki).to be false - expect(subject.reload.wiki_retry_count).to be_nil - expect(subject.reload.wiki_retry_at).to be_nil - expect(subject.reload.force_to_redownload_wiki).to be false - expect(subject.reload.last_wiki_sync_failure).to be_nil + expect(subject.reload).to have_attributes( + resync_wiki: false, + wiki_retry_count: be_nil, + wiki_retry_at: be_nil, + force_to_redownload_wiki: false, + last_wiki_sync_failure: be_nil, + wiki_missing_on_primary: false + ) end it 'resets verification state' do @@ -485,6 +499,14 @@ describe Geo::ProjectRegistry do expect(subject.reload.last_wiki_verification_failure).to be_nil end + context 'when a wiki was missing on primary' do + it 'sets wiki_missing_on_primary as true' do + subject.finish_sync!(type, true) + + expect(subject.reload.wiki_missing_on_primary).to be true + end + end + context 'when a wiki sync was scheduled after the last sync began' do before do subject.update!(resync_wiki_was_scheduled_at: subject.last_wiki_synced_at + 1.minute) diff --git a/ee/spec/services/geo/repository_sync_service_spec.rb b/ee/spec/services/geo/repository_sync_service_spec.rb index 720d27e02605d452e6fb53904f665307554a6d91..7f816aaa7a236e3f757c087375e616e2821fe9cd 100644 --- a/ee/spec/services/geo/repository_sync_service_spec.rb +++ b/ee/spec/services/geo/repository_sync_service_spec.rb @@ -105,8 +105,10 @@ describe Geo::RepositorySyncService do subject.execute - expect(Geo::ProjectRegistry.last.resync_repository).to be true - expect(Geo::ProjectRegistry.last.repository_retry_count).to eq(1) + expect(Geo::ProjectRegistry.last).to have_attributes( + resync_repository: true, + repository_retry_count: 1 + ) end it 'marks sync as successful if no repository found' do @@ -118,8 +120,11 @@ describe Geo::RepositorySyncService do subject.execute - expect(registry.reload.resync_repository).to be false - expect(registry.reload.last_repository_successful_sync_at).not_to be nil + expect(registry.reload).to have_attributes( + resync_repository: false, + last_repository_successful_sync_at: be_present, + repository_missing_on_primary: true + ) end it 'marks resync as true after a failure' do diff --git a/ee/spec/services/geo/wiki_sync_service_spec.rb b/ee/spec/services/geo/wiki_sync_service_spec.rb index ed16fceb65a419a8ddac6559f4e4c91acb76ae77..050e2347aff3f3ec1b8b7bbaeeec553545d5b4fe 100644 --- a/ee/spec/services/geo/wiki_sync_service_spec.rb +++ b/ee/spec/services/geo/wiki_sync_service_spec.rb @@ -84,8 +84,10 @@ RSpec.describe Geo::WikiSyncService do subject.execute - expect(Geo::ProjectRegistry.last.resync_wiki).to be true - expect(Geo::ProjectRegistry.last.wiki_retry_count).to eq(1) + expect(Geo::ProjectRegistry.last).to have_attributes( + resync_wiki: true, + wiki_retry_count: 1 + ) end it 'marks sync as successful if no repository found' do @@ -97,8 +99,11 @@ RSpec.describe Geo::WikiSyncService do subject.execute - expect(registry.reload.resync_wiki).to be false - expect(registry.last_wiki_successful_sync_at).not_to be nil + expect(registry.reload).to have_attributes( + resync_wiki: false, + last_wiki_successful_sync_at: be_present, + wiki_missing_on_primary: true + ) end it 'marks resync as true after a failure' do