diff --git a/ee/app/models/concerns/geo/replicable_registry.rb b/ee/app/models/concerns/geo/replicable_registry.rb index ddb7eaeacb0b4183d6f23f77efaebdbda81fa3ae..df2557022858df990a5efa396a0bfafe3bfc72d1 100644 --- a/ee/app/models/concerns/geo/replicable_registry.rb +++ b/ee/app/models/concerns/geo/replicable_registry.rb @@ -19,6 +19,12 @@ def state_value(state_string) STATE_VALUES[state_string] end + def unsynced_objects + # rubocop:disable Database/AvoidUsingPluckWithoutLimit -- To be fixed before merge + model_class.find(unsynced.pluck(model_foreign_key)).minimum(:updated_at) + # rubocop:enable Database/AvoidUsingPluckWithoutLimit + end + def for_model_record_id(id) find_or_initialize_by(model_foreign_key => id) end @@ -81,6 +87,7 @@ def replicator_class scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.current))) } scope :synced, -> { with_state(:synced) } scope :sync_timed_out, -> { with_state(:started).where(last_synced_at: ...replicator_class.sync_timeout.ago) } + scope :unsynced, -> { without_state(:synced) } state_machine :state, initial: :pending do state :pending, value: STATE_VALUES[:pending] diff --git a/ee/app/models/geo_node_status.rb b/ee/app/models/geo_node_status.rb index 530a07f9d9a9517367a6af95929b4e7a54361dee..7b4fa8a1c53deb4660514a222ea6c4c4dedfbbf8 100644 --- a/ee/app/models/geo_node_status.rb +++ b/ee/app/models/geo_node_status.rb @@ -36,7 +36,8 @@ def self.status_fields_for(replicable_class) "#{replicable_class.replicable_name_plural}_registry_count": "Number of #{replicable_class.replicable_title_plural} synced to sync on secondary", "#{replicable_class.replicable_name_plural}_verification_total_count": "Number of #{replicable_class.replicable_title_plural} available to verify on secondary", "#{replicable_class.replicable_name_plural}_verified_count": "Number of #{replicable_class.replicable_title_plural} verified on the secondary", - "#{replicable_class.replicable_name_plural}_verification_failed_count": "Number of #{replicable_class.replicable_title_plural} failed to verify on secondary" + "#{replicable_class.replicable_name_plural}_verification_failed_count": "Number of #{replicable_class.replicable_title_plural} failed to verify on secondary", + "#{replicable_class.replicable_name_plural}_oldest_unsynced_time": "Timestamp of the oldest out of sync #{replicable_class.replicable_title_plural} on secondary" } end diff --git a/ee/lib/gitlab/geo/replicator.rb b/ee/lib/gitlab/geo/replicator.rb index 1a83864f4194ebcb65dfec9b0633c95dfdacc144..d02f8ae8be6405a51b0234b4fd56e0d78a7d00d3 100644 --- a/ee/lib/gitlab/geo/replicator.rb +++ b/ee/lib/gitlab/geo/replicator.rb @@ -175,6 +175,10 @@ def self.replication_enabled? Feature.enabled?(replication_enabled_feature_key, type: :ops) end + def self.oldest_unsynced + registry_class.with_state(:synced) + end + # @example Given `Geo::PackageFileRegistryFinder`, this returns # `::Geo::PackageFileReplicator` # @example Given `Resolver::Geo::PackageFileRegistriesResolver`, this