2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Database
|
|
|
|
##
|
|
|
|
# This class is used to make it possible to ensure read consistency in
|
2021-09-04 01:27:46 +05:30
|
|
|
# GitLab without the need of overriding a lot of methods / classes /
|
2021-03-11 19:13:27 +05:30
|
|
|
# classs.
|
|
|
|
#
|
|
|
|
class Consistency
|
|
|
|
##
|
2021-09-04 01:27:46 +05:30
|
|
|
# Within the block, disable the database load balancing for calls that
|
|
|
|
# require read consistency after recent writes.
|
2021-03-11 19:13:27 +05:30
|
|
|
#
|
|
|
|
def self.with_read_consistency(&block)
|
2021-09-04 01:27:46 +05:30
|
|
|
::Gitlab::Database::LoadBalancing::Session
|
|
|
|
.current.use_primary(&block)
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|