Commit 9f42733a authored by Imre Farkas's avatar Imre Farkas

Merge branch 'mmj-remove-ff-periodic-project-authorizations' into 'master'

Remove feature flags used for utilizing load balancing capabilities in UserRefreshOverUserRangeWorker [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!63280
parents 3628bf4a dd5830e7
# frozen_string_literal: true
module AuthorizedProjectUpdate
class RecalculateForUserRangeService
def initialize(start_user_id, end_user_id)
@start_user_id = start_user_id
@end_user_id = end_user_id
end
def execute
User.where(id: start_user_id..end_user_id).select(:id).find_each do |user| # rubocop: disable CodeReuse/ActiveRecord
Users::RefreshAuthorizedProjectsService.new(user, source: self.class.name).execute
end
end
private
attr_reader :start_user_id, :end_user_id
end
end
...@@ -2,10 +2,9 @@ ...@@ -2,10 +2,9 @@
module AuthorizedProjectUpdate module AuthorizedProjectUpdate
class UserRefreshOverUserRangeWorker # rubocop:disable Scalability/IdempotentWorker class UserRefreshOverUserRangeWorker # rubocop:disable Scalability/IdempotentWorker
# When the feature flag named `periodic_project_authorization_update_via_replica` is enabled, # This worker checks if users requires an update to their project_authorizations records.
# this worker checks if a specific user requires an update to their project_authorizations records.
# This check is done via the data read from the database replica (and not from the primary). # This check is done via the data read from the database replica (and not from the primary).
# If this check returns true, a completely new Sidekiq job is enqueued for this specific user # If this check returns true, a completely new Sidekiq job is enqueued for a specific user
# so as to update its project_authorizations records. # so as to update its project_authorizations records.
# There is a possibility that the data in the replica is lagging behind the primary # There is a possibility that the data in the replica is lagging behind the primary
...@@ -24,27 +23,16 @@ module AuthorizedProjectUpdate ...@@ -24,27 +23,16 @@ 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: :delayed_consistency_for_user_refresh_over_range_worker data_consistency :delayed
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)
User.where(id: start_user_id..end_user_id).find_each do |user| # rubocop: disable CodeReuse/ActiveRecord User.where(id: start_user_id..end_user_id).find_each do |user| # rubocop: disable CodeReuse/ActiveRecord
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
use_primary_database
AuthorizedProjectUpdate::RecalculateForUserRangeService.new(start_user_id, end_user_id).execute
end
end end
private private
def use_primary_database
if ::Gitlab::Database::LoadBalancing.enable?
::Gitlab::Database::LoadBalancing::Session.current.use_primary!
end
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
......
---
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
---
name: periodic_project_authorization_update_via_replica
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/58752
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/327092
milestone: '13.11'
type: development
group: group::access
default_enabled: false
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::RecalculateForUserRangeService do
describe '#execute' do
let_it_be(:users) { create_list(:user, 2) }
it 'calls Users::RefreshAuthorizedProjectsService' do
user_ids = users.map(&:id)
User.where(id: user_ids).select(:id).each do |user|
expect(Users::RefreshAuthorizedProjectsService).to(
receive(:new).with(user, source: described_class.name).and_call_original)
end
range = user_ids.minmax
described_class.new(*range).execute
end
end
end
...@@ -12,15 +12,9 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do ...@@ -12,15 +12,9 @@ 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: :delayed_consistency_for_user_refresh_over_range_worker,
data_consistency: :delayed data_consistency: :delayed
describe '#perform' do describe '#perform' do
context 'when the feature flag `periodic_project_authorization_update_via_replica` is enabled' do
before do
stub_feature_flags(periodic_project_authorization_update_via_replica: true)
end
context 'checks if project authorization update is required' do context 'checks if project authorization update is required' do
it 'checks if a project_authorization refresh is needed for each of the users' do it 'checks if a project_authorization refresh is needed for each of the users' do
User.where(id: start_user_id..end_user_id).each do |user| User.where(id: start_user_id..end_user_id).each do |user|
...@@ -52,31 +46,4 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do ...@@ -52,31 +46,4 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
end end
end end
end end
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
it 'calls AuthorizedProjectUpdate::RecalculateForUserRangeService' do
expect_next_instance_of(AuthorizedProjectUpdate::RecalculateForUserRangeService, start_user_id, end_user_id) do |service|
expect(service).to receive(:execute)
end
execute_worker
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 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