Commit 4000cf5d authored by Douwe Maan's avatar Douwe Maan

Merge branch 'ab-11499-mirror-scheduling-featureflag' into 'master'

Mirror scheduling: Remove feature flag

Closes #5035 and #11499

See merge request gitlab-org/gitlab-ee!13422
parents 424dfdfe 16832d7e
...@@ -7,9 +7,6 @@ class RepositoryUpdateMirrorWorker ...@@ -7,9 +7,6 @@ class RepositoryUpdateMirrorWorker
include Gitlab::ShellAdapter include Gitlab::ShellAdapter
include ProjectStartImport 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. # Retry not necessary. It will try again at the next update interval.
sidekiq_options retry: false, status_expiration: StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION sidekiq_options retry: false, status_expiration: StuckImportJobsWorker::IMPORT_JOBS_EXPIRATION
...@@ -34,20 +31,10 @@ class RepositoryUpdateMirrorWorker ...@@ -34,20 +31,10 @@ class RepositoryUpdateMirrorWorker
fail_mirror(project, ex.message) fail_mirror(project, ex.message)
raise UpdateError, "#{ex.class}: #{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 end
private private
def lease
@lease ||= ::Gitlab::ExclusiveLease.new(LEASE_KEY, timeout: LEASE_TIMEOUT)
end
def start_mirror(project) def start_mirror(project)
import_state = project.import_state import_state = project.import_state
......
...@@ -17,16 +17,14 @@ class UpdateAllMirrorsWorker ...@@ -17,16 +17,14 @@ class UpdateAllMirrorsWorker
# If we didn't get the lease, exit early # If we didn't get the lease, exit early
return unless scheduling_ran return unless scheduling_ran
if Feature.enabled?(:update_all_mirrors_worker_rescheduling) # Wait to give some jobs a chance to complete
# Wait to give some jobs a chance to complete Kernel.sleep(RESCHEDULE_WAIT)
Kernel.sleep(RESCHEDULE_WAIT)
# If there's capacity left now (some jobs completed),
# If there's capacity left now (some jobs completed), # reschedule this job to enqueue more work.
# reschedule this job to enqueue more work. #
# # This is in addition to the regular (cron-like) scheduling of this job.
# This is in addition to the regular (cron-like) scheduling of this job. reschedule_if_capacity_left
reschedule_if_capacity_left
end
end end
# rubocop: disable CodeReuse/ActiveRecord # 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' require 'rails_helper'
describe RepositoryUpdateMirrorWorker do describe RepositoryUpdateMirrorWorker do
include ExclusiveLeaseHelpers
describe '#perform' do describe '#perform' do
let(:jid) { '12345678' } let(:jid) { '12345678' }
let!(:project) { create(:project) } let!(:project) { create(:project) }
...@@ -50,51 +48,5 @@ describe RepositoryUpdateMirrorWorker do ...@@ -50,51 +48,5 @@ describe RepositoryUpdateMirrorWorker do
expect { subject.perform(started_project.id) }.to change { import_state.reload.status }.to('finished') expect { subject.perform(started_project.id) }.to change { import_state.reload.status }.to('finished')
end end
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
end end
...@@ -24,32 +24,26 @@ describe UpdateAllMirrorsWorker do ...@@ -24,32 +24,26 @@ describe UpdateAllMirrorsWorker do
worker.perform worker.perform
end end
context 'with update_all_mirrors_worker_rescheduling feature' do it 'sleeps a bit after scheduling mirrors' do
before do expect(Kernel).to receive(:sleep).with(described_class::RESCHEDULE_WAIT)
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)
worker.perform worker.perform
end end
it 'reschedules the job if capacity is left' do it 'reschedules the job if capacity is left' do
allow(Gitlab::Mirror).to receive(:reschedule_immediately?).and_return(true) 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 worker.perform
end end
it 'does not reschedule the job if no capacity left' do it 'does not reschedule the job if no capacity left' do
allow(Gitlab::Mirror).to receive(:reschedule_immediately?).and_return(false) 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 worker.perform
end
end end
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