mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
FIX: Don't treat master as up if it is still loading data.
This commit is contained in:
parent
9375dcb6fe
commit
fbbcde1230
|
@ -98,8 +98,8 @@ class DiscourseRedis
|
|||
options = @options.dup
|
||||
options.delete(:connector)
|
||||
client = Redis::Client.new(options)
|
||||
client.call([:role])
|
||||
@options
|
||||
loading = client.call([:info]).split("\r\n").include?("loading:1")
|
||||
loading ? @slave_options : @options
|
||||
rescue Redis::ConnectionError, Redis::CannotConnectError, RuntimeError => ex
|
||||
raise ex if ex.class == RuntimeError && ex.message != "Name or service not known"
|
||||
@fallback_handler.master = false
|
||||
|
|
|
@ -70,6 +70,18 @@ describe DiscourseRedis do
|
|||
end
|
||||
end
|
||||
|
||||
it "should return the slave config when master is still loading data" do
|
||||
begin
|
||||
Redis::Client.any_instance.expects(:call).with([:info]).returns("someconfig:haha\r\nloading:1")
|
||||
config = connector.resolve
|
||||
|
||||
expect(config[:host]).to eq(slave_host)
|
||||
expect(config[:port]).to eq(slave_port)
|
||||
ensure
|
||||
fallback_handler.master = true
|
||||
end
|
||||
end
|
||||
|
||||
it "should raise the right error" do
|
||||
error = RuntimeError.new('test error')
|
||||
Redis::Client.any_instance.expects(:call).raises(error).twice
|
||||
|
|
Loading…
Reference in New Issue
Block a user