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
720f0214
Commit
720f0214
authored
Sep 02, 2021
by
nmilojevic1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reviewer suggestions
- Fix naming
parent
a42396a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
lib/gitlab/database/load_balancing/sidekiq_client_middleware.rb
...tlab/database/load_balancing/sidekiq_client_middleware.rb
+9
-6
lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb
...tlab/database/load_balancing/sidekiq_server_middleware.rb
+2
-2
No files found.
lib/gitlab/database/load_balancing/sidekiq_client_middleware.rb
View file @
720f0214
...
...
@@ -4,6 +4,8 @@ module Gitlab
module
Database
module
LoadBalancing
class
SidekiqClientMiddleware
include
Gitlab
::
Utils
::
StrongMemoize
def
call
(
worker_class
,
job
,
_queue
,
_redis_pool
)
# Mailers can't be constantized
worker_class
=
worker_class
.
to_s
.
safe_constantize
...
...
@@ -35,15 +37,16 @@ module Gitlab
#
# TODO: Replace hardcoded database config name :main when we merge unification strategy
# https://gitlab.com/gitlab-org/gitlab/-/issues/336566
wal_location
=
calculate_wal_location
job
[
'wal_locations'
]
=
{
main:
wal_location
}
if
wal_location
end
def
calculate_wal_location
if
Session
.
current
.
use_primary?
load_balancer
.
primary_write_location
else
load_balancer
.
host
.
database_replica_location
def
wal_location
strong_memoize
(
:wal_location
)
do
if
Session
.
current
.
use_primary?
load_balancer
.
primary_write_location
else
load_balancer
.
host
.
database_replica_location
end
end
end
...
...
lib/gitlab/database/load_balancing/sidekiq_server_middleware.rb
View file @
720f0214
...
...
@@ -44,7 +44,7 @@ module Gitlab
return
:primary_no_wal
unless
wal_locations
if
all_replica_caught_up?
(
wal_locations
)
if
all_
databases_has_
replica_caught_up?
(
wal_locations
)
# Happy case: we can read from a replica.
retried_before?
(
worker_class
,
job
)
?
:replica_retried
:
:replica
elsif
can_retry?
(
worker_class
,
job
)
...
...
@@ -89,7 +89,7 @@ module Gitlab
job
[
'retry_count'
].
nil?
end
def
all_replica_caught_up?
(
wal_locations
)
def
all_
databases_has_
replica_caught_up?
(
wal_locations
)
wal_locations
.
all?
do
|
_config_name
,
location
|
# Once we add support for multiple databases to our load balancer, we would use something like this:
# Gitlab::Database::DATABASES[config_name].load_balancer.select_up_to_date_host(location)
...
...
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