FIX: Backup/Restore didn't use correct Redis namespace in multisite (#18060)
In a multisite Discourse reported that no backup is running after 60 seconds because the Redis key expired. Also, the thread that listens for a shutdown signal stopped running immediately because it didn't detect a running operation.
This commit is contained in:
parent
935609172a
commit
9ff13cee14
|
@ -144,8 +144,13 @@ module BackupRestore
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.keep_it_running
|
def self.keep_it_running
|
||||||
|
db = RailsMultisite::ConnectionManagement.current_db
|
||||||
|
|
||||||
# extend the expiry by 1 minute every 30 seconds
|
# extend the expiry by 1 minute every 30 seconds
|
||||||
Thread.new do
|
Thread.new do
|
||||||
|
RailsMultisite::ConnectionManagement.with_connection(db) do
|
||||||
|
Thread.current.name = "keep_op_running"
|
||||||
|
|
||||||
# this thread will be killed when the fork dies
|
# this thread will be killed when the fork dies
|
||||||
while true
|
while true
|
||||||
Discourse.redis.expire(running_key, 1.minute)
|
Discourse.redis.expire(running_key, 1.minute)
|
||||||
|
@ -153,6 +158,7 @@ module BackupRestore
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.shutdown_signal_key
|
def self.shutdown_signal_key
|
||||||
"backup_restore_operation_should_shutdown"
|
"backup_restore_operation_should_shutdown"
|
||||||
|
|
|
@ -98,12 +98,16 @@ module BackupRestore
|
||||||
BackupRestore.clear_shutdown_signal!
|
BackupRestore.clear_shutdown_signal!
|
||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
|
Thread.current.name = "shutdown_wait"
|
||||||
|
|
||||||
|
RailsMultisite::ConnectionManagement.with_connection(@current_db) do
|
||||||
while BackupRestore.is_operation_running?
|
while BackupRestore.is_operation_running?
|
||||||
exit if BackupRestore.should_shutdown?
|
exit if BackupRestore.should_shutdown?
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def mark_backup_as_running
|
def mark_backup_as_running
|
||||||
log "Marking backup as running..."
|
log "Marking backup as running..."
|
||||||
|
|
|
@ -47,12 +47,16 @@ module BackupRestore
|
||||||
BackupRestore.clear_shutdown_signal!
|
BackupRestore.clear_shutdown_signal!
|
||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
|
Thread.current.name = "shutdown_wait"
|
||||||
|
|
||||||
|
RailsMultisite::ConnectionManagement.with_connection(@current_db) do
|
||||||
while BackupRestore.is_operation_running?
|
while BackupRestore.is_operation_running?
|
||||||
exit if BackupRestore.should_shutdown?
|
exit if BackupRestore.should_shutdown?
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def pause_sidekiq(reason)
|
def pause_sidekiq(reason)
|
||||||
return if Sidekiq.paused?
|
return if Sidekiq.paused?
|
||||||
|
|
|
@ -36,4 +36,21 @@ RSpec.describe BackupRestore::SystemInterface, type: :multisite do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#listen_for_shutdown_signal" do
|
||||||
|
it "uses the correct Redis namespace" do
|
||||||
|
test_multisite_connection("second") do
|
||||||
|
BackupRestore.mark_as_running!
|
||||||
|
|
||||||
|
expect do
|
||||||
|
thread = subject.listen_for_shutdown_signal
|
||||||
|
BackupRestore.set_shutdown_signal!
|
||||||
|
thread.join
|
||||||
|
end.to raise_error(SystemExit)
|
||||||
|
|
||||||
|
BackupRestore.clear_shutdown_signal!
|
||||||
|
BackupRestore.mark_as_not_running!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue