Commit 2f7ca7e0 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'mj-replica-rollout-new-plan' into 'master'

Make incremental rollout possible for `UserRefreshOverUserRangeWorker` so as to read data from replica  [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!61883
parents d562f206 8afc2b39
...@@ -24,7 +24,7 @@ module AuthorizedProjectUpdate ...@@ -24,7 +24,7 @@ module AuthorizedProjectUpdate
# `data_consistency :delayed` and not `idempotent!` # `data_consistency :delayed` and not `idempotent!`
# See https://gitlab.com/gitlab-org/gitlab/-/issues/325291 # See https://gitlab.com/gitlab-org/gitlab/-/issues/325291
deduplicate :until_executing, including_scheduled: true deduplicate :until_executing, including_scheduled: true
data_consistency :delayed, feature_flag: :periodic_project_authorization_update_via_replica data_consistency :delayed, feature_flag: :delayed_consistency_for_user_refresh_over_range_worker
def perform(start_user_id, end_user_id) def perform(start_user_id, end_user_id)
if Feature.enabled?(:periodic_project_authorization_update_via_replica) if Feature.enabled?(:periodic_project_authorization_update_via_replica)
...@@ -32,12 +32,17 @@ module AuthorizedProjectUpdate ...@@ -32,12 +32,17 @@ module AuthorizedProjectUpdate
enqueue_project_authorizations_refresh(user) if project_authorizations_needs_refresh?(user) enqueue_project_authorizations_refresh(user) if project_authorizations_needs_refresh?(user)
end end
else else
use_primary_database
AuthorizedProjectUpdate::RecalculateForUserRangeService.new(start_user_id, end_user_id).execute AuthorizedProjectUpdate::RecalculateForUserRangeService.new(start_user_id, end_user_id).execute
end end
end end
private private
def use_primary_database
# no-op in CE, overriden in EE
end
def project_authorizations_needs_refresh?(user) def project_authorizations_needs_refresh?(user)
AuthorizedProjectUpdate::FindRecordsDueForRefreshService.new(user).needs_refresh? AuthorizedProjectUpdate::FindRecordsDueForRefreshService.new(user).needs_refresh?
end end
...@@ -49,3 +54,5 @@ module AuthorizedProjectUpdate ...@@ -49,3 +54,5 @@ module AuthorizedProjectUpdate
end end
end end
end end
AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker.prepend_mod_with('AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker')
---
name: delayed_consistency_for_user_refresh_over_range_worker
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61883
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/327092
milestone: '13.12'
type: development
group: group::access
default_enabled: false
# frozen_string_literal: true
module EE
module AuthorizedProjectUpdate
module UserRefreshOverUserRangeWorker # rubocop:disable Scalability/IdempotentWorker
extend ::Gitlab::Utils::Override
private
override :use_primary_database
def use_primary_database
if ::Gitlab::Database::LoadBalancing.enable?
::Gitlab::Database::LoadBalancing::Session.current.use_primary!
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
let_it_be(:project) { create(:project) }
let(:user) { project.namespace.owner }
let(:start_user_id) { user.id }
let(:end_user_id) { start_user_id }
let(:execute_worker) { subject.perform(start_user_id, end_user_id) }
describe '#perform' do
context 'when the feature flag `periodic_project_authorization_update_via_replica` is disabled' do
before do
stub_feature_flags(periodic_project_authorization_update_via_replica: false)
end
context 'when load balancing is enabled' do
before do
allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(true)
end
it 'reads from the primary database' do
expect(Gitlab::Database::LoadBalancing::Session.current)
.to receive(:use_primary!)
execute_worker
end
end
end
end
end
...@@ -11,7 +11,7 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do ...@@ -11,7 +11,7 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
it_behaves_like 'worker with data consistency', it_behaves_like 'worker with data consistency',
described_class, described_class,
feature_flag: :periodic_project_authorization_update_via_replica, feature_flag: :delayed_consistency_for_user_refresh_over_range_worker,
data_consistency: :delayed data_consistency: :delayed
describe '#perform' do describe '#perform' 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