Commit daf543ff authored by Stan Hu's avatar Stan Hu

Merge branch 'bw-verification-resync-fix' into 'master'

Geo repository verification: ignore repos/wikis needing resync

See merge request gitlab-org/gitlab-ee!5568
parents 625caf57 f8f16b18
...@@ -181,12 +181,10 @@ module Geo ...@@ -181,12 +181,10 @@ module Geo
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of registries that need verification # @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of registries that need verification
def fdw_find_registries_to_verify(batch_size:) def fdw_find_registries_to_verify(batch_size:)
repo_condition = repo_condition =
local_registry_table[:repository_verification_checksum_sha].eq(nil) local_repo_condition
.and(local_registry_table[:last_repository_verification_failure].eq(nil))
.and(fdw_repository_state_table[:repository_verification_checksum].not_eq(nil)) .and(fdw_repository_state_table[:repository_verification_checksum].not_eq(nil))
wiki_condition = wiki_condition =
local_registry_table[:wiki_verification_checksum_sha].eq(nil) local_wiki_condition
.and(local_registry_table[:last_wiki_verification_failure].eq(nil))
.and(fdw_repository_state_table[:wiki_verification_checksum].not_eq(nil)) .and(fdw_repository_state_table[:wiki_verification_checksum].not_eq(nil))
Geo::ProjectRegistry Geo::ProjectRegistry
...@@ -316,12 +314,8 @@ module Geo ...@@ -316,12 +314,8 @@ module Geo
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of registries that need verification # @return [ActiveRecord::Relation<Geo::ProjectRegistry>] list of registries that need verification
def legacy_find_registries_to_verify(batch_size:) def legacy_find_registries_to_verify(batch_size:)
repo_condition = repo_condition = local_repo_condition
local_registry_table[:repository_verification_checksum_sha].eq(nil) wiki_condition = local_wiki_condition
.and(local_registry_table[:last_repository_verification_failure].eq(nil))
wiki_condition =
local_registry_table[:wiki_verification_checksum_sha].eq(nil)
.and(local_registry_table[:last_wiki_verification_failure].eq(nil))
registries = Geo::ProjectRegistry registries = Geo::ProjectRegistry
.where(repo_condition.or(wiki_condition)) .where(repo_condition.or(wiki_condition))
...@@ -355,10 +349,6 @@ module Geo ...@@ -355,10 +349,6 @@ module Geo
Geo::ProjectRegistry.where(project_id: project_ids) Geo::ProjectRegistry.where(project_id: project_ids)
end end
def local_registry_table
Geo::ProjectRegistry.arel_table
end
def legacy_repository_state_table def legacy_repository_state_table
::ProjectRepositoryState.arel_table ::ProjectRepositoryState.arel_table
end end
...@@ -370,5 +360,21 @@ module Geo ...@@ -370,5 +360,21 @@ module Geo
def fdw_repository_state_table def fdw_repository_state_table
Geo::Fdw::ProjectRepositoryState.arel_table Geo::Fdw::ProjectRepositoryState.arel_table
end end
def local_registry_table
Geo::ProjectRegistry.arel_table
end
def local_repo_condition
local_registry_table[:repository_verification_checksum_sha].eq(nil)
.and(local_registry_table[:last_repository_verification_failure].eq(nil))
.and(local_registry_table[:resync_repository].eq(false))
end
def local_wiki_condition
local_registry_table[:wiki_verification_checksum_sha].eq(nil)
.and(local_registry_table[:last_wiki_verification_failure].eq(nil))
.and(local_registry_table[:resync_wiki].eq(false))
end
end end
end end
---
title: During repository verification, ignore repositories/wikis that need to be resynced
merge_request: 5568
author:
type: fixed
...@@ -509,10 +509,10 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -509,10 +509,10 @@ describe Geo::ProjectRegistryFinder, :geo do
repository_outdated_secondary = create(:repository_state, :repository_verified, :wiki_verified).project repository_outdated_secondary = create(:repository_state, :repository_verified, :wiki_verified).project
wiki_outdated_secondary = create(:repository_state, :repository_verified, :wiki_verified).project wiki_outdated_secondary = create(:repository_state, :repository_verified, :wiki_verified).project
registry_unverified_secondary = create(:geo_project_registry, project: project_unverified_secondary) registry_unverified_secondary = create(:geo_project_registry, :synced, project: project_unverified_secondary)
registry_outdated_secondary = create(:geo_project_registry, :repository_verification_outdated, :wiki_verification_outdated, project: project_outdated_secondary) registry_outdated_secondary = create(:geo_project_registry, :synced, :repository_verification_outdated, :wiki_verification_outdated, project: project_outdated_secondary)
registry_repository_outdated_secondary = create(:geo_project_registry, :repository_verification_outdated, :wiki_verified, project: repository_outdated_secondary) registry_repository_outdated_secondary = create(:geo_project_registry, :synced, :repository_verification_outdated, :wiki_verified, project: repository_outdated_secondary)
registry_wiki_outdated_secondary = create(:geo_project_registry, :repository_verified, :wiki_verification_outdated, project: wiki_outdated_secondary) registry_wiki_outdated_secondary = create(:geo_project_registry, :synced, :repository_verified, :wiki_verification_outdated, project: wiki_outdated_secondary)
expect(subject.find_registries_to_verify(batch_size: 100)) expect(subject.find_registries_to_verify(batch_size: 100))
.to match_array([ .to match_array([
...@@ -536,9 +536,9 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -536,9 +536,9 @@ describe Geo::ProjectRegistryFinder, :geo do
repository_failed_primary = create(:repository_state, :repository_failed, :wiki_verified).project repository_failed_primary = create(:repository_state, :repository_failed, :wiki_verified).project
wiki_failed_primary = create(:repository_state, :repository_verified, :wiki_failed).project wiki_failed_primary = create(:repository_state, :repository_verified, :wiki_failed).project
create(:geo_project_registry, project: verification_failed_primary) create(:geo_project_registry, :synced, project: verification_failed_primary)
registry_repository_failed_primary = create(:geo_project_registry, project: repository_failed_primary) registry_repository_failed_primary = create(:geo_project_registry, :synced, project: repository_failed_primary)
registry_wiki_failed_primary = create(:geo_project_registry, project: wiki_failed_primary) registry_wiki_failed_primary = create(:geo_project_registry, :synced, project: wiki_failed_primary)
expect(subject.find_registries_to_verify(batch_size: 100)) expect(subject.find_registries_to_verify(batch_size: 100))
.to match_array([ .to match_array([
...@@ -559,6 +559,20 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -559,6 +559,20 @@ describe Geo::ProjectRegistryFinder, :geo do
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty
end end
it 'does not return registries when the repo needs to be resynced' do
project_verified = create(:repository_state, :repository_verified).project
create(:geo_project_registry, :repository_sync_failed, project: project_verified)
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty
end
it 'does not return registries when the wiki needs to be resynced' do
project_verified = create(:repository_state, :wiki_verified).project
create(:geo_project_registry, :wiki_sync_failed, project: project_verified)
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty
end
end end
end end
......
...@@ -26,8 +26,8 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea ...@@ -26,8 +26,8 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea
other_project = create(:project) other_project = create(:project)
create(:repository_state, :repository_verified, project: project) create(:repository_state, :repository_verified, project: project)
create(:repository_state, :repository_verified, project: other_project) create(:repository_state, :repository_verified, project: other_project)
create(:geo_project_registry, :repository_verification_outdated, project: project) create(:geo_project_registry, :synced, :repository_verification_outdated, project: project)
create(:geo_project_registry, :repository_verification_outdated, project: other_project) create(:geo_project_registry, :synced, :repository_verification_outdated, project: other_project)
expect(secondary_singleworker).to receive(:perform_async).twice expect(secondary_singleworker).to receive(:perform_async).twice
...@@ -36,7 +36,7 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea ...@@ -36,7 +36,7 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea
it 'schedules job for projects missing repository verification' do it 'schedules job for projects missing repository verification' do
create(:repository_state, :repository_verified, :wiki_verified, project: project) create(:repository_state, :repository_verified, :wiki_verified, project: project)
missing_repository_verification = create(:geo_project_registry, :wiki_verified, project: project) missing_repository_verification = create(:geo_project_registry, :synced, :wiki_verified, project: project)
expect(secondary_singleworker).to receive(:perform_async).with(missing_repository_verification.id) expect(secondary_singleworker).to receive(:perform_async).with(missing_repository_verification.id)
...@@ -45,7 +45,7 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea ...@@ -45,7 +45,7 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea
it 'schedules job for projects missing wiki verification' do it 'schedules job for projects missing wiki verification' do
create(:repository_state, :repository_verified, :wiki_verified, project: project) create(:repository_state, :repository_verified, :wiki_verified, project: project)
missing_wiki_verification = create(:geo_project_registry, :repository_verified, project: project) missing_wiki_verification = create(:geo_project_registry, :synced, :repository_verified, project: project)
expect(secondary_singleworker).to receive(:perform_async).with(missing_wiki_verification.id) expect(secondary_singleworker).to receive(:perform_async).with(missing_wiki_verification.id)
...@@ -67,8 +67,8 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea ...@@ -67,8 +67,8 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea
let(:project6_both_verified) { create(:repository_state, :repository_verified, :wiki_verified).project } let(:project6_both_verified) { create(:repository_state, :repository_verified, :wiki_verified).project }
it 'handles multiple batches of projects needing verification' do it 'handles multiple batches of projects needing verification' do
reg1 = create(:geo_project_registry, :repository_verification_outdated, project: project1_repo_verified) reg1 = create(:geo_project_registry, :synced, :repository_verification_outdated, project: project1_repo_verified)
reg2 = create(:geo_project_registry, :repository_verification_outdated, project: project2_repo_verified) reg2 = create(:geo_project_registry, :synced, :repository_verification_outdated, project: project2_repo_verified)
expect(secondary_singleworker).to receive(:perform_async).with(reg1.id).once expect(secondary_singleworker).to receive(:perform_async).with(reg1.id).once
...@@ -82,12 +82,12 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea ...@@ -82,12 +82,12 @@ describe Geo::RepositoryVerification::Secondary::ShardWorker, :postgresql, :clea
end end
it 'handles multiple batches of projects needing verification, skipping failed repos' do it 'handles multiple batches of projects needing verification, skipping failed repos' do
reg1 = create(:geo_project_registry, :repository_verification_outdated, project: project1_repo_verified) reg1 = create(:geo_project_registry, :synced, :repository_verification_outdated, project: project1_repo_verified)
reg2 = create(:geo_project_registry, :repository_verification_outdated, project: project2_repo_verified) reg2 = create(:geo_project_registry, :synced, :repository_verification_outdated, project: project2_repo_verified)
create(:geo_project_registry, :repository_verification_outdated, project: project3_repo_failed) create(:geo_project_registry, :synced, :repository_verification_outdated, project: project3_repo_failed)
reg4 = create(:geo_project_registry, :wiki_verification_outdated, project: project4_wiki_verified) reg4 = create(:geo_project_registry, :synced, :wiki_verification_outdated, project: project4_wiki_verified)
create(:geo_project_registry, :repository_verification_failed, :wiki_verification_failed, project: project5_both_verified) create(:geo_project_registry, :synced, :repository_verification_failed, :wiki_verification_failed, project: project5_both_verified)
reg6 = create(:geo_project_registry, project: project6_both_verified) reg6 = create(:geo_project_registry, :synced, project: project6_both_verified)
expect(secondary_singleworker).to receive(:perform_async).with(reg1.id).once expect(secondary_singleworker).to receive(:perform_async).with(reg1.id).once
......
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