Commit 791064da authored by Stan Hu's avatar Stan Hu

Disable mirror workers for Geo secondaries

Customers using remote mirrors would see errors in their Sidekiq logs after
the worker attempted to update its database.  We should disable this until we
have a better way of synching the mirror workers.

See #1598
parent 5c29411e
......@@ -75,6 +75,7 @@ class RemoteMirror < ActiveRecord::Base
def sync
return unless project && enabled
return if Gitlab::Geo.secondary?
RepositoryUpdateRemoteMirrorWorker.perform_in(BACKOFF_DELAY, self.id, Time.now) if project&.repository_exists?
end
......
......@@ -5,6 +5,9 @@ class UpdateAllMirrorsWorker
LEASE_TIMEOUT = 840
def perform
# This worker requires updating the database state, which we can't
# do on a Geo secondary
return if Gitlab::Geo.secondary?
return unless try_obtain_lease
fail_stuck_mirrors!
......
---
title: Disable mirror workers for Geo secondaries
merge_request:
author:
......@@ -41,11 +41,23 @@ module Gitlab
sync_times
end
def update_all_mirrors_cron_job
Sidekiq::Cron::Job.find("update_all_mirrors_worker")
end
def destroy_cron_job!
update_all_mirrors_cron_job&.destroy
end
def configure_cron_job!
if Gitlab::Geo.secondary?
destroy_cron_job!
return
end
minimum_mirror_sync_time = current_application_settings.minimum_mirror_sync_time rescue FIFTEEN
sync_time = SYNC_TIME_TO_CRON[minimum_mirror_sync_time]
Sidekiq::Cron::Job.find("update_all_mirrors_worker")&.destroy
destroy_cron_job!
Sidekiq::Cron::Job.create(
name: 'update_all_mirrors_worker',
......
......@@ -191,6 +191,19 @@ describe Gitlab::Mirror do
expect(Sidekiq::Cron::Job.find("update_all_mirrors_worker").cron).to eq(fifteen_cron)
end
end
describe 'when Geo is enabled' do
it 'disables mirror cron job' do
described_class.configure_cron_job!
expect(described_class.update_all_mirrors_cron_job).to be_enabled
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
described_class.configure_cron_job!
expect(described_class.update_all_mirrors_cron_job).to be_nil
end
end
end
end
......
......@@ -115,6 +115,14 @@ describe RemoteMirror do
expect(remote_mirror.sync).to be_nil
end
end
context 'as a Geo secondary' do
it 'returns nil' do
allow(Gitlab::Geo).to receive(:secondary?).and_return(true)
expect(remote_mirror.sync).to be_nil
end
end
end
context '#updated_since?' do
......
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