Refactor legacy finder to find verified registries

These changes use the new finder when FDW is enabled without selective
sync to avoid code duplication.
parent cc517e48
# frozen_string_literal: true # frozen_string_literal: true
# Finder for retrieving project registries that have been verified # Finder for retrieving project registries that have been verified
# scoped to a type (repository or wiki) using cross-database joins # scoped to a type (repository or wiki) using cross-database joins.
# for selective sync.
# #
# Basic usage: # Basic usage:
# #
...@@ -22,30 +21,16 @@ module Geo ...@@ -22,30 +21,16 @@ module Geo
end end
def execute def execute
if selective_sync?
verified_registries_for_selective_sync
else
verified_registries
end
end
private
attr_reader :type
def verified_registries
Geo::ProjectRegistry.verified(type)
end
# rubocop: disable CodeReuse/ActiveRecord
def verified_registries_for_selective_sync
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
verified_registries, Geo::ProjectRegistry.verified(type),
current_node.projects.pluck(:id), current_node.projects.pluck_primary_key,
Geo::ProjectRegistry, Geo::ProjectRegistry,
foreign_key: :project_id foreign_key: :project_id
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
private
attr_reader :type
end end
end end
...@@ -196,10 +196,10 @@ module Geo ...@@ -196,10 +196,10 @@ module Geo
end end
def finder_klass_for_verified_registries def finder_klass_for_verified_registries
if Gitlab::Geo::Fdw.enabled_for_selective_sync? if !Gitlab::Geo::Fdw.enabled? || use_legacy_queries_for_selective_sync?
Geo::ProjectRegistryVerifiedFinder
else
Geo::LegacyProjectRegistryVerifiedFinder Geo::LegacyProjectRegistryVerifiedFinder
else
Geo::ProjectRegistryVerifiedFinder
end end
end end
......
...@@ -22,84 +22,68 @@ describe Geo::LegacyProjectRegistryVerifiedFinder, :geo do ...@@ -22,84 +22,68 @@ describe Geo::LegacyProjectRegistryVerifiedFinder, :geo do
let!(:registry_wiki_verification_failed_broken_shard) { create(:geo_project_registry, :repository_verified, :wiki_verification_failed, project: project_4) } let!(:registry_wiki_verification_failed_broken_shard) { create(:geo_project_registry, :repository_verified, :wiki_verification_failed, project: project_4) }
let!(:registry_verification_failed) { create(:geo_project_registry, :repository_verification_failed, :wiki_verification_failed) } let!(:registry_verification_failed) { create(:geo_project_registry, :repository_verification_failed, :wiki_verification_failed) }
shared_examples 'finds verified registries' do before do
context 'with repository type' do stub_fdw_disabled
subject { described_class.new(current_node: node, type: :repository) } end
context 'without selective sync' do
it 'returns all verified registries' do
expect(subject.execute).to contain_exactly(registry_verified, registry_wiki_verification_failed, registry_wiki_verification_failed_broken_shard)
end
end
context 'with selective sync by namespace' do context 'with repository type' do
it 'returns verified registries where projects belongs to the namespaces' do subject { described_class.new(current_node: node, type: :repository) }
node.update!(selective_sync_type: 'namespaces', namespaces: [group_1, nested_group_1])
expect(subject.execute).to contain_exactly(registry_verified, registry_wiki_verification_failed) context 'without selective sync' do
end it 'returns all verified registries' do
expect(subject.execute).to contain_exactly(registry_verified, registry_wiki_verification_failed, registry_wiki_verification_failed_broken_shard)
end end
end
context 'with selective sync by shard' do context 'with selective sync by namespace' do
it 'returns verified registries where projects belongs to the shards' do it 'returns verified registries where projects belongs to the namespaces' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken']) node.update!(selective_sync_type: 'namespaces', namespaces: [group_1, nested_group_1])
expect(subject.execute).to contain_exactly(registry_wiki_verification_failed_broken_shard) expect(subject.execute).to contain_exactly(registry_verified, registry_wiki_verification_failed)
end
end end
end end
context 'with wiki type' do context 'with selective sync by shard' do
subject { described_class.new(current_node: node, type: :wiki) } it 'returns verified registries where projects belongs to the shards' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
context 'without selective sync' do expect(subject.execute).to contain_exactly(registry_wiki_verification_failed_broken_shard)
it 'returns all verified registries' do
expect(subject.execute).to contain_exactly(registry_verified, registry_repository_verification_failed, registry_repository_verification_failed_broken_shard)
end
end end
end
end
context 'with selective sync by namespace' do context 'with wiki type' do
it 'returns verified registries where projects belongs to the namespaces' do subject { described_class.new(current_node: node, type: :wiki) }
node.update!(selective_sync_type: 'namespaces', namespaces: [group_1, nested_group_1])
expect(subject.execute).to contain_exactly(registry_verified, registry_repository_verification_failed) context 'without selective sync' do
end it 'returns all verified registries' do
expect(subject.execute).to contain_exactly(registry_verified, registry_repository_verification_failed, registry_repository_verification_failed_broken_shard)
end end
end
context 'with selective sync by shard' do context 'with selective sync by namespace' do
it 'returns verified registries where projects belongs to the shards' do it 'returns verified registries where projects belongs to the namespaces' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken']) node.update!(selective_sync_type: 'namespaces', namespaces: [group_1, nested_group_1])
expect(subject.execute).to contain_exactly(registry_repository_verification_failed_broken_shard) expect(subject.execute).to contain_exactly(registry_verified, registry_repository_verification_failed)
end
end end
end end
context 'with invalid type' do context 'with selective sync by shard' do
subject { described_class.new(current_node: node, type: :invalid) } it 'returns verified registries where projects belongs to the shards' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
it 'returns nothing' do expect(subject.execute).to contain_exactly(registry_repository_verification_failed_broken_shard)
expect(subject.execute).to be_empty
end end
end end
end end
# Disable transactions via :delete method because a foreign table context 'with invalid type' do
# can't see changes inside a transaction of a different connection. subject { described_class.new(current_node: node, type: :invalid) }
context 'FDW', :delete do
before do
skip('FDW is not configured') unless Gitlab::Geo::Fdw.enabled?
end
include_examples 'finds verified registries' it 'returns nothing' do
end expect(subject.execute).to be_empty
context 'Legacy' do
before do
stub_fdw_disabled
end end
include_examples 'finds verified registries'
end end
end end
end end
...@@ -148,22 +148,72 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -148,22 +148,72 @@ describe Geo::ProjectRegistryFinder, :geo do
end end
describe '#count_verified_repositories' do describe '#count_verified_repositories' do
it 'counts projects that verified' do before do
create(:geo_project_registry, :repository_verified, project: project_repository_verified) project_1_in_synced_group = create(:project, group: synced_group)
create(:geo_project_registry, :repository_verified, project: build(:project)) project_2_in_synced_group = create(:project, group: synced_group)
create(:geo_project_registry, :repository_verification_failed, project: project_repository_verification_failed) project_3_in_synced_group = create(:project, group: synced_group)
project_4_broken_storage = create(:project, :broken_storage)
create(:geo_project_registry, :repository_verified, :wiki_verified, project: project_synced)
create(:geo_project_registry, :repository_verified, project: project_1_in_synced_group)
create(:geo_project_registry, :repository_verification_failed, project: project_3_in_synced_group)
create(:geo_project_registry, :repository_verified, project: project_4_broken_storage)
create(:geo_project_registry, :wiki_verified, project: project_2_in_synced_group)
end
it 'counts registries that repository have beend verified' do
expect(subject.count_verified_repositories).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that repository have beend verified where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_verified_repositories).to eq 1
end
end
expect(subject.count_verified_repositories).to eq 2 context 'with selective sync by shard' do
it 'counts registries that repository have beend verified where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_verified_repositories).to eq 1
end
end end
end end
describe '#count_verified_wikis' do describe '#count_verified_wikis' do
it 'counts wikis that verified' do before do
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified) project_1_in_synced_group = create(:project, group: synced_group)
create(:geo_project_registry, :wiki_verified, project: build(:project)) project_2_in_synced_group = create(:project, group: synced_group)
create(:geo_project_registry, :wiki_verification_failed, project: project_wiki_verification_failed) project_3_in_synced_group = create(:project, group: synced_group)
project_4_broken_storage = create(:project, :broken_storage)
create(:geo_project_registry, :wiki_verified, :wiki_verified, project: project_synced)
create(:geo_project_registry, :wiki_verified, project: project_1_in_synced_group)
create(:geo_project_registry, :wiki_verification_failed, project: project_3_in_synced_group)
create(:geo_project_registry, :wiki_verified, project: project_4_broken_storage)
create(:geo_project_registry, :repository_verified, project: project_2_in_synced_group)
end
it 'counts registries that wiki have beend verified' do
expect(subject.count_verified_wikis).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that wiki have beend verified where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_verified_wikis).to eq 1
end
end
expect(subject.count_verified_wikis).to eq 2 context 'with selective sync by shard' do
it 'counts registries that wiki have beend verified where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_verified_wikis).to eq 1
end
end end
end end
......
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