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,7 +22,10 @@ describe Geo::LegacyProjectRegistryVerifiedFinder, :geo do ...@@ -22,7 +22,10 @@ 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
stub_fdw_disabled
end
context 'with repository type' do context 'with repository type' do
subject { described_class.new(current_node: node, type: :repository) } subject { described_class.new(current_node: node, type: :repository) }
...@@ -83,23 +86,4 @@ describe Geo::LegacyProjectRegistryVerifiedFinder, :geo do ...@@ -83,23 +86,4 @@ describe Geo::LegacyProjectRegistryVerifiedFinder, :geo do
end end
end 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
include_examples 'finds verified registries'
end
context 'Legacy' do
before do
stub_fdw_disabled
end
include_examples 'finds verified registries'
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
expect(subject.count_verified_repositories).to eq 2 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
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
expect(subject.count_verified_wikis).to eq 2 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
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