Improve FileGcParameters field names.

This commit is contained in:
levlam 2021-12-11 23:03:11 +03:00
parent 6bd7e04875
commit 5801d6c695
4 changed files with 42 additions and 42 deletions

View File

@ -117,8 +117,8 @@ void StorageManager::run_gc(FileGcParameters parameters, bool return_deleted_fil
close_gc_worker();
}
bool split_by_owner_dialog_id = !parameters.owner_dialog_ids.empty() ||
!parameters.exclude_owner_dialog_ids.empty() || parameters.dialog_limit != 0;
bool split_by_owner_dialog_id = !parameters.owner_dialog_ids_.empty() ||
!parameters.exclude_owner_dialog_ids_.empty() || parameters.dialog_limit_ != 0;
get_storage_stats(
true /*need_all_files*/, split_by_owner_dialog_id,
PromiseCreator::lambda(
@ -156,7 +156,7 @@ void StorageManager::create_stats_worker() {
}
void StorageManager::on_all_files(FileGcParameters gc_parameters, Result<FileStats> r_file_stats) {
int32 dialog_limit = gc_parameters.dialog_limit;
int32 dialog_limit = gc_parameters.dialog_limit_;
if (is_closed_ && r_file_stats.is_ok()) {
r_file_stats = Global::request_aborted_error();
}

View File

@ -17,32 +17,32 @@ namespace td {
FileGcParameters::FileGcParameters(int64 size, int32 ttl, int32 count, int32 immunity_delay,
vector<FileType> file_types, vector<DialogId> owner_dialog_ids,
vector<DialogId> exclude_owner_dialog_ids, int32 dialog_limit)
: file_types(std::move(file_types))
, owner_dialog_ids(std::move(owner_dialog_ids))
, exclude_owner_dialog_ids(std::move(exclude_owner_dialog_ids))
, dialog_limit(dialog_limit) {
: file_types_(std::move(file_types))
, owner_dialog_ids_(std::move(owner_dialog_ids))
, exclude_owner_dialog_ids_(std::move(exclude_owner_dialog_ids))
, dialog_limit_(dialog_limit) {
auto &config = G()->shared_config();
this->max_files_size = size >= 0 ? size : config.get_option_integer("storage_max_files_size", 100 << 10) << 10;
max_files_size_ = size >= 0 ? size : config.get_option_integer("storage_max_files_size", 100 << 10) << 10;
this->max_time_from_last_access =
max_time_from_last_access_ =
ttl >= 0 ? ttl : narrow_cast<int32>(config.get_option_integer("storage_max_time_from_last_access", 60 * 60 * 23));
this->max_file_count =
count >= 0 ? count : narrow_cast<int32>(config.get_option_integer("storage_max_file_count", 40000));
max_file_count_ = count >= 0 ? count : narrow_cast<int32>(config.get_option_integer("storage_max_file_count", 40000));
this->immunity_delay = immunity_delay >= 0
? immunity_delay
: narrow_cast<int32>(config.get_option_integer("storage_immunity_delay", 60 * 60));
immunity_delay_ = immunity_delay >= 0
? immunity_delay
: narrow_cast<int32>(config.get_option_integer("storage_immunity_delay", 60 * 60));
}
StringBuilder &operator<<(StringBuilder &string_builder, const FileGcParameters &parameters) {
return string_builder << "FileGcParameters[" << tag("max_files_size", parameters.max_files_size)
<< tag("max_time_from_last_access", parameters.max_time_from_last_access)
<< tag("max_file_count", parameters.max_file_count)
<< tag("immunity_delay", parameters.immunity_delay) << tag("file_types", parameters.file_types)
<< tag("owner_dialog_ids", parameters.owner_dialog_ids)
<< tag("exclude_owner_dialog_ids", parameters.exclude_owner_dialog_ids)
<< tag("dialog_limit", parameters.dialog_limit) << ']';
return string_builder << "FileGcParameters[" << tag("max_files_size", parameters.max_files_size_)
<< tag("max_time_from_last_access", parameters.max_time_from_last_access_)
<< tag("max_file_count", parameters.max_file_count_)
<< tag("immunity_delay", parameters.immunity_delay_)
<< tag("file_types", parameters.file_types_)
<< tag("owner_dialog_ids", parameters.owner_dialog_ids_)
<< tag("exclude_owner_dialog_ids", parameters.exclude_owner_dialog_ids_)
<< tag("dialog_limit", parameters.dialog_limit_) << ']';
}
} // namespace td

View File

@ -20,16 +20,16 @@ struct FileGcParameters {
FileGcParameters(int64 size, int32 ttl, int32 count, int32 immunity_delay, vector<FileType> file_types,
vector<DialogId> owner_dialog_ids, vector<DialogId> exclude_owner_dialog_ids, int32 dialog_limit);
int64 max_files_size;
uint32 max_time_from_last_access;
uint32 max_file_count;
uint32 immunity_delay;
int64 max_files_size_;
uint32 max_time_from_last_access_;
uint32 max_file_count_;
uint32 immunity_delay_;
vector<FileType> file_types;
vector<DialogId> owner_dialog_ids;
vector<DialogId> exclude_owner_dialog_ids;
vector<FileType> file_types_;
vector<DialogId> owner_dialog_ids_;
vector<DialogId> exclude_owner_dialog_ids_;
int32 dialog_limit;
int32 dialog_limit_;
};
StringBuilder &operator<<(StringBuilder &string_builder, const FileGcParameters &parameters);

View File

@ -47,9 +47,9 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
immune_types[narrow_cast<size_t>(FileType::Background)] = true;
}
if (!parameters.file_types.empty()) {
if (!parameters.file_types_.empty()) {
std::fill(immune_types.begin(), immune_types.end(), true);
for (auto file_type : parameters.file_types) {
for (auto file_type : parameters.file_types_) {
immune_types[narrow_cast<size_t>(file_type)] = false;
}
for (int32 i = 0; i < MAX_FILE_TYPE; i++) {
@ -81,8 +81,8 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
total_size += info.size;
}
FileStats new_stats(false, parameters.dialog_limit != 0);
FileStats removed_stats(false, parameters.dialog_limit != 0);
FileStats new_stats(false, parameters.dialog_limit_ != 0);
FileStats removed_stats(false, parameters.dialog_limit_ != 0);
auto do_remove_file = [&removed_stats](const FullFileInfo &info) {
removed_stats.add_copy(info);
@ -105,24 +105,24 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
new_stats.add_copy(info);
return true;
}
if (td::contains(parameters.exclude_owner_dialog_ids, info.owner_dialog_id)) {
if (td::contains(parameters.exclude_owner_dialog_ids_, info.owner_dialog_id)) {
exclude_owner_dialog_id_ignored_cnt++;
new_stats.add_copy(info);
return true;
}
if (!parameters.owner_dialog_ids.empty() && !td::contains(parameters.owner_dialog_ids, info.owner_dialog_id)) {
if (!parameters.owner_dialog_ids_.empty() && !td::contains(parameters.owner_dialog_ids_, info.owner_dialog_id)) {
owner_dialog_id_ignored_cnt++;
new_stats.add_copy(info);
return true;
}
if (static_cast<double>(info.mtime_nsec) * 1e-9 > now - parameters.immunity_delay) {
if (static_cast<double>(info.mtime_nsec) * 1e-9 > now - parameters.immunity_delay_) {
// new files are immune to gc
time_immunity_ignored_cnt++;
new_stats.add_copy(info);
return true;
}
if (static_cast<double>(info.atime_nsec) * 1e-9 < now - parameters.max_time_from_last_access) {
if (static_cast<double>(info.atime_nsec) * 1e-9 < now - parameters.max_time_from_last_access_) {
do_remove_file(info);
total_removed_size += info.size;
remove_by_atime_cnt++;
@ -137,13 +137,13 @@ void FileGcWorker::run_gc(const FileGcParameters &parameters, std::vector<FullFi
// sort by max(atime, mtime)
std::sort(files.begin(), files.end(), [](const auto &a, const auto &b) { return a.atime_nsec < b.atime_nsec; });
// 1. Total size must be less than parameters.max_files_size
// 2. Total file count must be less than parameters.max_file_count
// 1. Total size must be less than parameters.max_files_size_
// 2. Total file count must be less than parameters.max_file_count_
size_t remove_count = 0;
if (files.size() > parameters.max_file_count) {
remove_count = files.size() - parameters.max_file_count;
if (files.size() > parameters.max_file_count_) {
remove_count = files.size() - parameters.max_file_count_;
}
int64 remove_size = -parameters.max_files_size;
int64 remove_size = -parameters.max_files_size_;
for (auto &file : files) {
remove_size += file.size;
}