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