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