PartsManager: some fixes

GitOrigin-RevId: fedd9458f18179cdabef579cdc251f8006a3f61e
This commit is contained in:
Arseny Smirnov 2019-07-30 21:27:39 +03:00
parent cfe7b95be5
commit 655add2ec0
4 changed files with 24 additions and 6 deletions

View File

@ -66,10 +66,12 @@ void FileLoader::update_local_file_location(const LocalFileLocation &local) {
}
void FileLoader::update_download_offset(int64 offset) {
parts_manager_.set_streaming_offset(offset);
//TODO: cancel only some queries
for (auto &it : part_map_) {
it.second.second.reset(); // cancel_query(it.second.second);
if (parts_manager_.get_streaming_offset() != offset) {
parts_manager_.set_streaming_offset(offset);
//TODO: cancel only some queries
for (auto &it : part_map_) {
it.second.second.reset(); // cancel_query(it.second.second);
}
}
update_estimated_limit();
loop();
@ -279,6 +281,10 @@ void FileLoader::on_result(NetQueryPtr query) {
}
void FileLoader::on_part_query(Part part, NetQueryPtr query) {
if (stop_flag_) {
// important for secret chats
return;
}
auto status = try_on_part_query(part, std::move(query));
if (status.is_error()) {
on_error(std::move(status));

View File

@ -119,6 +119,9 @@ Result<FileLoader::PrefixInfo> FileUploader::on_update_local_location(const Loca
file_type = location.partial().file_type_;
} else {
path = location.full().path_;
if (path.empty()) {
return Status::Error("FullLocalFileLocation whith empty path");
}
local_is_ready = true;
file_type = location.full().file_type_;
}
@ -160,8 +163,9 @@ Result<FileLoader::PrefixInfo> FileUploader::on_update_local_location(const Loca
fd_ = res_fd.move_as_ok();
fd_path_ = path;
is_temp_ = is_temp;
} else if (!fd_path_.empty()) {
TRY_STATUS(acquire_fd());
}
if (local_is_ready) {
CHECK(!fd_.empty());
TRY_RESULT(local_file_size, fd_.get_size());

View File

@ -206,6 +206,9 @@ int32 PartsManager::get_ready_prefix_count() {
}
return res;
}
int64 PartsManager::get_streaming_offset() const {
return streaming_offset_;
}
string PartsManager::get_bitmask() {
int32 prefix_count = -1;
if (need_check_) {
@ -452,7 +455,11 @@ void PartsManager::init_common(const std::vector<int> &ready_parts) {
part_status_ = vector<PartStatus>(part_count_);
for (auto i : ready_parts) {
LOG_CHECK(0 <= i && i < part_count_) << tag("i", i) << tag("part_count", part_count_);
LOG_CHECK(0 <= i && i < part_count_) << tag("i", i) << tag("part_count", part_count_) << tag("size", size_)
<< tag("part_size", part_size_) << tag("known_prefix_flag", known_prefix_flag_)
<< tag("real part_count",
std::accumulate(ready_parts.begin(), ready_parts.end(), 0,
[](auto a, auto b) { return max(a, b + 1); }));
part_status_[i] = PartStatus::Ready;
bitmask_.set(i);
auto part = get_part(i);

View File

@ -50,6 +50,7 @@ class PartsManager {
int32 get_part_count() const;
int32 get_unchecked_ready_prefix_count();
int32 get_ready_prefix_count();
int64 get_streaming_offset() const;
string get_bitmask();
private: