From 6e880f7ea0729255edf7e687f61fc7475a6d4dc8 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 16 Mar 2018 15:33:44 +0300 Subject: [PATCH] Enable DelayDispacher. Improve errors and logging. GitOrigin-RevId: e8d648e14183fe4a9409555eff5c6e167b5bcca2 --- td/telegram/DelayDispatcher.cpp | 4 +++- td/telegram/DelayDispatcher.h | 9 ++++++++- td/telegram/files/FileLoader.cpp | 7 ++++--- td/telegram/files/FileManager.cpp | 24 ++++++++++++++++-------- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/td/telegram/DelayDispatcher.cpp b/td/telegram/DelayDispatcher.cpp index 0407401a..d0f2f701 100644 --- a/td/telegram/DelayDispatcher.cpp +++ b/td/telegram/DelayDispatcher.cpp @@ -10,6 +10,7 @@ #include "td/telegram/net/NetQueryDispatcher.h" namespace td { + void DelayDispatcher::send_with_callback(NetQueryPtr query, ActorShared callback) { queue_.push({std::move(query), std::move(callback)}); loop(); @@ -29,7 +30,7 @@ void DelayDispatcher::loop() { queue_.pop(); G()->net_query_dispatcher().dispatch_with_callback(std::move(query.net_query), std::move(query.callback)); - wakeup_at_ = Timestamp::in(DELAY); + wakeup_at_ = Timestamp::in(delay_); if (queue_.empty()) { return; @@ -37,4 +38,5 @@ void DelayDispatcher::loop() { set_timeout_at(wakeup_at_.at()); } + } // namespace td diff --git a/td/telegram/DelayDispatcher.h b/td/telegram/DelayDispatcher.h index fc576c6e..88078016 100644 --- a/td/telegram/DelayDispatcher.h +++ b/td/telegram/DelayDispatcher.h @@ -5,16 +5,22 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #pragma once + #include "td/telegram/net/NetQuery.h" #include "td/actor/actor.h" + #include "td/utils/Time.h" #include namespace td { + class DelayDispatcher : public Actor { public: + explicit DelayDispatcher(double delay) : delay_(delay) { + } + void send_with_callback(NetQueryPtr query, ActorShared callback); private: @@ -24,8 +30,9 @@ class DelayDispatcher : public Actor { }; std::queue queue_; Timestamp wakeup_at_; - static constexpr double DELAY = 0.000; + double delay_; void loop() override; }; + } // namespace td diff --git a/td/telegram/files/FileLoader.cpp b/td/telegram/files/FileLoader.cpp index a8e4e2c2..dd54c12f 100644 --- a/td/telegram/files/FileLoader.cpp +++ b/td/telegram/files/FileLoader.cpp @@ -89,8 +89,8 @@ void FileLoader::start_up() { if (ordered_flag_) { ordered_parts_ = OrderedEventsProcessor>(parts_manager_.get_ready_prefix_count()); } - if (file_info.need_delay && false) { - delay_dispatcher_ = create_actor("DelayDispatcher"); + if (file_info.need_delay) { + delay_dispatcher_ = create_actor("DelayDispatcher", 0.003); } resource_state_.set_unit_size(parts_manager_.get_part_size()); update_estimated_limit(); @@ -131,7 +131,8 @@ Status FileLoader::do_loop() { if (parts_manager_.ready()) { TRY_STATUS(parts_manager_.finish()); TRY_STATUS(on_ok(parts_manager_.get_size())); - LOG(INFO) << "Bad download order rate: " << (100.0 * debug_bad_part_order_ / debug_total_parts_) << "% " + LOG(INFO) << "Bad download order rate: " + << (debug_total_parts_ == 0 ? 0.0 : 100.0 * debug_bad_part_order_ / debug_total_parts_) << "% " << debug_bad_part_order_ << "/" << debug_total_parts_; stop_flag_ = true; return Status::OK(); diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index a0a945ed..a05c9003 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -544,18 +544,21 @@ Status FileManager::check_local_location(FullLocalFileLocation &location, int64 size = stat.size_; } if (location.mtime_nsec_ == 0) { - LOG(INFO) << "Set file modification time to " << stat.mtime_nsec_; + LOG(INFO) << "Set file \"" << location.path_ << "\" modification time to " << stat.mtime_nsec_; location.mtime_nsec_ = stat.mtime_nsec_; } else if (location.mtime_nsec_ != stat.mtime_nsec_) { - LOG(INFO) << "File was nodified: old mtime = " << location.mtime_nsec_ << ", new mtime = " << stat.mtime_nsec_; - return Status::Error("File was modified"); + LOG(INFO) << "File \"" << location.path_ << "\" was nodified: old mtime = " << location.mtime_nsec_ + << ", new mtime = " << stat.mtime_nsec_; + return Status::Error(PSLICE() << "File \"" << location.path_ << "\" was modified"); } if ((location.file_type_ == FileType::Thumbnail || location.file_type_ == FileType::EncryptedThumbnail) && size >= MAX_THUMBNAIL_SIZE) { - return Status::Error(PSLICE() << "File is too big for thumbnail " << tag("size", format::as_size(size))); + return Status::Error(PSLICE() << "File \"" << location.path_ << "\" is too big for thumbnail " + << tag("size", format::as_size(size))); } if (size >= MAX_FILE_SIZE) { - return Status::Error(PSLICE() << "File is too big " << tag("size", format::as_size(size))); + return Status::Error(PSLICE() << "File \"" << location.path_ << "\" is too big " + << tag("size", format::as_size(size))); } return Status::OK(); } @@ -563,6 +566,9 @@ Status FileManager::check_local_location(FullLocalFileLocation &location, int64 static Status check_partial_local_location(const PartialLocalFileLocation &location) { TRY_RESULT(stat, stat(location.path_)); if (!stat.is_reg_) { + if (stat.is_dir_) { + return Status::Error(PSLICE() << "Can't use directory \"" << location.path_ << "\" as a file path"); + } return Status::Error("File must be a regular file"); } // can't check mtime. Hope nobody will mess with this file in our temporary dir. @@ -1262,6 +1268,8 @@ void FileManager::load_from_pmc(FileNodePtr node, bool new_remote, bool new_loca generate = file_view.generate_location(); } + LOG(INFO) << "Load from pmc " << file_id << "/" << file_view.file_id() << ", new_remote = " << new_remote + << ", new_local = " << new_local << ", new_generate = " << new_generate; auto load = [&](auto location) { TRY_RESULT(file_data, file_db_->get_file_data_sync(location)); TRY_RESULT(new_file_id, register_file(std::move(file_data), FileLocationSource::FromDb, "load_from_pmc", false)); @@ -1270,13 +1278,13 @@ void FileManager::load_from_pmc(FileNodePtr node, bool new_remote, bool new_loca return Status::OK(); }; if (new_remote) { - load(remote); + LOG_STATUS(load(remote)); } if (new_local) { - load(local); + LOG_STATUS(load(local)); } if (new_generate) { - load(generate); + LOG_STATUS(load(generate)); } return; }