diff --git a/td/telegram/Logging.cpp b/td/telegram/Logging.cpp index 730a576c..c895308b 100644 --- a/td/telegram/Logging.cpp +++ b/td/telegram/Logging.cpp @@ -6,6 +6,7 @@ // #include "td/telegram/Logging.h" +#include "td/telegram/files/FileGcWorker.h" #include "td/telegram/files/FileManager.h" #include "td/telegram/net/ConnectionCreator.h" #include "td/telegram/NotificationManager.h" @@ -33,11 +34,11 @@ static NullLog null_log; #define ADD_TAG(tag) \ { #tag, &VERBOSITY_NAME(tag) } static const std::map log_tags{ - ADD_TAG(td_init), ADD_TAG(update_file), ADD_TAG(connections), ADD_TAG(binlog), - ADD_TAG(proxy), ADD_TAG(net_query), ADD_TAG(td_requests), ADD_TAG(dc), - ADD_TAG(files), ADD_TAG(mtproto), ADD_TAG(raw_mtproto), ADD_TAG(fd), - ADD_TAG(actor), ADD_TAG(buffer), ADD_TAG(sqlite), ADD_TAG(notifications), - ADD_TAG(get_difference)}; + ADD_TAG(td_init), ADD_TAG(update_file), ADD_TAG(connections), ADD_TAG(binlog), + ADD_TAG(proxy), ADD_TAG(net_query), ADD_TAG(td_requests), ADD_TAG(dc), + ADD_TAG(files), ADD_TAG(mtproto), ADD_TAG(raw_mtproto), ADD_TAG(fd), + ADD_TAG(actor), ADD_TAG(buffer), ADD_TAG(sqlite), ADD_TAG(notifications), + ADD_TAG(get_difference), ADD_TAG(file_gc)}; #undef ADD_TAG Status Logging::set_current_stream(td_api::object_ptr stream) { diff --git a/td/telegram/files/FileGcParameters.cpp b/td/telegram/files/FileGcParameters.cpp index 7b949d73..500a3b18 100644 --- a/td/telegram/files/FileGcParameters.cpp +++ b/td/telegram/files/FileGcParameters.cpp @@ -9,7 +9,10 @@ #include "td/telegram/ConfigShared.h" #include "td/telegram/Global.h" +#include "td/utils/format.h" + namespace td { + FileGcParameters::FileGcParameters(int64 size, int32 ttl, int32 count, int32 immunity_delay, vector file_types, vector owner_dialog_ids, vector exclude_owner_dialog_ids, int32 dialog_limit) @@ -29,4 +32,15 @@ FileGcParameters::FileGcParameters(int64 size, int32 ttl, int32 count, int32 imm this->immunity_delay = immunity_delay >= 0 ? immunity_delay : config.get_option_integer("storage_immunity_delay", 60 * 60); } + +StringBuilder &operator<<(StringBuilder &string_builder, const FileGcParameters ¶meters) { + 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 diff --git a/td/telegram/files/FileGcParameters.h b/td/telegram/files/FileGcParameters.h index a0c3c355..b4276b1d 100644 --- a/td/telegram/files/FileGcParameters.h +++ b/td/telegram/files/FileGcParameters.h @@ -10,6 +10,7 @@ #include "td/telegram/files/FileLocation.h" #include "td/utils/common.h" +#include "td/utils/StringBuilder.h" namespace td { @@ -31,4 +32,6 @@ struct FileGcParameters { int32 dialog_limit; }; +StringBuilder &operator<<(StringBuilder &string_builder, const FileGcParameters ¶meters); + } // namespace td diff --git a/td/telegram/files/FileGcWorker.cpp b/td/telegram/files/FileGcWorker.cpp index 35dce38e..eb568b2c 100644 --- a/td/telegram/files/FileGcWorker.cpp +++ b/td/telegram/files/FileGcWorker.cpp @@ -20,6 +20,9 @@ #include namespace td { + +int VERBOSITY_NAME(file_gc) = VERBOSITY_NAME(INFO); + void FileGcWorker::do_remove_file(const FullFileInfo &info) { // LOG(WARNING) << "Gc remove file: " << tag("path", file) << tag("mtime", stat.mtime_nsec_ / 1000000000) // << tag("atime", stat.atime_nsec_ / 1000000000); @@ -33,7 +36,7 @@ void FileGcWorker::do_remove_file(const FullFileInfo &info) { void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector files, Promise promise) { auto begin_time = Time::now(); - LOG(INFO) << "Start files gc"; + VLOG(file_gc) << "Start files gc with " << parameters; // quite stupid implementations // needs a lot of memory // may write something more clever, but i will need at least 2 passes over the files @@ -160,14 +163,15 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector parent) : parent_(std::move(parent)) { diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index 944312da..cdfec22c 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -134,7 +134,15 @@ inline tl_object_ptr as_td_api(FileType file_type) { } } +constexpr int32 file_type_size = static_cast(FileType::Size); +extern const char *file_type_name[file_type_size]; + +inline StringBuilder &operator<<(StringBuilder &string_builder, FileType file_type) { + return string_builder << file_type_name[static_cast(file_type)]; +} + enum class FileDirType : int8 { Secure, Common }; + inline FileDirType get_file_dir_type(FileType file_type) { switch (file_type) { case FileType::Thumbnail: @@ -152,9 +160,6 @@ inline FileDirType get_file_dir_type(FileType file_type) { } } -constexpr int32 file_type_size = static_cast(FileType::Size); -extern const char *file_type_name[file_type_size]; - struct FileEncryptionKey { enum class Type : int32 { None, Secret, Secure }; FileEncryptionKey() = default; @@ -786,7 +791,7 @@ class FullRemoteFileLocation { inline StringBuilder &operator<<(StringBuilder &string_builder, const FullRemoteFileLocation &full_remote_file_location) { - string_builder << "[" << file_type_name[static_cast(full_remote_file_location.file_type_)]; + string_builder << "[" << full_remote_file_location.file_type_; if (!full_remote_file_location.is_web()) { string_builder << ", " << full_remote_file_location.get_dc_id(); } @@ -987,7 +992,7 @@ inline bool operator!=(const FullLocalFileLocation &lhs, const FullLocalFileLoca } inline StringBuilder &operator<<(StringBuilder &sb, const FullLocalFileLocation &location) { - return sb << "[" << file_type_name[static_cast(location.file_type_)] << "] at \"" << location.path_ << '"'; + return sb << '[' << location.file_type_ << "] at \"" << location.path_ << '"'; } class LocalFileLocation { @@ -1120,10 +1125,9 @@ inline bool operator!=(const FullGenerateFileLocation &lhs, const FullGenerateFi inline StringBuilder &operator<<(StringBuilder &string_builder, const FullGenerateFileLocation &full_generated_file_location) { - return string_builder << "[" - << tag("file_type", file_type_name[static_cast(full_generated_file_location.file_type_)]) + return string_builder << '[' << tag("file_type", full_generated_file_location.file_type_) << tag("original_path", full_generated_file_location.original_path_) - << tag("conversion", full_generated_file_location.conversion_) << "]"; + << tag("conversion", full_generated_file_location.conversion_) << ']'; } class GenerateFileLocation { diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 486b4579..61898529 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -2450,7 +2450,7 @@ void FileManager::on_error_impl(FileNodePtr node, FileManager::Query::Type type, }; if (status.code() != 1 && !G()->close_flag()) { LOG(WARNING) << "Failed to upload/download/generate file: " << status << ". Query type = " << type - << ". File type is " << file_type_name[static_cast(FileView(node).get_type())]; + << ". File type is " << FileView(node).get_type(); if (status.code() == 0) { // Remove partial locations if (node->local_.type() == LocalFileLocation::Type::Partial && status.message() != "FILE_UPLOAD_RESTART") {