Commit 991990f3 authored by Matthias Käppler's avatar Matthias Käppler

Merge branch '325519-prevent_retry_for_delayed_data_consistency' into 'master'

Prevent retry for delayed data consistency

See merge request gitlab-org/gitlab!65267
parents 6b1056e9 a3bea60b
...@@ -47,11 +47,36 @@ module ApplicationWorker ...@@ -47,11 +47,36 @@ module ApplicationWorker
end end
class_methods do class_methods do
extend ::Gitlab::Utils::Override
def inherited(subclass) def inherited(subclass)
subclass.set_queue subclass.set_queue
subclass.after_set_class_attribute { subclass.set_queue } subclass.after_set_class_attribute { subclass.set_queue }
end end
override :validate_worker_attributes!
def validate_worker_attributes!
super
# Since the delayed data_consistency will use sidekiq built in retry mechanism, it is required that this mechanism
# is not disabled.
if retry_disabled? && get_data_consistency == :delayed
raise ArgumentError, "Retry support cannot be disabled if data_consistency is set to :delayed"
end
end
# Checks if sidekiq retry support is disabled
def retry_disabled?
get_sidekiq_options['retry'] == 0 || get_sidekiq_options['retry'] == false
end
override :sidekiq_options
def sidekiq_options(opts = {})
super.tap do
validate_worker_attributes!
end
end
def perform_async(*args) def perform_async(*args)
# Worker execution for workers with data_consistency set to :delayed or :sticky # Worker execution for workers with data_consistency set to :delayed or :sticky
# will be delayed to give replication enough time to complete # will be delayed to give replication enough time to complete
......
...@@ -6,8 +6,6 @@ module Elastic ...@@ -6,8 +6,6 @@ module Elastic
included do included do
include ApplicationWorker include ApplicationWorker
sidekiq_options retry: 3
include Gitlab::ExclusiveLeaseHelpers include Gitlab::ExclusiveLeaseHelpers
# There is no onward scheduling and this cron handles work from across the # There is no onward scheduling and this cron handles work from across the
# application, so there's no useful context to add. # application, so there's no useful context to add.
......
...@@ -7,7 +7,7 @@ class ElasticIndexBulkCronWorker # rubocop:disable Scalability/IdempotentWorker ...@@ -7,7 +7,7 @@ class ElasticIndexBulkCronWorker # rubocop:disable Scalability/IdempotentWorker
urgency :throttled urgency :throttled
# Even though this worker is idempotent, until https://gitlab.com/gitlab-org/gitlab/-/issues/325291 is done # Even though this worker is idempotent, until https://gitlab.com/gitlab-org/gitlab/-/issues/325291 is done
# we can't use it with read-only database replicas # we can't use it with read-only database replicas
data_consistency :delayed data_consistency :sticky
private private
......
...@@ -7,7 +7,7 @@ class ElasticIndexInitialBulkCronWorker # rubocop:disable Scalability/Idempotent ...@@ -7,7 +7,7 @@ class ElasticIndexInitialBulkCronWorker # rubocop:disable Scalability/Idempotent
urgency :throttled urgency :throttled
# Even though this worker is idempotent, until https://gitlab.com/gitlab-org/gitlab/-/issues/325291 is done # Even though this worker is idempotent, until https://gitlab.com/gitlab-org/gitlab/-/issues/325291 is done
# we can't use it with read-only database replicas # we can't use it with read-only database replicas
data_consistency :delayed data_consistency :sticky
private private
......
...@@ -50,5 +50,5 @@ RSpec.describe ElasticIndexBulkCronWorker do ...@@ -50,5 +50,5 @@ RSpec.describe ElasticIndexBulkCronWorker do
it_behaves_like 'worker with data consistency', it_behaves_like 'worker with data consistency',
described_class, described_class,
data_consistency: :delayed data_consistency: :sticky
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ElasticIndexInitialBulkCronWorker do
it_behaves_like 'worker with data consistency',
described_class,
data_consistency: :sticky
end
...@@ -176,6 +176,77 @@ RSpec.describe ApplicationWorker do ...@@ -176,6 +176,77 @@ RSpec.describe ApplicationWorker do
end end
end end
describe '.data_consistency' do
using RSpec::Parameterized::TableSyntax
where(:data_consistency, :sidekiq_option_retry, :expect_error) do
:delayed | false | true
:delayed | 0 | true
:delayed | 3 | false
:delayed | nil | false
:sticky | false | false
:sticky | 0 | false
:sticky | 3 | false
:sticky | nil | false
:always | false | false
:always | 0 | false
:always | 3 | false
:always | nil | false
end
with_them do
before do
worker.sidekiq_options retry: sidekiq_option_retry unless sidekiq_option_retry.nil?
end
context "when workers data consistency is #{params['data_consistency']}" do
it "#{params['expect_error'] ? '' : 'not to '}raise an exception" do
if expect_error
expect { worker.data_consistency data_consistency }
.to raise_error("Retry support cannot be disabled if data_consistency is set to :delayed")
else
expect { worker.data_consistency data_consistency }
.not_to raise_error
end
end
end
end
end
describe '.retry' do
using RSpec::Parameterized::TableSyntax
where(:data_consistency, :sidekiq_option_retry, :expect_error) do
:delayed | false | true
:delayed | 0 | true
:delayed | 3 | false
:sticky | false | false
:sticky | 0 | false
:sticky | 3 | false
:always | false | false
:always | 0 | false
:always | 3 | false
end
with_them do
before do
worker.data_consistency(data_consistency)
end
context "when retry sidekiq option is #{params['sidekiq_option_retry']}" do
it "#{params['expect_error'] ? '' : 'not to '}raise an exception" do
if expect_error
expect { worker.sidekiq_options retry: sidekiq_option_retry }
.to raise_error("Retry support cannot be disabled if data_consistency is set to :delayed")
else
expect { worker.sidekiq_options retry: sidekiq_option_retry }
.not_to raise_error
end
end
end
end
end
describe '.perform_async' do describe '.perform_async' do
shared_examples_for 'worker utilizes load balancing capabilities' do |data_consistency| shared_examples_for 'worker utilizes load balancing capabilities' do |data_consistency|
before do before 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