Commit 7726ce69 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'mk/dry-up-verification-state-include' into 'master'

Refactor Geo::VerifiableRegistry module

See merge request gitlab-org/gitlab!56175
parents a773c2ea d8cc4f9a
...@@ -319,10 +319,7 @@ For example, to add support for files referenced by a `Widget` model with a ...@@ -319,10 +319,7 @@ For example, to add support for files referenced by a `Widget` model with a
# frozen_string_literal: true # frozen_string_literal: true
class Geo::WidgetRegistry < Geo::BaseRegistry class Geo::WidgetRegistry < Geo::BaseRegistry
include Geo::ReplicableRegistry include ::Geo::ReplicableRegistry
# TODO: Include VerificationState in VerifiableRegistry
# https://gitlab.com/gitlab-org/gitlab/-/issues/298811
include ::Gitlab::Geo::VerificationState
include ::Geo::VerifiableRegistry include ::Geo::VerifiableRegistry
MODEL_CLASS = ::Widget MODEL_CLASS = ::Widget
......
# frozen_string_literal: true # frozen_string_literal: true
module Geo::VerifiableRegistry module Geo
extend ActiveSupport::Concern module VerifiableRegistry
extend ActiveSupport::Concern
class_methods do include ::Gitlab::Geo::VerificationState
extend ::Gitlab::Utils::Override
class_methods do
# Overrides a method in `Gitlab::Geo::VerificationState`. This method is extend ::Gitlab::Utils::Override
# used by `Gitlab::Geo::VerificationState.start_verification_batch` to
# produce a query which must return values of the primary key of the # Overrides a method in `Gitlab::Geo::VerificationState`. This method is
# *model*, not of the *registry*. We need this so we can instantiate # used by `Gitlab::Geo::VerificationState.start_verification_batch` to
# Replicators. # produce a query which must return values of the primary key of the
override :verification_state_model_key # *model*, not of the *registry*. We need this so we can instantiate
def verification_state_model_key # Replicators.
self::MODEL_FOREIGN_KEY override :verification_state_model_key
end def verification_state_model_key
self::MODEL_FOREIGN_KEY
end
override :verification_pending_batch_relation override :verification_pending_batch_relation
def verification_pending_batch_relation(batch_size:) def verification_pending_batch_relation(batch_size:)
super.synced super.synced
end end
override :verification_failed_batch_relation override :verification_failed_batch_relation
def verification_failed_batch_relation(batch_size:) def verification_failed_batch_relation(batch_size:)
super.synced super.synced
end end
override :needs_verification_relation override :needs_verification_relation
def needs_verification_relation def needs_verification_relation
super.synced super.synced
end
end end
end
included do included do
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
sha_attribute :verification_checksum_mismatched sha_attribute :verification_checksum_mismatched
scope :available_verifiables, -> { all } scope :available_verifiables, -> { all }
override :clear_verification_failure_fields! override :clear_verification_failure_fields!
def clear_verification_failure_fields! def clear_verification_failure_fields!
super super
# Note: If the return value of a `before_transition` block is `false`, # Note: If the return value of a `before_transition` block is `false`,
# then the transition is halted. Anything else, including `nil`, does not # then the transition is halted. Anything else, including `nil`, does not
# halt the transition. # halt the transition.
self.checksum_mismatch = false self.checksum_mismatch = false
self.verification_checksum_mismatched = nil self.verification_checksum_mismatched = nil
end end
# Records a checksum mismatch # Records a checksum mismatch
# #
# @param [String] checksum value which does not match the primary checksum # @param [String] checksum value which does not match the primary checksum
def verification_failed_due_to_mismatch!(checksum, primary_checksum) def verification_failed_due_to_mismatch!(checksum, primary_checksum)
message = 'Checksum does not match the primary checksum' message = 'Checksum does not match the primary checksum'
details = { checksum: checksum, primary_checksum: primary_checksum } details = { checksum: checksum, primary_checksum: primary_checksum }
log_info(message, details) log_info(message, details)
self.verification_failure = "#{message} #{details}".truncate(255) self.verification_failure = "#{message} #{details}".truncate(255)
self.verification_checksum = checksum self.verification_checksum = checksum
self.verification_checksum_mismatched = checksum self.verification_checksum_mismatched = checksum
self.checksum_mismatch = true self.checksum_mismatch = true
self.verification_failed! self.verification_failed!
end end
private private
override :track_checksum_result! override :track_checksum_result!
def track_checksum_result!(checksum, calculation_started_at) def track_checksum_result!(checksum, calculation_started_at)
unless replicator.matches_checksum?(checksum) unless replicator.matches_checksum?(checksum)
return verification_failed_due_to_mismatch!(checksum, replicator.primary_checksum) return verification_failed_due_to_mismatch!(checksum, replicator.primary_checksum)
end end
verification_succeeded_with_checksum!(checksum, calculation_started_at) verification_succeeded_with_checksum!(checksum, calculation_started_at)
end
end end
end end
end end
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
class Geo::PackageFileRegistry < Geo::BaseRegistry class Geo::PackageFileRegistry < Geo::BaseRegistry
include ::Geo::ReplicableRegistry include ::Geo::ReplicableRegistry
include ::Gitlab::Geo::VerificationState
include ::Geo::VerifiableRegistry include ::Geo::VerifiableRegistry
MODEL_CLASS = ::Packages::PackageFile MODEL_CLASS = ::Packages::PackageFile
......
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