mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FEATURE: Introduce pg_force_readonly_mode GlobalSetting (#19612)
This allows the entire cluster to be forced into pg readonly mode. Equivalent to running `Discourse.enable_pg_force_readonly_mode` on the console.
This commit is contained in:
parent
998c47cf82
commit
5406e24acb
|
@ -365,3 +365,6 @@ preload_link_header = false
|
|||
|
||||
# When using an external upload store, redirect `user_avatar` requests instead of proxying
|
||||
redirect_avatar_requests = false
|
||||
|
||||
# Force the entire cluster into postgres readonly mode. Equivalent to running `Discourse.enable_pg_force_readonly_mode`
|
||||
pg_force_readonly_mode = false
|
||||
|
|
|
@ -69,7 +69,11 @@ if defined?(RailsFailover::ActiveRecord)
|
|||
end
|
||||
|
||||
RailsFailover::ActiveRecord.register_force_reading_role_callback do
|
||||
Discourse.redis.exists?(Discourse::PG_READONLY_MODE_KEY, Discourse::PG_FORCE_READONLY_MODE_KEY)
|
||||
GlobalSetting.pg_force_readonly_mode ||
|
||||
Discourse.redis.exists?(
|
||||
Discourse::PG_READONLY_MODE_KEY,
|
||||
Discourse::PG_FORCE_READONLY_MODE_KEY,
|
||||
)
|
||||
rescue => e
|
||||
if !e.is_a?(Redis::CannotConnectError)
|
||||
Rails.logger.warn "#{e.class} #{e.message}: #{e.backtrace.join("\n")}"
|
||||
|
|
|
@ -691,7 +691,7 @@ module Discourse
|
|||
end
|
||||
|
||||
def self.readonly_mode?(keys = READONLY_KEYS)
|
||||
recently_readonly? || Discourse.redis.exists?(*keys)
|
||||
recently_readonly? || GlobalSetting.pg_force_readonly_mode || Discourse.redis.exists?(*keys)
|
||||
end
|
||||
|
||||
def self.staff_writes_only_mode?
|
||||
|
|
|
@ -300,6 +300,12 @@ RSpec.describe Discourse do
|
|||
Discourse.disable_readonly_mode(user_readonly_mode_key)
|
||||
expect(Discourse.readonly_mode?).to eq(false)
|
||||
end
|
||||
|
||||
it "returns true when forced via global setting" do
|
||||
expect(Discourse.readonly_mode?).to eq(false)
|
||||
global_setting :pg_force_readonly_mode, true
|
||||
expect(Discourse.readonly_mode?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".received_postgres_readonly!" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user