Commit 720f0214 authored by nmilojevic1's avatar nmilojevic1

Add reviewer suggestions

- Fix naming
parent a42396a0
......@@ -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
......
......@@ -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)
......
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