mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 23:36:11 +08:00
FIX: PostgreSQLFallbackHandler
was bouncing in and out of readonly.
This commit is contained in:
@ -39,7 +39,7 @@ class PostgreSQLFallbackHandler
|
||||
end
|
||||
|
||||
Discourse.disable_readonly_mode
|
||||
master = true
|
||||
self.master = true
|
||||
end
|
||||
rescue => e
|
||||
if e.message.include?("could not connect to server")
|
||||
@ -77,6 +77,10 @@ class PostgreSQLFallbackHandler
|
||||
end
|
||||
end
|
||||
|
||||
def verify?
|
||||
!master && !running && !recently_checked?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def config
|
||||
@ -110,7 +114,7 @@ module ActiveRecord
|
||||
fallback_handler = ::PostgreSQLFallbackHandler.instance
|
||||
config = config.symbolize_keys
|
||||
|
||||
if !fallback_handler.master && !fallback_handler.running
|
||||
if fallback_handler.verify?
|
||||
connection = postgresql_connection(config.dup.merge({
|
||||
host: config[:replica_host], port: config[:replica_port]
|
||||
}))
|
||||
@ -148,9 +152,7 @@ module ActiveRecord
|
||||
end
|
||||
|
||||
def switch_back?
|
||||
if !fallback_handler.master && !fallback_handler.running
|
||||
fallback_handler.verify_master
|
||||
end
|
||||
fallback_handler.verify_master if fallback_handler.verify?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user