Commit 43b4ff34 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre Committed by Ash McKenzie

Remove legacy finder for projects registries that checksum mismatch

This commit removes the legacy queries for project registries that
checksum mismatch since we made Foreign Data Wrapper (FDW) a hard
requirement for Geo on GitLab 12.0.
parent f1bd092d
# frozen_string_literal: true
# Finder for retrieving project registries that checksum mismatch
# scoped to a type (repository or wiki) using cross-database joins
# for selective sync.
#
# Basic usage:
#
# Geo::LegacyProjectRegistryMismatchFinder.new(current_node: Gitlab::Geo.current_node, :repository).execute
#
# Valid `type` values are:
#
# * `:repository`
# * `:wiki`
#
# Any other value will be ignored.
module Geo
class LegacyProjectRegistryMismatchFinder < RegistryFinder
def initialize(current_node: nil, type:)
super(current_node: current_node)
@type = type.to_s.to_sym
end
def execute
legacy_inner_join_registry_ids(
Geo::ProjectRegistry.mismatch(type),
current_node.projects.pluck_primary_key,
Geo::ProjectRegistry,
foreign_key: :project_id
)
end
private
attr_reader :type
end
end
......@@ -140,16 +140,8 @@ module Geo
.execute
end
def finder_klass_for_mismatch_registries
if use_legacy_queries_for_selective_sync?
Geo::LegacyProjectRegistryMismatchFinder
else
Geo::ProjectRegistryMismatchFinder
end
end
def registries_for_mismatch_projects(type)
finder_klass_for_mismatch_registries
Geo::ProjectRegistryMismatchFinder
.new(current_node: current_node, type: type)
.execute
end
......
# frozen_string_literal: true
require 'spec_helper'
describe Geo::LegacyProjectRegistryMismatchFinder, :geo do
describe '#execute' do
let(:node) { create(:geo_node) }
let(:group_1) { create(:group) }
let(:group_2) { create(:group) }
let(:nested_group_1) { create(:group, parent: group_1) }
let(:project_1) { create(:project, group: group_1) }
let(:project_2) { create(:project, group: nested_group_1) }
let(:project_3) { create(:project, group: nested_group_1) }
let(:project_4) { create(:project, :broken_storage, group: group_2) }
let(:project_5) { create(:project, :broken_storage, group: group_2) }
let!(:registry_mismatch) { create(:geo_project_registry, :repository_checksum_mismatch, :wiki_checksum_mismatch, project: project_1) }
let!(:registry_repository_mismatch) { create(:geo_project_registry, :repository_checksum_mismatch, :wiki_verified, project: project_2) }
let!(:registry_wiki_mismatch) { create(:geo_project_registry, :repository_verified, :wiki_checksum_mismatch, project: project_3) }
let!(:registry_wiki_mismatch_broken_shard) { create(:geo_project_registry, :repository_verified, :wiki_checksum_mismatch, project: project_4) }
let!(:registry_repository_mismatch_broken_shard) { create(:geo_project_registry, :repository_checksum_mismatch, :wiki_verified, project: project_5) }
let!(:registry_verified) { create(:geo_project_registry, :repository_verified, :wiki_verified) }
context 'with repository type' do
subject { described_class.new(current_node: node, type: :repository) }
context 'without selective sync' do
it 'returns all mismatch registries' do
expect(subject.execute).to contain_exactly(registry_mismatch, registry_repository_mismatch, registry_repository_mismatch_broken_shard)
end
end
context 'with selective sync by namespace' do
it 'returns mismatch registries where projects belongs to the namespaces' do
node.update!(selective_sync_type: 'namespaces', namespaces: [group_1])
expect(subject.execute).to contain_exactly(registry_mismatch, registry_repository_mismatch)
end
end
context 'with selective sync by shard' do
it 'returns mismatch registries where projects belongs to the shards' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.execute).to contain_exactly(registry_repository_mismatch_broken_shard)
end
end
end
context 'with wiki type' do
subject { described_class.new(current_node: node, type: :wiki) }
context 'without selective sync' do
it 'returns all mismatch registries' do
expect(subject.execute).to contain_exactly(registry_mismatch, registry_wiki_mismatch, registry_wiki_mismatch_broken_shard)
end
end
context 'with selective sync by namespace' do
it 'returns mismatch registries where projects belongs to the namespaces' do
node.update!(selective_sync_type: 'namespaces', namespaces: [group_1])
expect(subject.execute).to contain_exactly(registry_mismatch, registry_wiki_mismatch)
end
end
context 'with selective sync by shard' do
it 'returns mismatch registries where projects belongs to the shards' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.execute).to contain_exactly(registry_wiki_mismatch_broken_shard)
end
end
end
context 'with invalid type' do
subject { described_class.new(current_node: node, type: :invalid) }
context 'without selective sync' do
it 'returns all mismatch registries' do
expect(subject.execute).to contain_exactly(registry_mismatch, registry_repository_mismatch, registry_wiki_mismatch, registry_repository_mismatch_broken_shard, registry_wiki_mismatch_broken_shard)
end
end
context 'with selective sync by namespace' do
it 'returns all mismatch registries where projects belongs to the namespaces' do
node.update!(selective_sync_type: 'namespaces', namespaces: [group_1])
expect(subject.execute).to contain_exactly(registry_mismatch, registry_repository_mismatch, registry_wiki_mismatch)
end
end
context 'with selective sync by shard' do
it 'returns all mismatch registries where projects belongs to the shards' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.execute).to contain_exactly(registry_repository_mismatch_broken_shard, registry_wiki_mismatch_broken_shard)
end
end
end
end
end
......@@ -489,64 +489,6 @@ describe Geo::ProjectRegistryFinder, :geo do
end
end
end
describe '#count_repositories_checksum_mismatch' do
before do
create(:geo_project_registry, :repository_checksum_mismatch, :wiki_checksum_mismatch, project: project)
create(:geo_project_registry, :repository_checksum_mismatch, project: project_1_in_synced_group)
create(:geo_project_registry, :repository_checksum_mismatch, :wiki_verified, project: project_4_broken_storage)
create(:geo_project_registry, :wiki_checksum_mismatch, project: project_2_in_synced_group)
end
it 'counts registries that repository mismatch' do
expect(subject.count_repositories_checksum_mismatch).to eq 3
end
context 'with selective sync by namespace' do
it 'counts mismatch registries where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_repositories_checksum_mismatch).to eq 1
end
end
context 'with selective sync by shard' do
it 'counts mismatch registries where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_repositories_checksum_mismatch).to eq 1
end
end
end
describe '#count_wikis_checksum_mismatch' do
before do
create(:geo_project_registry, :repository_checksum_mismatch, :wiki_checksum_mismatch, project: project)
create(:geo_project_registry, :repository_checksum_mismatch, project: project_1_in_synced_group)
create(:geo_project_registry, :wiki_checksum_mismatch, project: project_2_in_synced_group)
create(:geo_project_registry, :repository_verified, :wiki_checksum_mismatch, project: project_4_broken_storage)
end
it 'counts registries that wiki mismatch' do
expect(subject.count_wikis_checksum_mismatch).to eq 3
end
context 'with selective sync by namespace' do
it 'counts mismatch registries where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_wikis_checksum_mismatch).to eq 1
end
end
context 'with selective sync by shard' do
it 'counts mismatch registries where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_wikis_checksum_mismatch).to eq 1
end
end
end
end
describe '#find_unsynced_projects', :geo_fdw do
......@@ -591,9 +533,12 @@ describe Geo::ProjectRegistryFinder, :geo do
end
describe '#find_checksum_mismatch_project_registries', :geo_fdw do
include_examples 'delegates to the proper finder',
Geo::LegacyProjectRegistryMismatchFinder,
Geo::ProjectRegistryMismatchFinder,
:find_checksum_mismatch_project_registries, ['repository']
it 'delegates to the proper finder' do
expect_next_instance_of(Geo::ProjectRegistryMismatchFinder) do |finder|
expect(finder).to receive(:execute).once
end
subject.find_checksum_mismatch_project_registries('repository')
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