Commit b31cee4e authored by Michael Kozono's avatar Michael Kozono

Merge branch '223104-geo-refactor-finders' into 'master'

Geo - Refactor finders (Part I)

See merge request gitlab-org/gitlab!40313
parents 67bf6822 3c629e4e
......@@ -31,7 +31,7 @@ module Geo
.map! { |id, uploader| [id, uploader.sub(/Uploader\z/, '').underscore] }
tracked =
syncable
registry_class
.model_id_in(range)
.pluck(:file_id, :file_type)
# rubocop:enable CodeReuse/ActiveRecord
......@@ -46,7 +46,7 @@ module Geo
::Upload.replicables_for_geo_node
end
def syncable
def registry_class
Geo::UploadRegistry
end
end
......
......@@ -2,32 +2,6 @@
module Geo
class ContainerRepositoryRegistryFinder < RegistryFinder
def count_syncable
container_repositories.count
end
def count_synced
Geo::ContainerRepositoryRegistry.synced.count
end
def count_failed
Geo::ContainerRepositoryRegistry.failed.count
end
def count_registry
Geo::ContainerRepositoryRegistry.count
end
def find_registry_differences(range)
source_ids = container_repositories.id_in(range).pluck_primary_key
tracked_ids = Geo::ContainerRepositoryRegistry.pluck_model_ids_in_range(range)
untracked_ids = source_ids - tracked_ids
unused_tracked_ids = tracked_ids - source_ids
[untracked_ids, unused_tracked_ids]
end
# Returns Geo::ContainerRepositoryRegistry records that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
......@@ -46,7 +20,7 @@ module Geo
# @param [Array<Integer>] except_ids ids that will be ignored from the query
# rubocop:disable CodeReuse/ActiveRecord
def find_never_synced_registries(batch_size:, except_ids: [])
Geo::ContainerRepositoryRegistry
registry_class
.never_synced
.model_id_not_in(except_ids)
.limit(batch_size)
......@@ -55,7 +29,7 @@ module Geo
# rubocop:disable CodeReuse/ActiveRecord
def find_retryable_dirty_registries(batch_size:, except_ids: [])
Geo::ContainerRepositoryRegistry
registry_class
.failed
.retry_due
.model_id_not_in(except_ids)
......@@ -66,8 +40,12 @@ module Geo
private
def container_repositories
def replicables
current_node.container_repositories
end
def registry_class
Geo::ContainerRepositoryRegistry
end
end
end
......@@ -2,32 +2,6 @@
module Geo
class DesignRegistryFinder < RegistryFinder
def count_syncable
designs.count
end
def count_synced
registries.synced.count
end
def count_failed
registries.failed.count
end
def count_registry
registries.count
end
def find_registry_differences(range)
source_ids = designs.id_in(range).pluck_primary_key
tracked_ids = registries.pluck_model_ids_in_range(range)
untracked_ids = source_ids - tracked_ids
unused_tracked_ids = tracked_ids - source_ids
[untracked_ids, unused_tracked_ids]
end
# Returns Geo::DesignRegistry records that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
......@@ -46,7 +20,7 @@ module Geo
# @param [Array<Integer>] except_ids ids that will be ignored from the query
# rubocop:disable CodeReuse/ActiveRecord
def find_never_synced_registries(batch_size:, except_ids: [])
registries
registry_class
.never_synced
.model_id_not_in(except_ids)
.limit(batch_size)
......@@ -55,7 +29,7 @@ module Geo
# rubocop:disable CodeReuse/ActiveRecord
def find_retryable_dirty_registries(batch_size:, except_ids: [])
registries
registry_class
.updated_recently
.model_id_not_in(except_ids)
.order(Gitlab::Database.nulls_first_order(:last_synced_at))
......@@ -65,11 +39,11 @@ module Geo
private
def designs
def replicables
current_node.designs
end
def registries
def registry_class
Geo::DesignRegistry
end
end
......
......@@ -2,65 +2,11 @@
module Geo
class FileRegistryFinder < RegistryFinder
# @!method count_syncable
# Return a count of the registry records for the tracked file_type(s)
def count_syncable
syncable.count
end
# @!method count_synced
# Return a count of the registry records for the tracked file_type(s)
# that are synced
def count_synced
syncable.synced.count
end
# @!method count_failed
# Return a count of the registry records for the tracked file_type(s)
# that are sync failed
def count_failed
syncable.failed.count
end
# @!method count_synced_missing_on_primary
# Return a count of the registry records for the tracked file_type(s)
# that are synced and missing on the primary
def count_synced_missing_on_primary
syncable.synced.missing_on_primary.count
end
# @!method count_registry
# Return a count of the registry records for the tracked file_type(s)
def count_registry
syncable.count
end
# @!method find_registry_differences
# Returns untracked IDs as well as tracked IDs that are unused.
#
# Untracked IDs are model IDs that are supposed to be synced but don't yet
# have a registry entry.
#
# Unused tracked IDs are model IDs that are not supposed to be synced but
# already have a registry entry. For example:
#
# - orphaned registries
# - records that became excluded from selective sync
# - records that are in object storage, and `sync_object_storage` became
# disabled
#
# We compute both sets in this method to reduce the number of DB queries
# performed.
#
# @return [Array] the first element is an Array of untracked IDs, and the second element is an Array of tracked IDs that are unused
def find_registry_differences(range)
source_ids = replicables.id_in(range).pluck(replicable_primary_key) # rubocop:disable CodeReuse/ActiveRecord
tracked_ids = syncable.pluck_model_ids_in_range(range)
untracked_ids = source_ids - tracked_ids
unused_tracked_ids = tracked_ids - source_ids
[untracked_ids, unused_tracked_ids]
registry_class.synced.missing_on_primary.count
end
# @!method find_never_synced_registries
......@@ -84,7 +30,7 @@ module Geo
#
# rubocop:disable CodeReuse/ActiveRecord
def find_never_synced_registries(batch_size:, except_ids: [])
syncable
registry_class
.never
.model_id_not_in(except_ids)
.limit(batch_size)
......@@ -101,7 +47,7 @@ module Geo
#
# rubocop:disable CodeReuse/ActiveRecord
def find_retryable_failed_registries(batch_size:, except_ids: [])
syncable
registry_class
.failed
.retry_due
.model_id_not_in(except_ids)
......@@ -119,7 +65,7 @@ module Geo
#
# rubocop:disable CodeReuse/ActiveRecord
def find_retryable_synced_missing_on_primary_registries(batch_size:, except_ids: [])
syncable
registry_class
.synced
.missing_on_primary
.retry_due
......@@ -128,28 +74,6 @@ module Geo
end
# rubocop:enable CodeReuse/ActiveRecord
# @!method syncable
# Return an ActiveRecord::Base class for the tracked file_type(s)
def syncable
raise NotImplementedError,
"#{self.class} does not implement #{__method__}"
end
# @!method replicables
# Return an ActiveRecord::Relation of the replicable records for the
# tracked file_type(s)
def replicables
raise NotImplementedError,
"#{self.class} does not implement #{__method__}"
end
# @!method syncable
# Return the fully qualified name of the replicable primary key for the
# tracked file_type(s)
def replicable_primary_key
syncable::MODEL_CLASS.arel_table[:id]
end
def local_storage_only?
!current_node&.sync_object_storage
end
......
......@@ -6,7 +6,7 @@ module Geo
::Ci::JobArtifact.replicables_for_geo_node
end
def syncable
def registry_class
Geo::JobArtifactRegistry
end
end
......
......@@ -6,7 +6,7 @@ module Geo
local_storage_only? ? lfs_objects.with_files_stored_locally : lfs_objects
end
def syncable
def registry_class
Geo::LfsObjectRegistry
end
......
......@@ -10,6 +10,69 @@ module Geo
@current_node_id = current_node_id
end
# @!method find_registry_differences
# Returns untracked IDs as well as tracked IDs that are unused.
#
# Untracked IDs are model IDs that are supposed to be synced but don't yet
# have a registry entry.
#
# Unused tracked IDs are model IDs that are not supposed to be synced but
# already have a registry entry. For example:
#
# - orphaned registries
# - records that became excluded from selective sync
# - records that are in object storage, and `sync_object_storage` became
# disabled
#
# We compute both sets in this method to reduce the number of DB queries
# performed.
#
# @return [Array] the first element is an Array of untracked IDs, and the second element is an Array of tracked IDs that are unused
def find_registry_differences(range)
source_ids = replicables.id_in(range).pluck(replicable_primary_key) # rubocop:disable CodeReuse/ActiveRecord
tracked_ids = registry_class.pluck_model_ids_in_range(range)
untracked_ids = source_ids - tracked_ids
unused_tracked_ids = tracked_ids - source_ids
[untracked_ids, unused_tracked_ids]
end
# @!method registry_class
# Return an ActiveRecord::Base class for the tracked type
def registry_class
raise NotImplementedError,
"#{self.class} does not implement #{__method__}"
end
# @!method replicables
# Return an ActiveRecord::Relation of the replicable records for the
# tracked file_type(s)
def replicables
raise NotImplementedError,
"#{self.class} does not implement #{__method__}"
end
# @!method registry_count
# Return a count of the registry records for the tracked type(s)
def registry_count
registry_class.count
end
# @!method synced_count
# Return a count of the registry records for the tracked type
# that are synced
def synced_count
registry_class.synced.count
end
# @!method failed_count
# Return a count of the registry records for the tracked type
# that are sync failed
def failed_count
registry_class.failed.count
end
private
def current_node
......@@ -17,5 +80,12 @@ module Geo
GeoNode.find(current_node_id) if current_node_id
end
end
# @!method registry_class
# Return the fully qualified name of the replicable primary key for the
# tracked file_type(s)
def replicable_primary_key
registry_class::MODEL_CLASS.arel_table[:id]
end
end
end
......@@ -296,9 +296,6 @@ class GeoNodeStatus < ApplicationRecord
self.version = Gitlab::VERSION
self.revision = Gitlab.revision
self.projects_count = geo_node.projects.count
self.package_files_count = Geo::PackageFileReplicator.primary_total_count
load_status_message
load_event_data
load_primary_data
......@@ -424,10 +421,8 @@ class GeoNodeStatus < ApplicationRecord
def load_primary_data
return unless Gitlab::Geo.primary?
self.lfs_objects_count = LfsObject.count
self.job_artifacts_count = Ci::JobArtifact.not_expired.count
self.attachments_count = Upload.count
self.projects_count = geo_node.projects.count
self.package_files_count = Geo::PackageFileReplicator.primary_total_count
self.replication_slots_count = geo_node.replication_slots_count
self.replication_slots_used_count = geo_node.replication_slots_used_count
self.replication_slots_max_retained_wal_bytes = geo_node.replication_slots_max_retained_wal_bytes
......@@ -450,6 +445,7 @@ class GeoNodeStatus < ApplicationRecord
end
def load_repositories_data
self.projects_count = Geo::ProjectRegistry.count
self.repositories_synced_count = Geo::ProjectRegistry.synced(:repository).count
self.repositories_failed_count = Geo::ProjectRegistry.sync_failed(:repository).count
self.wikis_synced_count = Geo::ProjectRegistry.synced(:wiki).count
......@@ -459,54 +455,55 @@ class GeoNodeStatus < ApplicationRecord
def load_lfs_objects_data
return unless lfs_objects_replication_enabled
self.lfs_objects_count = lfs_objects_finder.count_syncable
self.lfs_objects_synced_count = lfs_objects_finder.count_synced
self.lfs_objects_failed_count = lfs_objects_finder.count_failed
self.lfs_objects_registry_count = lfs_objects_finder.count_registry
self.lfs_objects_count = lfs_objects_finder.registry_count
self.lfs_objects_synced_count = lfs_objects_finder.synced_count
self.lfs_objects_failed_count = lfs_objects_finder.failed_count
self.lfs_objects_registry_count = lfs_objects_finder.registry_count
self.lfs_objects_synced_missing_on_primary_count = lfs_objects_finder.count_synced_missing_on_primary
end
def load_job_artifacts_data
return unless job_artifacts_replication_enabled
self.job_artifacts_count = job_artifacts_finder.count_syncable
self.job_artifacts_synced_count = job_artifacts_finder.count_synced
self.job_artifacts_failed_count = job_artifacts_finder.count_failed
self.job_artifacts_registry_count = job_artifacts_finder.count_registry
self.job_artifacts_count = job_artifacts_finder.registry_count
self.job_artifacts_synced_count = job_artifacts_finder.synced_count
self.job_artifacts_failed_count = job_artifacts_finder.failed_count
self.job_artifacts_registry_count = job_artifacts_finder.registry_count
self.job_artifacts_synced_missing_on_primary_count = job_artifacts_finder.count_synced_missing_on_primary
end
def load_attachments_data
return unless attachments_replication_enabled
self.attachments_count = attachments_finder.count_syncable
self.attachments_synced_count = attachments_finder.count_synced
self.attachments_failed_count = attachments_finder.count_failed
self.attachments_registry_count = attachments_finder.count_registry
self.attachments_count = attachments_finder.registry_count
self.attachments_synced_count = attachments_finder.synced_count
self.attachments_failed_count = attachments_finder.failed_count
self.attachments_registry_count = attachments_finder.registry_count
self.attachments_synced_missing_on_primary_count = attachments_finder.count_synced_missing_on_primary
end
def load_container_registry_data
return unless container_repositories_replication_enabled
self.container_repositories_count = container_registry_finder.count_syncable
self.container_repositories_synced_count = container_registry_finder.count_synced
self.container_repositories_failed_count = container_registry_finder.count_failed
self.container_repositories_registry_count = container_registry_finder.count_registry
self.container_repositories_count = container_registry_finder.registry_count
self.container_repositories_synced_count = container_registry_finder.synced_count
self.container_repositories_failed_count = container_registry_finder.failed_count
self.container_repositories_registry_count = container_registry_finder.registry_count
end
def load_designs_data
return unless design_repositories_replication_enabled
self.design_repositories_count = design_registry_finder.count_syncable
self.design_repositories_synced_count = design_registry_finder.count_synced
self.design_repositories_failed_count = design_registry_finder.count_failed
self.design_repositories_registry_count = design_registry_finder.count_registry
self.design_repositories_count = design_registry_finder.registry_count
self.design_repositories_synced_count = design_registry_finder.synced_count
self.design_repositories_failed_count = design_registry_finder.failed_count
self.design_repositories_registry_count = design_registry_finder.registry_count
end
def load_package_files_data
# return unless package_files_replication_enabled # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/221069
self.package_files_count = Geo::PackageFileReplicator.registry_count
self.package_files_registry_count = Geo::PackageFileReplicator.registry_count
self.package_files_synced_count = Geo::PackageFileReplicator.synced_count
self.package_files_failed_count = Geo::PackageFileReplicator.failed_count
......
......@@ -30,7 +30,7 @@ RSpec.describe Geo::AttachmentRegistryFinder, :geo do
subject { described_class.new(current_node_id: secondary.id) }
describe '#count_syncable' do
describe '#registry_count' do
it 'counts registries for uploads' do
create(:geo_upload_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_upload_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
......@@ -41,26 +41,11 @@ RSpec.describe Geo::AttachmentRegistryFinder, :geo do
create(:geo_upload_registry, :attachment, file_id: upload_7.id, missing_on_primary: true)
create(:geo_upload_registry, :attachment, :never_synced, file_id: upload_8.id)
expect(subject.count_syncable).to eq 8
expect(subject.registry_count).to eq 8
end
end
describe '#count_registry' do
it 'counts registries for uploads' do
create(:geo_upload_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_upload_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
create(:geo_upload_registry, :attachment, :never_synced, file_id: upload_3.id)
create(:geo_upload_registry, :attachment, :failed, file_id: upload_4.id)
create(:geo_upload_registry, :attachment, file_id: upload_5.id, missing_on_primary: true, retry_at: 1.day.ago)
create(:geo_upload_registry, :attachment, :failed, file_id: upload_6.id)
create(:geo_upload_registry, :attachment, file_id: upload_7.id, missing_on_primary: true)
create(:geo_upload_registry, :attachment, :never_synced, file_id: upload_8.id)
expect(subject.count_registry).to eq 8
end
end
describe '#count_synced' do
describe '#synced_count' do
it 'counts registries that has been synced' do
create(:geo_upload_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_upload_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
......@@ -71,11 +56,11 @@ RSpec.describe Geo::AttachmentRegistryFinder, :geo do
create(:geo_upload_registry, :attachment, file_id: upload_7.id, missing_on_primary: true)
create(:geo_upload_registry, :attachment, :never_synced, file_id: upload_8.id)
expect(subject.count_synced).to eq 3
expect(subject.synced_count).to eq 3
end
end
describe '#count_failed' do
describe '#failed_count' do
it 'counts registries that sync has failed' do
create(:geo_upload_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_upload_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
......@@ -86,7 +71,7 @@ RSpec.describe Geo::AttachmentRegistryFinder, :geo do
create(:geo_upload_registry, :attachment, file_id: upload_7.id, missing_on_primary: true)
create(:geo_upload_registry, :attachment, :never_synced, file_id: upload_8.id)
expect(subject.count_failed).to eq 3
expect(subject.failed_count).to eq 3
end
end
......
......@@ -24,36 +24,30 @@ RSpec.describe Geo::ContainerRepositoryRegistryFinder, :geo do
stub_registry_replication_config(enabled: true)
end
describe '#count_syncable' do
it 'returns number of container repositories' do
expect(subject.count_syncable).to eq(6)
end
end
describe '#count_synced' do
it 'returns only synced registry' do
describe '#registry_count' do
it 'returns number of container registries' do
create(:container_repository_registry, :synced, container_repository_id: container_repository_1.id)
create(:container_repository_registry, :sync_failed, container_repository_id: container_repository_3.id)
expect(subject.count_synced).to eq(1)
expect(subject.registry_count).to eq(2)
end
end
describe '#count_failed' do
it 'returns only failed registry' do
describe '#synced_count' do
it 'returns only synced registry' do
create(:container_repository_registry, :synced, container_repository_id: container_repository_1.id)
create(:container_repository_registry, :sync_failed, container_repository_id: container_repository_3.id)
expect(subject.count_failed).to eq(1)
expect(subject.synced_count).to eq(1)
end
end
describe '#count_registry' do
it 'returns number of all registries' do
describe '#failed_count' do
it 'returns only failed registry' do
create(:container_repository_registry, :synced, container_repository_id: container_repository_1.id)
create(:container_repository_registry, :sync_failed, container_repository_id: container_repository_3.id)
expect(subject.count_registry).to eq(2)
expect(subject.failed_count).to eq(1)
end
end
......
......@@ -21,42 +21,30 @@ RSpec.describe Geo::DesignRegistryFinder, :geo do
stub_current_geo_node(secondary)
end
describe '#count_syncable' do
it 'returns number of designs' do
# Two designs for the same project to assert absence of duplicates
create_list(:design, 2, project: project_1)
create(:design, project: project_2)
result = subject.count_syncable
expect(result).to eq(2)
end
end
describe '#count_synced' do
it 'returns number of synced registries' do
describe '#registry_count' do
it 'returns number of desgin registries' do
create(:geo_design_registry, :synced, project_id: project_1.id)
create(:geo_design_registry, :sync_failed, project_id: project_2.id)
expect(subject.count_synced).to eq(1)
expect(subject.registry_count).to eq(2)
end
end
describe '#count_failed' do
it 'returns number of failed registries' do
describe '#synced_count' do
it 'returns number of synced registries' do
create(:geo_design_registry, :synced, project_id: project_1.id)
create(:geo_design_registry, :sync_failed, project_id: project_2.id)
expect(subject.count_failed).to eq(1)
expect(subject.synced_count).to eq(1)
end
end
describe '#count_registry' do
it 'returns number of all registries' do
describe '#failed_count' do
it 'returns number of failed registries' do
create(:geo_design_registry, :synced, project_id: project_1.id)
create(:geo_design_registry, :sync_failed, project_id: project_2.id)
expect(subject.count_registry).to eq(2)
expect(subject.failed_count).to eq(1)
end
end
......
......@@ -6,7 +6,7 @@ RSpec.describe Geo::FileRegistryFinder, :geo do
context 'with abstract methods' do
%w[
replicables
syncable
registry_class
].each do |required_method|
it "requires subclasses to implement #{required_method}" do
expect { subject.send(required_method) }.to raise_error(NotImplementedError)
......
......@@ -30,7 +30,7 @@ RSpec.describe Geo::JobArtifactRegistryFinder, :geo do
subject { described_class.new(current_node_id: secondary.id) }
describe '#count_syncable' do
describe '#registry_count' do
it 'counts registries for job artifacts' do
create(:geo_job_artifact_registry, :failed, artifact_id: ci_job_artifact_1.id)
create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_2.id, missing_on_primary: true)
......@@ -41,26 +41,11 @@ RSpec.describe Geo::JobArtifactRegistryFinder, :geo do
create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_remote_2.id, missing_on_primary: true)
create(:geo_job_artifact_registry, :never_synced, artifact_id: ci_job_artifact_remote_3.id)
expect(subject.count_syncable).to eq 8
expect(subject.registry_count).to eq 8
end
end
describe '#count_registry' do
it 'counts registries for job artifacts' do
create(:geo_job_artifact_registry, :failed, artifact_id: ci_job_artifact_1.id)
create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_2.id, missing_on_primary: true)
create(:geo_job_artifact_registry, :never_synced, artifact_id: ci_job_artifact_3.id)
create(:geo_job_artifact_registry, :failed, artifact_id: ci_job_artifact_4.id)
create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_5.id, missing_on_primary: true, retry_at: 1.day.ago)
create(:geo_job_artifact_registry, :failed, artifact_id: ci_job_artifact_remote_1.id)
create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_remote_2.id, missing_on_primary: true)
create(:geo_job_artifact_registry, :never_synced, artifact_id: ci_job_artifact_remote_3.id)
expect(subject.count_registry).to eq 8
end
end
describe '#count_synced' do
describe '#synced_count' do
it 'counts registries that has been synced' do
create(:geo_job_artifact_registry, :failed, artifact_id: ci_job_artifact_1.id)
create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_2.id, missing_on_primary: true)
......@@ -71,11 +56,11 @@ RSpec.describe Geo::JobArtifactRegistryFinder, :geo do
create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_remote_2.id, missing_on_primary: true)
create(:geo_job_artifact_registry, :never_synced, artifact_id: ci_job_artifact_remote_3.id)
expect(subject.count_synced).to eq 3
expect(subject.synced_count).to eq 3
end
end
describe '#count_failed' do
describe '#failed_count' do
it 'counts registries that sync has failed' do
create(:geo_job_artifact_registry, :failed, artifact_id: ci_job_artifact_1.id)
create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_2.id, missing_on_primary: true)
......@@ -86,7 +71,7 @@ RSpec.describe Geo::JobArtifactRegistryFinder, :geo do
create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_remote_2.id, missing_on_primary: true)
create(:geo_job_artifact_registry, :never_synced, artifact_id: ci_job_artifact_remote_3.id)
expect(subject.count_failed).to eq 3
expect(subject.failed_count).to eq 3
end
end
......
......@@ -20,7 +20,7 @@ RSpec.describe Geo::LfsObjectRegistryFinder, :geo do
subject { described_class.new(current_node_id: secondary.id) }
describe '#count_syncable' do
describe '#registry_count' do
it 'counts registries for LFS objects' do
create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_1.id)
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_2.id, missing_on_primary: true)
......@@ -31,26 +31,11 @@ RSpec.describe Geo::LfsObjectRegistryFinder, :geo do
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_remote_2.id, missing_on_primary: true)
create(:geo_lfs_object_registry, :never_synced, lfs_object_id: lfs_object_remote_3.id)
expect(subject.count_syncable).to eq 8
expect(subject.registry_count).to eq 8
end
end
describe '#count_registry' do
it 'counts registries for LFS objects' do
create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_1.id)
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_2.id, missing_on_primary: true)
create(:geo_lfs_object_registry, :never_synced, lfs_object_id: lfs_object_3.id)
create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_4.id)
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_5.id, missing_on_primary: true, retry_at: 1.day.ago)
create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_remote_1.id)
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_remote_2.id, missing_on_primary: true)
create(:geo_lfs_object_registry, :never_synced, lfs_object_id: lfs_object_remote_3.id)
expect(subject.count_registry).to eq 8
end
end
describe '#count_synced' do
describe '#synced_count' do
it 'counts registries that has been synced' do
create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_1.id)
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_2.id, missing_on_primary: true)
......@@ -61,11 +46,11 @@ RSpec.describe Geo::LfsObjectRegistryFinder, :geo do
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_remote_2.id, missing_on_primary: true)
create(:geo_lfs_object_registry, :never_synced, lfs_object_id: lfs_object_remote_3.id)
expect(subject.count_synced).to eq 3
expect(subject.synced_count).to eq 3
end
end
describe '#count_failed' do
describe '#failed_count' do
it 'counts registries that sync has failed' do
create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_1.id)
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_2.id, missing_on_primary: true)
......@@ -76,7 +61,7 @@ RSpec.describe Geo::LfsObjectRegistryFinder, :geo do
create(:geo_lfs_object_registry, lfs_object_id: lfs_object_remote_2.id, missing_on_primary: true)
create(:geo_lfs_object_registry, :never_synced, lfs_object_id: lfs_object_remote_3.id)
expect(subject.count_failed).to eq 3
expect(subject.failed_count).to eq 3
end
end
......
......@@ -117,9 +117,20 @@ RSpec.describe GeoNodeStatus, :geo do
end
describe '#projects_count' do
it 'counts the number of projects' do
it 'counts the number of projects on a primary node' do
stub_current_geo_node(primary)
expect(subject.projects_count).to eq 4
end
it 'counts the number of projects on a secondary node' do
stub_current_geo_node(secondary)
create(:geo_project_registry, :synced, project: project_1)
create(:geo_project_registry, project: project_3)
expect(subject.projects_count).to eq 2
end
end
describe '#attachments_synced_count' do
......@@ -374,18 +385,14 @@ RSpec.describe GeoNodeStatus, :geo do
expect(subject.repositories_synced_in_percentage).to eq(0)
end
it 'returns the right percentage with no group restrictions' do
it 'returns the right percentage' do
create(:geo_project_registry, :synced, project: project_1)
create(:geo_project_registry, project: project_2)
create(:geo_project_registry, project: project_3)
create(:geo_project_registry, project: project_4)
expect(subject.repositories_synced_in_percentage).to be_within(0.0001).of(25)
end
it 'returns the right percentage with group restrictions' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [group])
create(:geo_project_registry, :synced, project: project_1)
expect(subject.repositories_synced_in_percentage).to be_within(0.0001).of(50)
end
end
describe '#wikis_synced_in_percentage' do
......@@ -399,18 +406,14 @@ RSpec.describe GeoNodeStatus, :geo do
expect(subject.wikis_synced_in_percentage).to eq(0)
end
it 'returns the right percentage with no group restrictions' do
it 'returns the right percentage' do
create(:geo_project_registry, :synced, project: project_1)
create(:geo_project_registry, project: project_2)
create(:geo_project_registry, project: project_3)
create(:geo_project_registry, project: project_4)
expect(subject.wikis_synced_in_percentage).to be_within(0.0001).of(25)
end
it 'returns the right percentage with group restrictions' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [group])
create(:geo_project_registry, :synced, project: project_1)
expect(subject.wikis_synced_in_percentage).to be_within(0.0001).of(50)
end
end
describe '#replication_slots_used_count' do
......@@ -583,16 +586,18 @@ RSpec.describe GeoNodeStatus, :geo do
end
describe '#container_repositories_count' do
let!(:container_1) { create(:container_repository) }
let!(:container_2) { create(:container_repository) }
let!(:container_1) { create(:container_repository_registry, :synced) }
let!(:container_2) { create(:container_repository_registry, :sync_failed) }
let!(:container_3) { create(:container_repository_registry, :sync_failed) }
let!(:container_4) { create(:container_repository) }
context 'when container repositories replication is active' do
before do
stub_geo_setting(registry_replication: { enabled: true })
end
it 'counts all the repositories' do
expect(subject.container_repositories_count).to eq(2)
it 'counts number of registries for repositories' do
expect(subject.container_repositories_count).to eq(3)
end
end
......@@ -687,10 +692,6 @@ RSpec.describe GeoNodeStatus, :geo do
end
describe '#container_repositories_synced_in_percentage' do
let!(:container_repository_1) { create(:container_repository, project: project_1) }
let!(:container_repository_2) { create(:container_repository, project: project_1) }
let!(:container_list) { create_list(:container_repository, 2, project: project_3) }
context 'when container repositories replication is active' do
before do
stub_geo_setting(registry_replication: { enabled: true })
......@@ -700,34 +701,32 @@ RSpec.describe GeoNodeStatus, :geo do
expect(subject.container_repositories_synced_in_percentage).to eq(0)
end
it 'returns the right percentage with no group restrictions' do
create(:container_repository_registry, :synced, container_repository: container_repository_1)
it 'returns the right percentage' do
create(:container_repository_registry, :synced)
create(:container_repository_registry)
create(:container_repository_registry)
create(:container_repository_registry)
expect(subject.container_repositories_synced_in_percentage).to be_within(0.0001).of(25)
end
it 'returns the right percentage with group restrictions' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [group])
create(:container_repository_registry, :synced, container_repository: container_repository_1)
expect(subject.container_repositories_synced_in_percentage).to be_within(0.0001).of(50)
end
end
it 'when container repositories replication is inactive returns 0' do
stub_geo_setting(registry_replication: { enabled: false })
create(:container_repository_registry, :synced, container_repository: container_repository_1)
create(:container_repository_registry, :synced)
expect(subject.container_repositories_synced_in_percentage).to eq(0)
end
end
describe '#design_repositories_count' do
it 'counts all the designs' do
create(:design)
create(:design)
it 'counts number of registries for repositories' do
create(:geo_design_registry, :sync_failed)
create(:geo_design_registry)
create(:geo_design_registry, :synced)
expect(subject.design_repositories_count).to eq(2)
expect(subject.design_repositories_count).to eq(3)
end
end
......@@ -764,23 +763,12 @@ RSpec.describe GeoNodeStatus, :geo do
expect(subject.design_repositories_synced_in_percentage).to eq(0)
end
it 'returns the right percentage with no group restrictions' do
it 'returns the right percentage' do
create(:geo_design_registry, :synced)
create(:geo_design_registry, :sync_failed)
expect(subject.design_repositories_synced_in_percentage).to be_within(0.0001).of(50)
end
it 'returns the right percentage with group restrictions' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [group])
create(:geo_design_registry, :synced, project: project_1)
create(:geo_design_registry, :sync_failed, project: project_2)
create(:geo_design_registry, :sync_failed, project: project_3)
create(:geo_design_registry, :sync_failed, project: project_4)
expect(subject.design_repositories_synced_in_percentage).to be_within(0.0001).of(50)
end
end
describe '#repositories_verified_count' do
......@@ -1006,7 +994,9 @@ RSpec.describe GeoNodeStatus, :geo do
describe '#[]' do
it 'returns values for each attribute' do
expect(subject[:projects_count]).to eq(4)
create(:geo_project_registry, project: project_1)
expect(subject[:projects_count]).to eq(1)
expect(subject[:repositories_synced_count]).to eq(0)
end
......@@ -1243,40 +1233,40 @@ RSpec.describe GeoNodeStatus, :geo do
stub_current_geo_node(primary)
end
it 'does not call LfsObjectRegistryFinder#count_syncable' do
expect_any_instance_of(Geo::LfsObjectRegistryFinder).not_to receive(:count_syncable)
it 'does not call LfsObjectRegistryFinder#registry_count' do
expect_any_instance_of(Geo::LfsObjectRegistryFinder).not_to receive(:registry_count)
subject
end
it 'does not call AttachmentRegistryFinder#count_syncable' do
expect_any_instance_of(Geo::AttachmentRegistryFinder).not_to receive(:count_syncable)
it 'does not call AttachmentRegistryFinder#registry_count' do
expect_any_instance_of(Geo::AttachmentRegistryFinder).not_to receive(:registry_count)
subject
end
it 'does not call JobArtifactRegistryFinder#count_syncable' do
expect_any_instance_of(Geo::JobArtifactRegistryFinder).not_to receive(:count_syncable)
it 'does not call JobArtifactRegistryFinder#registry_count' do
expect_any_instance_of(Geo::JobArtifactRegistryFinder).not_to receive(:registry_count)
subject
end
end
context 'on the secondary' do
it 'calls LfsObjectRegistryFinder#count_syncable' do
expect_any_instance_of(Geo::LfsObjectRegistryFinder).to receive(:count_syncable)
it 'calls LfsObjectRegistryFinder#registry_count' do
expect_any_instance_of(Geo::LfsObjectRegistryFinder).to receive(:registry_count).twice
subject
end
it 'calls AttachmentRegistryFinder#count_syncable' do
expect_any_instance_of(Geo::AttachmentRegistryFinder).to receive(:count_syncable)
it 'calls AttachmentRegistryFinder#registry_count' do
expect_any_instance_of(Geo::AttachmentRegistryFinder).to receive(:registry_count).twice
subject
end
it 'calls JobArtifactRegistryFinder#count_syncable' do
expect_any_instance_of(Geo::JobArtifactRegistryFinder).to receive(:count_syncable)
it 'calls JobArtifactRegistryFinder#registry_count' do
expect_any_instance_of(Geo::JobArtifactRegistryFinder).to receive(:registry_count).twice
subject
end
......
......@@ -3,12 +3,11 @@
RSpec.shared_examples 'a file registry finder' do
it 'responds to file registry finder methods' do
file_registry_finder_methods = %i{
syncable
count_syncable
count_synced
count_failed
registry_class
registry_count
synced_count
failed_count
count_synced_missing_on_primary
count_registry
find_retryable_failed_registries
find_retryable_synced_missing_on_primary_registries
}
......
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