mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 13:31:18 +08:00
FIX: Don't use DistributedCache to store redis readonly state
This can cause unbound CPU usage in some cases, and excessive logging in other cases. This commit moves redis readonly information into the local process, but maintains the DistributedCache for postgres readonly state.
This commit is contained in:

committed by
Guo Xiang Tan

parent
f3e4e6941c
commit
afb5ec811d
@ -219,8 +219,13 @@ describe Discourse do
|
||||
expect(Discourse.readonly_mode?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when Discourse is recently read only" do
|
||||
Discourse.received_readonly!
|
||||
it "returns true when postgres is recently read only" do
|
||||
Discourse.received_postgres_readonly!
|
||||
expect(Discourse.readonly_mode?).to eq(true)
|
||||
end
|
||||
|
||||
it "returns true when redis is recently read only" do
|
||||
Discourse.received_redis_readonly!
|
||||
expect(Discourse.readonly_mode?).to eq(true)
|
||||
end
|
||||
|
||||
@ -234,21 +239,28 @@ describe Discourse do
|
||||
end
|
||||
end
|
||||
|
||||
describe ".received_readonly!" do
|
||||
describe ".received_postgres_readonly!" do
|
||||
it "sets the right time" do
|
||||
time = Discourse.received_readonly!
|
||||
expect(Discourse.last_read_only['default']).to eq(time)
|
||||
time = Discourse.received_postgres_readonly!
|
||||
expect(Discourse.postgres_last_read_only['default']).to eq(time)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".received_redis_readonly!" do
|
||||
it "sets the right time" do
|
||||
time = Discourse.received_redis_readonly!
|
||||
expect(Discourse.redis_last_read_only['default']).to eq(time)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".clear_readonly!" do
|
||||
it "publishes the right message" do
|
||||
Discourse.received_readonly!
|
||||
Discourse.received_postgres_readonly!
|
||||
messages = []
|
||||
|
||||
expect do
|
||||
messages = MessageBus.track_publish { Discourse.clear_readonly! }
|
||||
end.to change { Discourse.last_read_only['default'] }.to(nil)
|
||||
end.to change { Discourse.postgres_last_read_only['default'] }.to(nil)
|
||||
|
||||
expect(messages.any? { |m| m.channel == Site::SITE_JSON_CHANNEL })
|
||||
.to eq(true)
|
||||
|
Reference in New Issue
Block a user