mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
DEV: Add ENV flag to test out ActiveRecord::Failover
.
This commit is contained in:
parent
0854785175
commit
8c86a109bb
2
Gemfile
2
Gemfile
|
@ -249,4 +249,4 @@ gem 'webpush', require: false
|
|||
gem 'colored2', require: false
|
||||
gem 'maxminddb'
|
||||
|
||||
gem 'rails_failover', require: false
|
||||
gem 'rails_failover', require: false, git: 'https://github.com/discourse/rails_failover'
|
||||
|
|
13
Gemfile.lock
13
Gemfile.lock
|
@ -1,3 +1,12 @@
|
|||
GIT
|
||||
remote: https://github.com/discourse/rails_failover
|
||||
revision: ba904987444b96a3fb627ed0b145059ff9f1cf6c
|
||||
specs:
|
||||
rails_failover (0.4.0)
|
||||
activerecord (~> 6.0)
|
||||
listen (~> 3.2)
|
||||
railties (~> 6.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
|
@ -277,8 +286,6 @@ GEM
|
|||
nokogiri (>= 1.6)
|
||||
rails-html-sanitizer (1.3.0)
|
||||
loofah (~> 2.3)
|
||||
rails_failover (0.2.0)
|
||||
redis (~> 4)
|
||||
rails_multisite (2.1.2)
|
||||
activerecord (> 5.0, < 7)
|
||||
railties (> 5.0, < 7)
|
||||
|
@ -514,7 +521,7 @@ DEPENDENCIES
|
|||
rack (= 2.2.2)
|
||||
rack-mini-profiler
|
||||
rack-protection
|
||||
rails_failover
|
||||
rails_failover!
|
||||
rails_multisite
|
||||
railties (= 6.0.3)
|
||||
rake
|
||||
|
|
|
@ -134,7 +134,11 @@ class GlobalSetting
|
|||
end
|
||||
end
|
||||
|
||||
hash["adapter"] = "postgresql_fallback" if hash["replica_host"]
|
||||
if hash["replica_host"]
|
||||
if !ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
|
||||
hash["adapter"] = "postgresql_fallback"
|
||||
end
|
||||
end
|
||||
|
||||
hostnames = [ hostname ]
|
||||
hostnames << backup_hostname if backup_hostname.present?
|
||||
|
@ -165,15 +169,9 @@ class GlobalSetting
|
|||
c[:port] = redis_port if redis_port
|
||||
|
||||
if redis_slave_host && redis_slave_port
|
||||
if ENV["RAILS_FAILOVER"]
|
||||
c[:replica_host] = redis_slave_host
|
||||
c[:replica_port] = redis_slave_port
|
||||
c[:connector] = RailsFailover::Redis::Connector
|
||||
else
|
||||
c[:slave_host] = redis_slave_host
|
||||
c[:slave_port] = redis_slave_port
|
||||
c[:connector] = DiscourseRedis::Connector
|
||||
end
|
||||
c[:slave_host] = redis_slave_host
|
||||
c[:slave_port] = redis_slave_port
|
||||
c[:connector] = DiscourseRedis::Connector
|
||||
end
|
||||
|
||||
c[:password] = redis_password if redis_password.present?
|
||||
|
@ -195,15 +193,9 @@ class GlobalSetting
|
|||
c[:port] = message_bus_redis_port if message_bus_redis_port
|
||||
|
||||
if message_bus_redis_slave_host && message_bus_redis_slave_port
|
||||
if ENV["RAILS_FAILOVER"]
|
||||
c[:replica_host] = message_bus_redis_slave_host
|
||||
c[:replica_port] = message_bus_redis_slave_port
|
||||
c[:connector] = RailsFailover::Redis::Connector
|
||||
else
|
||||
c[:slave_host] = message_bus_redis_slave_host
|
||||
c[:slave_port] = message_bus_redis_slave_port
|
||||
c[:connector] = DiscourseRedis::Connector
|
||||
end
|
||||
c[:slave_host] = message_bus_redis_slave_host
|
||||
c[:slave_port] = message_bus_redis_slave_port
|
||||
c[:connector] = DiscourseRedis::Connector
|
||||
end
|
||||
|
||||
c[:password] = message_bus_redis_password if message_bus_redis_password.present?
|
||||
|
|
|
@ -27,8 +27,8 @@ require_relative '../lib/discourse_plugin_registry'
|
|||
|
||||
require_relative '../lib/plugin_gem'
|
||||
|
||||
if ENV['RAILS_FAILOVER']
|
||||
require 'rails_failover'
|
||||
if ENV['ACTIVE_RECORD_RAILS_FAILOVER']
|
||||
require 'rails_failover/active_record'
|
||||
end
|
||||
|
||||
# Global config
|
||||
|
|
|
@ -4,18 +4,3 @@ if Rails.env.development? && ENV['DISCOURSE_FLUSH_REDIS']
|
|||
puts "Flushing redis (development mode)"
|
||||
Discourse.redis.flushdb
|
||||
end
|
||||
|
||||
if ENV['RAILS_FAILOVER']
|
||||
message_bus_keepalive_interval = MessageBus.keepalive_interval
|
||||
|
||||
RailsFailover::Redis.register_master_up_callback do
|
||||
MessageBus.keepalive_interval = message_bus_keepalive_interval
|
||||
Discourse.clear_readonly!
|
||||
Discourse.request_refresh!
|
||||
end
|
||||
|
||||
RailsFailover::Redis.register_master_down_callback do
|
||||
# Disables MessageBus keepalive when Redis is in readonly mode
|
||||
MessageBus.keepalive_interval = 0
|
||||
end
|
||||
end
|
||||
|
|
17
config/initializers/002-rails_failover.rb
Normal file
17
config/initializers/002-rails_failover.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
if ENV["ACTIVE_RECORD_RAILS_FAILOVER"]
|
||||
RailsFailover::ActiveRecord.on_failover do
|
||||
Discourse.enable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
|
||||
Sidekiq.pause!("pg_failover") if !Sidekiq.paused?
|
||||
end
|
||||
|
||||
RailsFailover::ActiveRecord.on_fallback do
|
||||
Discourse.disable_readonly_mode(Discourse::PG_READONLY_MODE_KEY)
|
||||
Sidekiq.unpause!
|
||||
end
|
||||
|
||||
RailsFailover::ActiveRecord.register_force_reading_role_callback do
|
||||
Discourse.pg_readonly_mode?
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user