mirror of
https://github.com/discourse/discourse.git
synced 2025-09-04 08:47:37 +08:00
Make PostgreSQL failover work with distributed cache.
This commit is contained in:
parent
989280a222
commit
fe1e78ddf4
4 changed files with 20 additions and 8 deletions
|
@ -7,10 +7,12 @@ class PostgreSQLFallbackHandler
|
|||
include Singleton
|
||||
|
||||
attr_reader :masters_down
|
||||
attr_accessor :initialized
|
||||
|
||||
def initialize
|
||||
@masters_down = DistributedCache.new('masters_down')
|
||||
@masters_down = DistributedCache.new('masters_down', namespace: false)
|
||||
@mutex = Mutex.new
|
||||
@initialized = false
|
||||
end
|
||||
|
||||
def verify_master
|
||||
|
@ -126,13 +128,12 @@ module ActiveRecord
|
|||
else
|
||||
begin
|
||||
connection = postgresql_connection(config)
|
||||
fallback_handler.master_down = false
|
||||
fallback_handler.initialized ||= true
|
||||
rescue PG::ConnectionBad => e
|
||||
on_boot = fallback_handler.master_down?.nil?
|
||||
fallback_handler.master_down = true
|
||||
fallback_handler.verify_master
|
||||
|
||||
if on_boot
|
||||
if !fallback_handler.initialized
|
||||
return postgresql_fallback_connection(config)
|
||||
else
|
||||
raise e
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue