FIX: refreshes disk_space on backup create/destroy (#6169)

This commit is contained in:
Joffrey JAFFEUX 2018-07-25 08:26:30 -04:00 committed by GitHub
parent 776fd0de66
commit 578c8e861b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 7 deletions

View File

@ -1,3 +1,5 @@
require 'disk_space'
class Backup
include ActiveModel::SerializerSupport
@ -36,6 +38,7 @@ class Backup
def after_remove_hook
remove_from_s3 if SiteSetting.enable_s3_backups? && !SiteSetting.s3_disable_cleanup?
DiskSpace.reset_cached_stats unless SiteSetting.enable_s3_backups?
end
def s3_bucket

View File

@ -1,3 +1,5 @@
require 'disk_space'
module BackupRestore
class Backuper
@ -276,9 +278,15 @@ module BackupRestore
unpause_sidekiq
disable_readonly_mode if Discourse.readonly_mode?
mark_backup_as_not_running
refresh_disk_space
log "Finished!"
end
def refresh_disk_space
log "Refreshing disk cache..."
DiskSpace.reset_cached_stats
end
def remove_tar_leftovers
log "Removing '.tar' leftovers..."
Dir["#{@archive_directory}/*.tar"].each { |filename| File.delete(filename) }

View File

@ -2,6 +2,9 @@ class DiskSpace
extend ActionView::Helpers::NumberHelper
DISK_SPACE_STATS_CACHE_KEY = 'disk_space_stats'.freeze
DISK_SPACE_STATS_UPDATED_CACHE_KEY = 'disk_space_stats_updated'.freeze
def self.uploads_used_bytes
# used(uploads_path)
# temporary (on our internal setup its just too slow to iterate)
@ -37,25 +40,36 @@ class DiskSpace
}
end
def self.reset_cached_stats
$redis.del(DISK_SPACE_STATS_UPDATED_CACHE_KEY)
$redis.del(DISK_SPACE_STATS_CACHE_KEY)
compute_disk_space
end
def self.cached_stats
stats = $redis.get('disk_space_stats')
updated_at = $redis.get('disk_space_stats_updated')
stats = $redis.get(DISK_SPACE_STATS_CACHE_KEY)
updated_at = $redis.get(DISK_SPACE_STATS_UPDATED_CACHE_KEY)
unless updated_at && (Time.now.to_i - updated_at.to_i) < 30.minutes
Scheduler::Defer.later "updated stats" do
$redis.set('disk_space_stats_updated', Time.now.to_i)
$redis.set('disk_space_stats', self.stats.to_json)
end
compute_disk_space
end
if stats
JSON.parse(stats)
end
end
protected
def self.compute_disk_space
Scheduler::Defer.later 'updated stats' do
$redis.set(DISK_SPACE_STATS_CACHE_KEY, self.stats.to_json)
$redis.set(DISK_SPACE_STATS_UPDATED_CACHE_KEY, Time.now.to_i)
end
nil
end
def self.free(path)
`df -Pk #{path} | awk 'NR==2 {print $4;}'`.to_i * 1024
end