From a1c13eb3c63d569f1ac6efa6a6eccf9b0a52cab4 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 9 Jun 2020 16:36:04 +0800 Subject: [PATCH] DEV: Redis failover should only clear redis recently readonly. --- config/initializers/002-rails_failover.rb | 2 +- lib/discourse.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/initializers/002-rails_failover.rb b/config/initializers/002-rails_failover.rb index 72df0c99171..d53451bc4ce 100644 --- a/config/initializers/002-rails_failover.rb +++ b/config/initializers/002-rails_failover.rb @@ -10,7 +10,7 @@ if ENV["REDIS_RAILS_FAILOVER"] end RailsFailover::Redis.on_fallback do - Discourse.clear_readonly! + Discourse.clear_redis_readonly! Discourse.request_refresh! MessageBus.keepalive_interval = message_bus_keepalive_interval end diff --git a/lib/discourse.rb b/lib/discourse.rb index c46d91e3625..67ac64c2972 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -518,12 +518,21 @@ module Discourse postgres_last_read_only[Discourse.redis.namespace] = Time.zone.now end + def self.clear_postgres_readonly! + postgres_last_read_only[Discourse.redis.namespace] = nil + end + def self.received_redis_readonly! redis_last_read_only[Discourse.redis.namespace] = Time.zone.now end + def self.clear_redis_readonly! + redis_last_read_only[Discourse.redis.namespace] = nil + end + def self.clear_readonly! - postgres_last_read_only[Discourse.redis.namespace] = redis_last_read_only[Discourse.redis.namespace] = nil + clear_redis_readonly! + clear_postgres_readonly! Site.clear_anon_cache! true end