Commit 16832d7e authored by Andreas Brandl's avatar Andreas Brandl

Mirror scheduling: Remove feature flag

This removes the feature flag update_all_mirrors_worker_rescheduling and
makes the new behavior the default while cleaning up code and specs.

Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/11499.
Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/5035.
parent 352fb274
......@@ -7,9 +7,6 @@ class RepositoryUpdateMirrorWorker
include Gitlab::ShellAdapter
include ProjectStartImport
LEASE_KEY = 'repository_update_mirror_worker_start_scheduler'.freeze
LEASE_TIMEOUT = 2.seconds
# Retry not necessary. It will try again at the next update interval.
sidekiq_options retry: false, status_expiration: StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION
......@@ -34,20 +31,10 @@ class RepositoryUpdateMirrorWorker
fail_mirror(project, ex.message)
raise UpdateError, "#{ex.class}: #{ex.message}"
ensure
unless Feature.enabled?(:update_all_mirrors_worker_rescheduling)
if !lease.exists? && lease.try_obtain && Gitlab::Mirror.reschedule_immediately?
UpdateAllMirrorsWorker.perform_async
end
end
end
private
def lease
@lease ||= ::Gitlab::ExclusiveLease.new(LEASE_KEY, timeout: LEASE_TIMEOUT)
end
def start_mirror(project)
import_state = project.import_state
......
......@@ -17,16 +17,14 @@ class UpdateAllMirrorsWorker
# If we didn't get the lease, exit early
return unless scheduling_ran
if Feature.enabled?(:update_all_mirrors_worker_rescheduling)
# Wait to give some jobs a chance to complete
Kernel.sleep(RESCHEDULE_WAIT)
# If there's capacity left now (some jobs completed),
# reschedule this job to enqueue more work.
#
# This is in addition to the regular (cron-like) scheduling of this job.
reschedule_if_capacity_left
end
# Wait to give some jobs a chance to complete
Kernel.sleep(RESCHEDULE_WAIT)
# If there's capacity left now (some jobs completed),
# reschedule this job to enqueue more work.
#
# This is in addition to the regular (cron-like) scheduling of this job.
reschedule_if_capacity_left
end
# rubocop: disable CodeReuse/ActiveRecord
......
---
title: Improve scheduling of mirror updates to reduce frequency of database queries
merge_request: 11217
author:
type: performance
require 'rails_helper'
describe RepositoryUpdateMirrorWorker do
include ExclusiveLeaseHelpers
describe '#perform' do
let(:jid) { '12345678' }
let!(:project) { create(:project) }
......@@ -50,51 +48,5 @@ describe RepositoryUpdateMirrorWorker do
expect { subject.perform(started_project.id) }.to change { import_state.reload.status }.to('finished')
end
end
context 'reschedule mirrors' do
before do
allow_any_instance_of(Projects::UpdateMirrorService).to receive(:execute).and_return(status: :success)
stub_feature_flags(update_all_mirrors_worker_rescheduling: false)
end
context 'when we obtain the lease' do
before do
allow(stub_exclusive_lease).to receive(:exists?).and_return(false)
end
it 'performs UpdateAllMirrorsWorker when reschedule_immediately? returns true' do
allow(Gitlab::Mirror).to receive(:reschedule_immediately?).and_return(true)
expect(UpdateAllMirrorsWorker).to receive(:perform_async).once
subject.perform(project.id)
end
it 'does not perform UpdateAllMirrorsWorker when reschedule_immediately? returns false' do
allow(Gitlab::Mirror).to receive(:reschedule_immediately?).and_return(false)
expect(UpdateAllMirrorsWorker).not_to receive(:perform_async)
subject.perform(project.id)
end
end
it 'does not perform UpdateAllMirrorsWorker when we cannot obtain the lease' do
stub_exclusive_lease_taken
expect(UpdateAllMirrorsWorker).not_to receive(:perform_async)
subject.perform(project.id)
end
it 'does not perform UpdateAllMirrorsWorker when the lease already exists' do
stub_exclusive_lease_taken
expect(UpdateAllMirrorsWorker).not_to receive(:perform_async)
subject.perform(project.id)
end
end
end
end
......@@ -24,32 +24,26 @@ describe UpdateAllMirrorsWorker do
worker.perform
end
context 'with update_all_mirrors_worker_rescheduling feature' do
before do
stub_feature_flags(update_all_mirrors_worker_rescheduling: true)
end
it 'sleeps a bit after scheduling mirrors' do
expect(Kernel).to receive(:sleep).with(described_class::RESCHEDULE_WAIT)
it 'sleeps a bit after scheduling mirrors' do
expect(Kernel).to receive(:sleep).with(described_class::RESCHEDULE_WAIT)
worker.perform
end
worker.perform
end
it 'reschedules the job if capacity is left' do
allow(Gitlab::Mirror).to receive(:reschedule_immediately?).and_return(true)
it 'reschedules the job if capacity is left' do
allow(Gitlab::Mirror).to receive(:reschedule_immediately?).and_return(true)
expect(described_class).to receive(:perform_async)
expect(described_class).to receive(:perform_async)
worker.perform
end
worker.perform
end
it 'does not reschedule the job if no capacity left' do
allow(Gitlab::Mirror).to receive(:reschedule_immediately?).and_return(false)
it 'does not reschedule the job if no capacity left' do
allow(Gitlab::Mirror).to receive(:reschedule_immediately?).and_return(false)
expect(described_class).not_to receive(:perform_async)
expect(described_class).not_to receive(:perform_async)
worker.perform
end
worker.perform
end
end
......
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