Commit 29bc64b4 authored by Mike Kozono's avatar Mike Kozono

Refactor: Extract more checksum methods

Out of Gitlab::Geo::Replicator, and into the Geo::VerifiableReplicator
concern.
parent d166eecc
......@@ -4,7 +4,7 @@ module Geo
module RepositoryReplicatorStrategy
extend ActiveSupport::Concern
include Delay
include ::Geo::VerifiableReplicator
include Gitlab::Geo::LogHelpers
included do
......
......@@ -6,6 +6,20 @@ module Geo
include Delay
class_methods do
def checksummed
model.available_replicables.checksummed
end
def checksummed_count
model.available_replicables.checksummed.count
end
def checksum_failed_count
model.available_replicables.checksum_failed.count
end
end
def after_verifiable_update
schedule_checksum_calculation if needs_checksum?
end
......@@ -26,6 +40,23 @@ module Geo
model_record.verification_checksum == checksum
end
def needs_checksum?
return true unless model_record.respond_to?(:needs_checksum?)
model_record.needs_checksum?
end
# Checksum value from the main database
#
# @abstract
def primary_checksum
model_record.verification_checksum
end
def secondary_checksum
registry.verification_checksum
end
private
# Update checksum on Geo primary database
......@@ -48,5 +79,9 @@ module Geo
retry_count = model_record.verification_retry_count.to_i + 1
[next_retry_time(retry_count), retry_count]
end
def schedule_checksum_calculation
raise NotImplementedError
end
end
end
......@@ -134,18 +134,6 @@ module Gitlab
replicator_class.new(model_record_id: replicable_id)
end
def self.checksummed
model.available_replicables.checksummed
end
def self.checksummed_count
model.available_replicables.checksummed.count
end
def self.checksum_failed_count
model.available_replicables.checksum_failed.count
end
def self.primary_total_count
model.available_replicables.count
end
......@@ -265,17 +253,6 @@ module Gitlab
registry_class.for_model_record_id(model_record_id)
end
# Checksum value from the main database
#
# @abstract
def primary_checksum
model_record.verification_checksum
end
def secondary_checksum
registry.verification_checksum
end
# Return exactly the data needed by `for_replicable_params` to
# reinstantiate this Replicator elsewhere.
#
......@@ -298,10 +275,6 @@ module Gitlab
publish(:updated, **updated_params)
end
def schedule_checksum_calculation
raise NotImplementedError
end
def created_params
event_params
end
......@@ -318,12 +291,6 @@ module Gitlab
{ model_record_id: model_record.id }
end
def needs_checksum?
return true unless model_record.respond_to?(:needs_checksum?)
model_record.needs_checksum?
end
protected
# Store an event on the database
......
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