Commit 4833e484 authored by Michael Kozono's avatar Michael Kozono

Merge branch '223249-remove-fdw-related-code-for-projects-and-wikis' into 'master'

Geo - Remove the unused Geo::Fdw::GeoNode#project_registries method

See merge request gitlab-org/gitlab!38206
parents 16da87e1 8eb4f441
...@@ -836,19 +836,19 @@ Geo::JobArtifactRegistry.synced.missing_on_primary.pluck(:artifact_id) ...@@ -836,19 +836,19 @@ Geo::JobArtifactRegistry.synced.missing_on_primary.pluck(:artifact_id)
#### Get the number of verification failed repositories #### Get the number of verification failed repositories
```ruby ```ruby
Geo::ProjectRegistryFinder.new.count_verification_failed_repositories Geo::ProjectRegistry.verification_failed('repository').count
``` ```
#### Find the verification failed repositories #### Find the verification failed repositories
```ruby ```ruby
Geo::ProjectRegistry.verification_failed_repos Geo::ProjectRegistry.verification_failed('repository')
``` ```
### Find repositories that failed to sync ### Find repositories that failed to sync
```ruby ```ruby
Geo::ProjectRegistryFinder.new.find_failed_project_registries('repository') Geo::ProjectRegistry.sync_failed('repository')
``` ```
### Resync repositories ### Resync repositories
......
...@@ -38,18 +38,6 @@ module Geo ...@@ -38,18 +38,6 @@ module Geo
end end
end end
def project_registries
return Geo::ProjectRegistry.all unless selective_sync?
if selective_sync_by_namespaces?
registries_for_selected_namespaces
elsif selective_sync_by_shards?
registries_for_selected_shards
else
Geo::ProjectRegistry.none
end
end
def container_repositories def container_repositories
return Geo::Fdw::ContainerRepository.all unless selective_sync? return Geo::Fdw::ContainerRepository.all unless selective_sync?
...@@ -67,16 +55,6 @@ module Geo ...@@ -67,16 +55,6 @@ module Geo
Geo::Fdw::Project.within_shards(selective_sync_shards) Geo::Fdw::Project.within_shards(selective_sync_shards)
end end
def registries_for_selected_namespaces
Gitlab::Geo::Fdw::ProjectRegistryQueryBuilder.new
.within_namespaces(selected_namespaces_and_descendants.select(:id))
end
def registries_for_selected_shards
Gitlab::Geo::Fdw::ProjectRegistryQueryBuilder.new
.within_shards(selective_sync_shards)
end
def project_model def project_model
Geo::Fdw::Project Geo::Fdw::Project
end end
......
...@@ -39,17 +39,6 @@ module Geo ...@@ -39,17 +39,6 @@ module Geo
end end
class << self class << self
def missing_project_registry
left_outer_join_project_registry
.where(Geo::ProjectRegistry.arel_table[:project_id].eq(nil))
end
def recently_updated
inner_join_project_registry
.merge(Geo::ProjectRegistry.dirty)
.merge(Geo::ProjectRegistry.retry_due)
end
# Searches for a list of projects based on the query given in `query`. # Searches for a list of projects based on the query given in `query`.
# #
# On PostgreSQL this method uses "ILIKE" to perform a case-insensitive # On PostgreSQL this method uses "ILIKE" to perform a case-insensitive
...@@ -76,17 +65,6 @@ module Geo ...@@ -76,17 +65,6 @@ module Geo
joins(join_statement.join_sources) joins(join_statement.join_sources)
end end
private
def left_outer_join_project_registry
join_statement =
arel_table
.join(Geo::ProjectRegistry.arel_table, Arel::Nodes::OuterJoin)
.on(arel_table[:id].eq(Geo::ProjectRegistry.arel_table[:project_id]))
joins(join_statement.join_sources)
end
end end
end end
end end
......
...@@ -174,31 +174,25 @@ class Geo::ProjectRegistry < Geo::BaseRegistry ...@@ -174,31 +174,25 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
end end
def self.repositories_checksummed_pending_verification def self.repositories_checksummed_pending_verification
where(repositories_pending_verification.and(arel_table[:primary_repository_checksummed].eq(true)))
end
def self.wikis_checksummed_pending_verification
where(wikis_pending_verification.and(arel_table[:primary_wiki_checksummed].eq(true)))
end
def self.repositories_pending_verification
repository_exists_on_primary = repository_exists_on_primary =
Arel::Nodes::SqlLiteral.new("project_registry.repository_missing_on_primary IS NOT TRUE") Arel::Nodes::SqlLiteral.new('project_registry.repository_missing_on_primary IS NOT TRUE')
arel_table[:repository_verification_checksum_sha].eq(nil) where(repository_exists_on_primary)
.and(arel_table[:last_repository_verification_failure].eq(nil)) .where(last_repository_verification_failure: nil,
.and(arel_table[:resync_repository].eq(false)) primary_repository_checksummed: true,
.and(repository_exists_on_primary) resync_repository: false,
repository_verification_checksum_sha: nil)
end end
def self.wikis_pending_verification def self.wikis_checksummed_pending_verification
wiki_exists_on_primary = wiki_exists_on_primary =
Arel::Nodes::SqlLiteral.new("project_registry.wiki_missing_on_primary IS NOT TRUE") Arel::Nodes::SqlLiteral.new('project_registry.wiki_missing_on_primary IS NOT TRUE')
arel_table[:wiki_verification_checksum_sha].eq(nil) where(wiki_exists_on_primary)
.and(arel_table[:last_wiki_verification_failure].eq(nil)) .where(last_wiki_verification_failure: nil,
.and(arel_table[:resync_wiki].eq(false)) primary_wiki_checksummed: true,
.and(wiki_exists_on_primary) resync_wiki: false,
wiki_verification_checksum_sha: nil)
end end
def self.flag_repositories_for_resync! def self.flag_repositories_for_resync!
......
# frozen_string_literal: true
module Gitlab
module Geo
class Fdw
class BaseQueryBuilder < SimpleDelegator
def initialize(query = nil)
@query = query || base
super(query)
end
private
attr_reader :query
def base
raise NotImplementedError
end
def reflect(query)
self.class.new(query)
end
end
end
end
end
# frozen_string_literal: true
# Builder class to create composable queries using FDW to
# retrieve project registries.
#
# Basic usage:
#
# Gitlab::Geo::Fdw::ProjectRegistryQueryBuilder
# .new(Geo::ProjectRegistry.all)
# .registries_pending_verification
# .within_shards(selective_sync_shards)
#
module Gitlab
module Geo
class Fdw
class ProjectRegistryQueryBuilder < BaseQueryBuilder
# rubocop:disable CodeReuse/ActiveRecord
def registries_pending_verification
reflect(
query
.joins(fdw_inner_join_projects)
.joins(fdw_inner_join_repository_state)
.where(repositories_pending_verification.or(wikis_pending_verification))
)
end
# rubocop:enable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord
def within_namespaces(namespace_ids)
reflect(
query
.joins(fdw_inner_join_projects)
.merge(projects_within_namespaces(namespace_ids))
)
end
# rubocop:enable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord
def within_shards(shard_names)
reflect(
query
.joins(fdw_inner_join_projects)
.merge(projects_within_shards(shard_names))
)
end
# rubocop:enable CodeReuse/ActiveRecord
private
def base
::Geo::ProjectRegistry.select(project_registries_table[Arel.star])
end
def project_registries_table
::Geo::ProjectRegistry.arel_table
end
def fdw_projects_table
::Geo::Fdw::Project.arel_table
end
def fdw_repository_state_table
::Geo::Fdw::ProjectRepositoryState.arel_table
end
def fdw_inner_join_projects
project_registries_table
.join(fdw_projects_table, Arel::Nodes::InnerJoin)
.on(project_registries_table[:project_id].eq(fdw_projects_table[:id]))
.join_sources
end
def fdw_inner_join_repository_state
project_registries_table
.join(fdw_repository_state_table, Arel::Nodes::InnerJoin)
.on(project_registries_table[:project_id].eq(fdw_repository_state_table[:project_id]))
.join_sources
end
def projects_within_namespaces(namespace_ids)
::Geo::Fdw::Project.within_namespaces(namespace_ids)
end
def projects_within_shards(shard_names)
::Geo::Fdw::Project.within_shards(shard_names)
end
def repositories_pending_verification
::Geo::ProjectRegistry
.repositories_pending_verification
.and(fdw_repository_state_table[:repository_verification_checksum].not_eq(nil))
end
def wikis_pending_verification
::Geo::ProjectRegistry
.wikis_pending_verification
.and(fdw_repository_state_table[:wiki_verification_checksum].not_eq(nil))
end
end
end
end
end
...@@ -42,38 +42,6 @@ RSpec.describe Geo::Fdw::GeoNode, :geo, type: :model do ...@@ -42,38 +42,6 @@ RSpec.describe Geo::Fdw::GeoNode, :geo, type: :model do
end end
end end
# Disable transactions via :delete method because a foreign table
# can't see changes inside a transaction of a different connection.
describe '#project_registries', :geo_fdw do
let!(:registry_1) { create(:geo_project_registry, project: project_1) }
let!(:registry_2) { create(:geo_project_registry, project: project_2) }
let!(:registry_3) { create(:geo_project_registry, project: project_3) }
subject { described_class.find(node.id) }
it 'returns all registries without selective sync' do
expect(subject.project_registries).to match_array([registry_1, registry_2, registry_3])
end
it 'returns registries where projects belong to the namespaces with selective sync by namespace' do
node.update!(selective_sync_type: 'namespaces', namespaces: [group_1])
expect(subject.project_registries).to match_array([registry_1, registry_2])
end
it 'returns registries where projects belong to the shards with selective sync by shard' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: %w[broken])
expect(subject.project_registries).to match_array([registry_3])
end
it 'returns nothing if an unrecognised selective sync type is used' do
node.update_attribute(:selective_sync_type, 'unknown')
expect(subject.project_registries).to be_empty
end
end
describe '#projects_outside_selective_sync', :geo_fdw do describe '#projects_outside_selective_sync', :geo_fdw do
subject { described_class.find(node.id) } subject { described_class.find(node.id) }
......
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