Enable DelayDispacher. Improve errors and logging.

GitOrigin-RevId: e8d648e14183fe4a9409555eff5c6e167b5bcca2
This commit is contained in:
levlam 2018-03-16 15:33:44 +03:00
parent bc7599925e
commit 6e880f7ea0
4 changed files with 31 additions and 13 deletions

View File

@ -10,6 +10,7 @@
#include "td/telegram/net/NetQueryDispatcher.h"
namespace td {
void DelayDispatcher::send_with_callback(NetQueryPtr query, ActorShared<NetQueryCallback> 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

View File

@ -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 <queue>
namespace td {
class DelayDispatcher : public Actor {
public:
explicit DelayDispatcher(double delay) : delay_(delay) {
}
void send_with_callback(NetQueryPtr query, ActorShared<NetQueryCallback> callback);
private:
@ -24,8 +30,9 @@ class DelayDispatcher : public Actor {
};
std::queue<Query> queue_;
Timestamp wakeup_at_;
static constexpr double DELAY = 0.000;
double delay_;
void loop() override;
};
} // namespace td

View File

@ -89,8 +89,8 @@ void FileLoader::start_up() {
if (ordered_flag_) {
ordered_parts_ = OrderedEventsProcessor<std::pair<Part, NetQueryPtr>>(parts_manager_.get_ready_prefix_count());
}
if (file_info.need_delay && false) {
delay_dispatcher_ = create_actor<DelayDispatcher>("DelayDispatcher");
if (file_info.need_delay) {
delay_dispatcher_ = create_actor<DelayDispatcher>("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();

View File

@ -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;
}