Commit 3f079524 authored by Quang-Minh Nguyen's avatar Quang-Minh Nguyen

Force with_fast_statement_timeout to use replicas

parent e1b019bf
......@@ -52,13 +52,15 @@ class ApplicationRecord < ActiveRecord::Base
# Start a new transaction with a shorter-than-usual statement timeout. This is
# currently one third of the default 15-second timeout
def self.with_fast_statement_timeout
def self.with_fast_read_statement_timeout
::Gitlab::Database::LoadBalancing::Session.current.use_replica do
transaction(requires_new: true) do
connection.exec_query("SET LOCAL statement_timeout = 5000")
yield
end
end
end
def self.safe_find_or_create_by(*args, &block)
safe_ensure_unique(retries: 1) do
......
......@@ -78,7 +78,7 @@ module Gitlab
# to perform the calculation more efficiently. Until then, use a shorter
# timeout and return -1 as a sentinel value if it is triggered
begin
ApplicationRecord.with_fast_statement_timeout do
ApplicationRecord.with_fast_read_statement_timeout do
finder.count_by_state
end
rescue ActiveRecord::QueryCanceled => err
......
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