Process reset checksum events on secondary nodes

Reset the repository/wiki verification state for a project
when the secondary node gets a Geo::ResetChecksumEvent.
parent 0ac40127
......@@ -160,6 +160,21 @@ class Geo::ProjectRegistry < Geo::BaseRegistry
)
end
# Resets repository/wiki verification state. Is called when a Geo
# secondary node process a Geo::ResetChecksymEvent.
def reset_checksum!
update!(
repository_verification_checksum_sha: nil,
wiki_verification_checksum_sha: nil,
repository_checksum_mismatch: false,
wiki_checksum_mismatch: false,
last_repository_verification_failure: nil,
last_wiki_verification_failure: nil,
repository_verification_retry_count: nil,
wiki_verification_retry_count: nil
)
end
def repository_sync_due?(scheduled_time)
never_synced_repository? || repository_sync_needed?(scheduled_time)
end
......
# frozen_string_literal: true
module Gitlab
module Geo
module LogCursor
module Events
class ResetChecksumEvent
include BaseEvent
def process
registry.reset_checksum! unless skippable?
log_event
end
private
def log_event
logger.event_info(
created_at,
'Reset checksum',
project_id: event.project_id,
skippable: skippable?
)
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Geo::LogCursor::Events::ResetChecksumEvent, :postgresql, :clean_gitlab_redis_shared_state do
let(:logger) { Gitlab::Geo::LogCursor::Logger.new(described_class, Logger::INFO) }
let(:event_log) { create(:geo_event_log, :reset_checksum_event) }
let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) }
let(:reset_checksum_event) { event_log.reset_checksum_event }
let(:project) { reset_checksum_event.project }
subject { described_class.new(reset_checksum_event, Time.now, logger) }
around do |example|
Sidekiq::Testing.fake! { example.run }
end
describe '#process' do
context 'when a tracking entry does not exist' do
it 'does not create a tracking entry' do
expect { subject.process }.not_to change(Geo::ProjectRegistry, :count)
end
it 'logs an info event' do
data = {
class: described_class.name,
message: 'Reset checksum',
project_id: project.id,
skippable: true
}
expect(::Gitlab::Logger)
.to receive(:info)
.with(hash_including(data))
subject.process
end
end
context 'when a tracking entry exists' do
let!(:registry) { create(:geo_project_registry, :repository_verified, :wiki_verified, project: project) }
it 'resets repository/wiki verification state' do
subject.process
expect(registry.reload).to have_attributes(
repository_verification_checksum_sha: nil,
wiki_verification_checksum_sha: nil
)
end
it 'logs an info event' do
data = {
class: described_class.name,
message: 'Reset checksum',
project_id: project.id,
skippable: false
}
expect(::Gitlab::Logger)
.to receive(:info)
.with(hash_including(data))
subject.process
end
end
end
end
......@@ -753,6 +753,34 @@ describe Geo::ProjectRegistry do
end
end
describe '#reset_checksum!' do
it 'resets repository/wiki verification state' do
subject.update!(
repository_verification_checksum_sha: 'abc123',
wiki_verification_checksum_sha: 'abc123',
repository_checksum_mismatch: true,
wiki_checksum_mismatch: true,
last_repository_verification_failure: 'foo',
last_wiki_verification_failure: 'foo',
repository_verification_retry_count: 1,
wiki_verification_retry_count: 1
)
subject.reset_checksum!
expect(subject).to have_attributes(
repository_verification_checksum_sha: nil,
wiki_verification_checksum_sha: nil,
repository_checksum_mismatch: false,
wiki_checksum_mismatch: false,
last_repository_verification_failure: nil,
last_wiki_verification_failure: nil,
repository_verification_retry_count: nil,
wiki_verification_retry_count: nil
)
end
end
describe '#repository_verification_pending?' do
it 'returns true when outdated' do
registry = create(:geo_project_registry, :repository_verification_outdated)
......
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