Refactor legacy finder to find registries where sync has failed

These changes use the new finder when FDW is enabled without selective
sync to avoid code duplication.
parent 784760b1
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Finder for retrieving project registries that synchronization have # Finder for retrieving project registries that synchronization have
# failed scoped to a type (repository or wiki) using cross-database # failed scoped to a type (repository or wiki) using cross-database
# joins for selective sync. # joins.
# #
# Basic usage: # Basic usage:
# #
...@@ -22,30 +22,16 @@ module Geo ...@@ -22,30 +22,16 @@ module Geo
end end
def execute def execute
if selective_sync?
failed_registries_for_selective_sync
else
failed_registries
end
end
private
attr_reader :type
def failed_registries
Geo::ProjectRegistry.sync_failed(type)
end
# rubocop: disable CodeReuse/ActiveRecord
def failed_registries_for_selective_sync
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
failed_registries, Geo::ProjectRegistry.sync_failed(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
...@@ -182,10 +182,10 @@ module Geo ...@@ -182,10 +182,10 @@ module Geo
end end
def finder_klass_for_failed_registries def finder_klass_for_failed_registries
if Gitlab::Geo::Fdw.enabled_for_selective_sync? if !Gitlab::Geo::Fdw.enabled? || use_legacy_queries_for_selective_sync?
Geo::ProjectRegistrySyncFailedFinder
else
Geo::LegacyProjectRegistrySyncFailedFinder Geo::LegacyProjectRegistrySyncFailedFinder
else
Geo::ProjectRegistrySyncFailedFinder
end end
end end
......
...@@ -22,102 +22,86 @@ describe Geo::LegacyProjectRegistrySyncFailedFinder, :geo do ...@@ -22,102 +22,86 @@ describe Geo::LegacyProjectRegistrySyncFailedFinder, :geo do
let!(:registry_repository_failed_broken_shard) { create(:geo_project_registry, :synced, :repository_sync_failed, project: project_5) } let!(:registry_repository_failed_broken_shard) { create(:geo_project_registry, :synced, :repository_sync_failed, project: project_5) }
let!(:registry_synced) { create(:geo_project_registry, :synced) } let!(:registry_synced) { create(:geo_project_registry, :synced) }
shared_examples 'finds failed 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 failed registries' do
expect(subject.execute).to match_array([registry_failed, registry_repository_failed, registry_repository_failed_broken_shard])
end
end
context 'with selective sync by namespace' do context 'with repository type' do
it 'returns failed 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 match_array([registry_failed, registry_repository_failed]) context 'without selective sync' do
end it 'returns all failed registries' do
expect(subject.execute).to match_array([registry_failed, registry_repository_failed, registry_repository_failed_broken_shard])
end end
end
context 'with selective sync by shard' do context 'with selective sync by namespace' do
it 'returns failed registries where projects belongs to the shards' do it 'returns failed 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 match_array([registry_repository_failed_broken_shard]) expect(subject.execute).to match_array([registry_failed, registry_repository_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 failed 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 match_array([registry_repository_failed_broken_shard])
it 'returns all failed registries' do
expect(subject.execute).to match_array([registry_failed, registry_wiki_failed, registry_wiki_failed_broken_shard])
end
end end
end
end
context 'with selective sync by namespace' do context 'with wiki type' do
it 'returns failed 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 match_array([registry_failed, registry_wiki_failed]) context 'without selective sync' do
end it 'returns all failed registries' do
expect(subject.execute).to match_array([registry_failed, registry_wiki_failed, registry_wiki_failed_broken_shard])
end end
end
context 'with selective sync by shard' do context 'with selective sync by namespace' do
it 'returns failed registries where projects belongs to the shards' do it 'returns failed 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 match_array([registry_wiki_failed_broken_shard]) expect(subject.execute).to match_array([registry_failed, registry_wiki_failed])
end
end end
end end
context 'with no type' do context 'with selective sync by shard' do
subject { described_class.new(current_node: node, type: :invalid) } it 'returns failed 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 match_array([registry_wiki_failed_broken_shard])
it 'returns all failed registries' do
expect(subject.execute).to match_array([registry_failed, registry_repository_failed, registry_wiki_failed, registry_repository_failed_broken_shard, registry_wiki_failed_broken_shard])
end
end end
end
end
context 'with selective sync by namespace' do context 'with no type' do
it 'returns all failed registries where projects belongs to the namespaces' do subject { described_class.new(current_node: node, type: :invalid) }
node.update!(selective_sync_type: 'namespaces', namespaces: [group_1, nested_group_1])
expect(subject.execute).to match_array([registry_failed, registry_repository_failed, registry_wiki_failed]) context 'without selective sync' do
end it 'returns all failed registries' do
expect(subject.execute).to match_array([registry_failed, registry_repository_failed, registry_wiki_failed, registry_repository_failed_broken_shard, registry_wiki_failed_broken_shard])
end end
end
context 'with selective sync by shard' do context 'with selective sync by namespace' do
it 'returns all failed registries where projects belongs to the shards' do it 'returns all failed 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 match_array([registry_repository_failed_broken_shard, registry_wiki_failed_broken_shard]) expect(subject.execute).to match_array([registry_failed, registry_repository_failed, registry_wiki_failed])
end
end end
end end
end
# Disable transactions via :delete method because a foreign table context 'with selective sync by shard' do
# can't see changes inside a transaction of a different connection. it 'returns all failed registries where projects belongs to the shards' do
context 'FDW', :delete do node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
before do
skip('FDW is not configured') unless Gitlab::Geo::Fdw.enabled?
end
include_examples 'finds failed registries' expect(subject.execute).to match_array([registry_repository_failed_broken_shard, registry_wiki_failed_broken_shard])
end end
context 'Legacy' do
before do
stub_fdw_disabled
end end
include_examples 'finds failed registries'
end 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