Commit 010bc43f authored by Gabriel Mazetto's avatar Gabriel Mazetto

Adds `USE_NEW_LOAD_BALANCER_QUERY` ENV feature flag

This new flag allows to switch to the new query that can work in
patroni standby cluster, querying the leader as the "primary" equivalent
parent 98d6eb28
...@@ -259,18 +259,25 @@ module Gitlab ...@@ -259,18 +259,25 @@ module Gitlab
# @param [ActiveRecord::Connection] ar_connection # @param [ActiveRecord::Connection] ar_connection
# @return [String] # @return [String]
def self.get_write_location(ar_connection) def self.get_write_location(ar_connection)
row = ar_connection use_new_load_balancer_query = Gitlab::Utils.to_boolean(ENV['USE_NEW_LOAD_BALANCER_QUERY'], default: false)
.select_all(<<~SQL)
SELECT CASE sql = if use_new_load_balancer_query
WHEN pg_is_in_recovery() = true AND EXISTS (SELECT 1 FROM pg_stat_get_wal_senders()) <<~NEWSQL
THEN pg_last_wal_replay_lsn()::text SELECT CASE
WHEN pg_is_in_recovery() = false WHEN pg_is_in_recovery() = true AND EXISTS (SELECT 1 FROM pg_stat_get_wal_senders())
THEN pg_current_wal_insert_lsn()::text THEN pg_last_wal_replay_lsn()::text
ELSE NULL WHEN pg_is_in_recovery() = false
END AS location; THEN pg_current_wal_insert_lsn()::text
ELSE NULL
END AS location;
NEWSQL
else
<<~SQL
SELECT pg_current_wal_insert_lsn()::text AS location
SQL SQL
.first end
row = ar_connection.select_all(sql).first
row['location'] if row row['location'] if row
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