Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
dd5830e7
Commit
dd5830e7
authored
Jun 04, 2021
by
Manoj M J
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Utilize load balancing capabilities for UserRefreshOverUserRangeWorker
Changelog: performance
parent
edb4eaa2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
20 additions
and
122 deletions
+20
-122
app/services/authorized_project_update/recalculate_for_user_range_service.rb
...ized_project_update/recalculate_for_user_range_service.rb
+0
-20
app/workers/authorized_project_update/user_refresh_over_user_range_worker.rb
...zed_project_update/user_refresh_over_user_range_worker.rb
+5
-17
config/feature_flags/development/delayed_consistency_for_user_refresh_over_range_worker.yml
...elayed_consistency_for_user_refresh_over_range_worker.yml
+0
-8
config/feature_flags/development/periodic_project_authorization_update_via_replica.yml
...ent/periodic_project_authorization_update_via_replica.yml
+0
-8
spec/services/authorized_project_update/recalculate_for_user_range_service_spec.rb
...project_update/recalculate_for_user_range_service_spec.rb
+0
-21
spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb
...roject_update/user_refresh_over_user_range_worker_spec.rb
+15
-48
No files found.
app/services/authorized_project_update/recalculate_for_user_range_service.rb
deleted
100644 → 0
View file @
edb4eaa2
# 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
app/workers/authorized_project_update/user_refresh_over_user_range_worker.rb
View file @
dd5830e7
...
@@ -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
else
use_primary_database
AuthorizedProjectUpdate
::
RecalculateForUserRangeService
.
new
(
start_user_id
,
end_user_id
).
execute
end
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
...
...
config/feature_flags/development/delayed_consistency_for_user_refresh_over_range_worker.yml
deleted
100644 → 0
View file @
edb4eaa2
---
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
config/feature_flags/development/periodic_project_authorization_update_via_replica.yml
deleted
100644 → 0
View file @
edb4eaa2
---
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
spec/services/authorized_project_update/recalculate_for_user_range_service_spec.rb
deleted
100644 → 0
View file @
edb4eaa2
# 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
spec/workers/authorized_project_update/user_refresh_over_user_range_worker_spec.rb
View file @
dd5830e7
...
@@ -12,70 +12,37 @@ RSpec.describe AuthorizedProjectUpdate::UserRefreshOverUserRangeWorker do
...
@@ -12,70 +12,37 @@ 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
context
'checks if project authorization update is required'
do
before
do
it
'checks if a project_authorization refresh is needed for each of the users'
do
stub_feature_flags
(
periodic_project_authorization_update_via_replica:
true
)
User
.
where
(
id:
start_user_id
..
end_user_id
).
each
do
|
user
|
end
expect
(
AuthorizedProjectUpdate
::
FindRecordsDueForRefreshService
).
to
(
receive
(
:new
).
with
(
user
).
and_call_original
)
context
'checks if project authorization update is required'
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
|
expect
(
AuthorizedProjectUpdate
::
FindRecordsDueForRefreshService
).
to
(
receive
(
:new
).
with
(
user
).
and_call_original
)
end
execute_worker
end
end
context
'when there are project authorization records due for either removal or addition for a specific user'
do
before
do
user
.
project_authorizations
.
delete_all
end
it
'enqueues a new project authorization update job for the user'
do
expect
(
AuthorizedProjectUpdate
::
UserRefreshWithLowUrgencyWorker
).
to
receive
(
:perform_async
).
with
(
user
.
id
)
execute_worker
end
end
end
context
'when there are no additions or removals to be made to project authorizations for a specific user'
do
it
'does not enqueue a new project authorization update job for the user'
do
expect
(
AuthorizedProjectUpdate
::
UserRefreshWithLowUrgencyWorker
).
not_to
receive
(
:perform_async
)
execute_worker
execute_worker
end
end
end
end
end
context
'when the
feature flag `periodic_project_authorization_update_via_replica` is disabled
'
do
context
'when the
re are project authorization records due for either removal or addition for a specific user
'
do
before
do
before
do
stub_feature_flags
(
periodic_project_authorization_update_via_replica:
false
)
user
.
project_authorizations
.
delete_all
end
end
it
'calls AuthorizedProjectUpdate::RecalculateForUserRangeService'
do
it
'enqueues a new project authorization update job for the user'
do
expect_next_instance_of
(
AuthorizedProjectUpdate
::
RecalculateForUserRangeService
,
start_user_id
,
end_user_id
)
do
|
service
|
expect
(
AuthorizedProjectUpdate
::
UserRefreshWithLowUrgencyWorker
).
to
receive
(
:perform_async
).
with
(
user
.
id
)
expect
(
service
).
to
receive
(
:execute
)
end
execute_worker
execute_worker
end
end
end
context
'when load balancing is enabled'
do
context
'when there are no additions or removals to be made to project authorizations for a specific user'
do
before
do
it
'does not enqueue a new project authorization update job for the user'
do
allow
(
Gitlab
::
Database
::
LoadBalancing
).
to
receive
(
:enable?
).
and_return
(
true
)
expect
(
AuthorizedProjectUpdate
::
UserRefreshWithLowUrgencyWorker
).
not_to
receive
(
:perform_async
)
end
it
'reads from the primary database'
do
expect
(
Gitlab
::
Database
::
LoadBalancing
::
Session
.
current
).
to
receive
(
:use_primary!
)
execute_worker
execute_worker
end
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment