Disable MessageBus's keepalive when Redis is readonly.

This commit is contained in:
Guo Xiang Tan 2017-08-01 23:07:52 +09:00
parent bd0efb8525
commit 7d5b6e2b3c
2 changed files with 11 additions and 1 deletions

View File

@ -15,6 +15,7 @@ class DiscourseRedis
@mutex = Mutex.new
@slave_config = DiscourseRedis.slave_config
@timer_task = init_timer_task
@message_bus_keepalive_interval = MessageBus.keepalive_interval
end
def verify_master
@ -41,6 +42,7 @@ class DiscourseRedis
slave_client.call([:client, [:kill, 'type', connection_type]])
end
MessageBus.keepalive_interval = @message_bus_keepalive_interval
Discourse.clear_readonly!
Discourse.request_refresh!
success = true
@ -57,7 +59,12 @@ class DiscourseRedis
end
def master=(args)
synchronize { @master = args }
synchronize do
@master = args
# Disables MessageBus keepalive when Redis is in readonly mode
MessageBus.keepalive_interval = 0 if !@master
end
end
def running?

View File

@ -99,7 +99,9 @@ describe DiscourseRedis do
it 'should return the right value if the master server is still down' do
fallback_handler.master = false
Redis::Client.any_instance.expects(:call).with([:info]).returns("Some other stuff")
expect(fallback_handler.initiate_fallback_to_master).to eq(false)
expect(MessageBus.keepalive_interval).to eq(0)
end
it 'should fallback to the master server once it is up' do
@ -113,6 +115,7 @@ describe DiscourseRedis do
expect(fallback_handler.initiate_fallback_to_master).to eq(true)
expect(fallback_handler.master).to eq(true)
expect(Discourse.recently_readonly?).to eq(false)
expect(MessageBus.keepalive_interval).to eq(-1)
end
end
end