Skip to content

Commit

Permalink
hotfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Inversion-des committed Sep 10, 2021
1 parent 429a096 commit 5b6e7a7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/Storage/_Storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def add_update(file)
target_dir.upload_from_file(file.abs_path, nil, convert:false)
end
# *too many different errors: HTTPClient::KeepAliveDisconnected, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::ENETUNREACH, Google::Apis::TransmissionError, SocketError
rescue e
rescue StandardError => e
# (<!)
if e.is_a?(Google::Apis::ClientError) && e.message.includes?('storageQuotaExceeded')
raise NoFreeSpace
Expand Down
22 changes: 17 additions & 5 deletions app/Storage/_StorageArray.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def add_update(file)
# upload attempts
begin
if storage=possible_storages.shift
w(" (array) add_update to: #{storage.key}")
storage.add_update file
# *update works thanks to hash default proc
files_map[fn].update(
Expand Down Expand Up @@ -178,25 +179,36 @@ def storagesH
end

# if over_used_space — move some files to other storages
def balance_if_needed
def balance_if_needed(tmp_dir:nil, fast_one:nil)
storages.each do |storage|
while storage.used_space > storage.quota
over_used_space = storage.used_space - storage.quota
w(%Q{over_used_space=}+over_used_space.inspect)
w(%Q{over_used_space.hr=}+over_used_space.hr.inspect)
w(%Q{ storage.key=}+ storage.key.inspect)
# find the best file_to_move
file_name_to_move = nil
moved_file_size = nil
min_size_diff = storage.used_space + 1
files_map.each do |some_file_name, some_file|
next if some_file.storage != storage.key # we need only files on this storage
size_diff = (some_file.size - over_used_space).abs
if size_diff < min_size_diff
min_size_diff = size_diff
file_name_to_move = some_file_name
moved_file_size = some_file.size
end
end
file_to_move = get file_name_to_move
# it should find the best next storage and delete from the current one
w(%Q{ file_name_to_move=}+ file_name_to_move.inspect)
w(%Q{ moved_file_size.hr=}+ moved_file_size.hr.inspect)
# *fast_one used here to do not download file from cloud if it is awailable on LocalFS
# *we do not use tmp files if reading from LocalFS
tmp_dir = nil if fast_one.is_a?(Storage::LocalFS)
file_to_move = fast_one.get file_name_to_move, to:tmp_dir
# *it should find the best next storage and delete from the current one
add_update file_to_move

# delete tmp file
file_to_move.del! if tmp_dir
end
end
end
Expand Down Expand Up @@ -263,7 +275,7 @@ def free_space
def update_stats
@db.used = @array.files_map.values.sum{|_| _.storage == @key ? _.size : 0 }
@db.used_MB = (@db.used.to_f / 1.MB).ceil
@db.used_perc = (@db.used.to_f / quota).round(2) if quota < Float::INFINITY
@db.used_perc = (@db.used.to_f / quota * 100).round(1) if quota < Float::INFINITY
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/Sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2419,7 +2419,7 @@ def fast_one

def balance_if_needed
storages.values.each do |_|
_.balance_if_needed if _.is_a? StorageArray
_.balance_if_needed(tmp_dir:@sync.tmp_dir, fast_one:fast_one) if _.is_a? StorageArray
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/app_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ def cmd
dir_path: 'F:/FarDrive_storage',
quota_MB: 700
},
LocalFS_2(
LocalFS_2: {
dir_path: 'G:/FarDrive_storage',
quota_GB: 20
)
}
},
array_2: {
_config: {
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21.09.09
21.09.10

0 comments on commit 5b6e7a7

Please sign in to comment.