Commit 811b3068 authored by Stan Hu's avatar Stan Hu

Merge branch 'da-track-registries-marked-as-synced' into 'master'

Track registries marked as synced when repository does not found

See merge request gitlab-org/gitlab-ee!6694
parents 1f29109f efa43df4
......@@ -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,
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
---
title: Track registries marked as synced when repository does not found
merge_request: 6694
author:
type: other
# 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
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......
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