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