Move find_never_synced_registries to the parent class

Refactor code to make the finder class
closer to a Geo replicator.
parent 2df757d7
...@@ -2,31 +2,6 @@ ...@@ -2,31 +2,6 @@
module Geo module Geo
class ContainerRepositoryRegistryFinder < RegistryFinder class ContainerRepositoryRegistryFinder < RegistryFinder
# Returns Geo::ContainerRepositoryRegistry records that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
# table to be the single source of truth. The contract is that other
# processes need to ensure that the table only contains records that should
# be synced.
#
# Any registries that have ever been synced that currently need to be
# resynced will be handled by other find methods (like
# #find_retryable_dirty_registries)
#
# You can pass a list with `except_ids:` so you can exclude items you
# already scheduled but haven't finished and aren't persisted to the database yet
#
# @param [Integer] batch_size used to limit the results returned
# @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: [])
registry_class
.never_synced
.model_id_not_in(except_ids)
.limit(batch_size)
end
# rubocop:enable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord # rubocop:disable CodeReuse/ActiveRecord
def find_retryable_dirty_registries(batch_size:, except_ids: []) def find_retryable_dirty_registries(batch_size:, except_ids: [])
registry_class registry_class
......
...@@ -2,31 +2,6 @@ ...@@ -2,31 +2,6 @@
module Geo module Geo
class DesignRegistryFinder < RegistryFinder class DesignRegistryFinder < RegistryFinder
# Returns Geo::DesignRegistry records that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
# table to be the single source of truth. The contract is that other
# processes need to ensure that the table only contains records that should
# be synced.
#
# Any registries that have ever been synced that currently need to be
# resynced will be handled by other find methods (like
# #find_retryable_dirty_registries)
#
# You can pass a list with `except_ids:` so you can exclude items you
# already scheduled but haven't finished and aren't persisted to the database yet
#
# @param [Integer] batch_size used to limit the results returned
# @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: [])
registry_class
.never_synced
.model_id_not_in(except_ids)
.limit(batch_size)
end
# rubocop:enable CodeReuse/ActiveRecord
# rubocop:disable CodeReuse/ActiveRecord # rubocop:disable CodeReuse/ActiveRecord
def find_retryable_dirty_registries(batch_size:, except_ids: []) def find_retryable_dirty_registries(batch_size:, except_ids: [])
registry_class registry_class
......
...@@ -9,34 +9,6 @@ module Geo ...@@ -9,34 +9,6 @@ module Geo
registry_class.synced.missing_on_primary.count registry_class.synced.missing_on_primary.count
end end
# @!method find_never_synced_registries
# Return an ActiveRecord::Relation of the registry records for the
# tracked file_type(s) that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
# table to be the single source of truth. The contract is that other
# processes need to ensure that the table only contains records that should
# be synced.
#
# Any registries that have ever been synced that currently need to be
# resynced will be handled by other find methods (like
# #find_retryable_failed_registries)
#
# You can pass a list with `except_ids:` so you can exclude items you
# already scheduled but haven't finished and aren't persisted to the database yet
#
# @param [Integer] batch_size used to limit the results returned
# @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: [])
registry_class
.never
.model_id_not_in(except_ids)
.limit(batch_size)
end
# rubocop:enable CodeReuse/ActiveRecord
# @!method find_retryable_failed_registries # @!method find_retryable_failed_registries
# Return an ActiveRecord::Relation of registry records marked as failed, # Return an ActiveRecord::Relation of registry records marked as failed,
# which are ready to be retried, excluding specified IDs, limited to # which are ready to be retried, excluding specified IDs, limited to
......
...@@ -38,6 +38,34 @@ module Geo ...@@ -38,6 +38,34 @@ module Geo
[untracked_ids, unused_tracked_ids] [untracked_ids, unused_tracked_ids]
end end
# @!method find_never_synced_registries
# Return an ActiveRecord::Relation of the registry records for the
# tracked ype that have never been synced.
#
# Does not care about selective sync, because it considers the Registry
# table to be the single source of truth. The contract is that other
# processes need to ensure that the table only contains records that should
# be synced.
#
# Any registries that have ever been synced that currently need to be
# resynced will be handled by other find methods (like
# #find_retryable_failed_registries)
#
# You can pass a list with `except_ids:` so you can exclude items you
# already scheduled but haven't finished and aren't persisted to the database yet
#
# @param [Integer] batch_size used to limit the results returned
# @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: [])
registry_class
.never_synced
.model_id_not_in(except_ids)
.limit(batch_size)
end
# rubocop:enable CodeReuse/ActiveRecord
# @!method registry_class # @!method registry_class
# Return an ActiveRecord::Base class for the tracked type # Return an ActiveRecord::Base class for the tracked type
def registry_class def registry_class
......
...@@ -6,7 +6,7 @@ class Geo::JobArtifactRegistry < Geo::BaseRegistry ...@@ -6,7 +6,7 @@ class Geo::JobArtifactRegistry < Geo::BaseRegistry
MODEL_CLASS = ::Ci::JobArtifact MODEL_CLASS = ::Ci::JobArtifact
MODEL_FOREIGN_KEY = :artifact_id MODEL_FOREIGN_KEY = :artifact_id
scope :never, -> { where(success: false, retry_count: nil) } scope :never_synced, -> { where(success: false, retry_count: nil) }
def self.failed def self.failed
where(success: false).where.not(retry_count: nil) where(success: false).where.not(retry_count: nil)
......
...@@ -11,7 +11,7 @@ class Geo::LfsObjectRegistry < Geo::BaseRegistry ...@@ -11,7 +11,7 @@ class Geo::LfsObjectRegistry < Geo::BaseRegistry
belongs_to :lfs_object, class_name: 'LfsObject' belongs_to :lfs_object, class_name: 'LfsObject'
scope :never, -> { where(success: false, retry_count: nil) } scope :never_synced, -> { where(success: false, retry_count: nil) }
def self.failed def self.failed
where(success: false).where.not(retry_count: nil) where(success: false).where.not(retry_count: nil)
......
...@@ -12,7 +12,7 @@ class Geo::UploadRegistry < Geo::BaseRegistry ...@@ -12,7 +12,7 @@ class Geo::UploadRegistry < Geo::BaseRegistry
scope :failed, -> { where(success: false).where.not(retry_count: nil) } scope :failed, -> { where(success: false).where.not(retry_count: nil) }
scope :fresh, -> { order(created_at: :desc) } scope :fresh, -> { order(created_at: :desc) }
scope :never, -> { where(success: false, retry_count: nil) } scope :never_synced, -> { where(success: false, retry_count: nil) }
def self.finder_class def self.finder_class
::Geo::AttachmentRegistryFinder ::Geo::AttachmentRegistryFinder
...@@ -54,7 +54,7 @@ class Geo::UploadRegistry < Geo::BaseRegistry ...@@ -54,7 +54,7 @@ class Geo::UploadRegistry < Geo::BaseRegistry
self.public_send(status) # rubocop: disable GitlabSecurity/PublicSend self.public_send(status) # rubocop: disable GitlabSecurity/PublicSend
# Explained via: https://gitlab.com/gitlab-org/gitlab/-/issues/216049 # Explained via: https://gitlab.com/gitlab-org/gitlab/-/issues/216049
when 'pending' when 'pending'
self.never self.never_synced
else else
all all
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