Improve protected parts calculation.

GitOrigin-RevId: f066b0680a11b6c376eead756f9d67880eb6d17e
This commit is contained in:
levlam 2020-08-26 12:24:06 +03:00
parent e8c630180f
commit 3b4d55233c
3 changed files with 9 additions and 3 deletions

View File

@ -68,8 +68,11 @@ void FileLoader::update_local_file_location(const LocalFileLocation &local) {
void FileLoader::update_downloaded_part(int64 offset, int64 limit) { void FileLoader::update_downloaded_part(int64 offset, int64 limit) {
if (parts_manager_.get_streaming_offset() != offset) { if (parts_manager_.get_streaming_offset() != offset) {
auto begin_part_id = parts_manager_.set_streaming_offset(offset, limit); auto begin_part_id = parts_manager_.set_streaming_offset(offset, limit);
auto end_part_id = begin_part_id + static_cast<int32>(part_map_.size()) * 2; auto new_end_part_id = limit <= 0 ? parts_manager_.get_part_count()
VLOG(files) << "Protect parts " << begin_part_id << " ... " << end_part_id; : static_cast<int32>((offset + limit - 1) / parts_manager_.get_part_size()) + 1;
auto max_parts = static_cast<int32>(ResourceManager::MAX_RESOURCE_LIMIT / parts_manager_.get_part_size());
auto end_part_id = begin_part_id + td::min(max_parts, new_end_part_id - begin_part_id);
VLOG(files) << "Protect parts " << begin_part_id << " ... " << end_part_id - 1;
for (auto &it : part_map_) { for (auto &it : part_map_) {
if (!(begin_part_id <= it.second.first.id && it.second.first.id < end_part_id)) { if (!(begin_part_id <= it.second.first.id && it.second.first.id < end_part_id)) {
VLOG(files) << "Cancel part " << it.second.first.id; VLOG(files) << "Cancel part " << it.second.first.id;
@ -224,6 +227,7 @@ void FileLoader::tear_down() {
ordered_parts_.clear([](auto &&part) { part.second->clear(); }); ordered_parts_.clear([](auto &&part) { part.second->clear(); });
send_closure(std::move(delay_dispatcher_), &DelayDispatcher::close_silent); send_closure(std::move(delay_dispatcher_), &DelayDispatcher::close_silent);
} }
void FileLoader::update_estimated_limit() { void FileLoader::update_estimated_limit() {
if (stop_flag_) { if (stop_flag_) {
return; return;

View File

@ -132,7 +132,7 @@ void ResourceManager::loop() {
return; return;
} }
auto active_limit = resource_state_.active_limit(); auto active_limit = resource_state_.active_limit();
resource_state_.update_limit(2 * 1024 * (1 << 10) - active_limit); resource_state_.update_limit(MAX_RESOURCE_LIMIT - active_limit);
LOG(INFO) << tag("unused", resource_state_.unused()); LOG(INFO) << tag("unused", resource_state_.unused());
if (mode_ == Mode::Greedy) { if (mode_ == Mode::Greedy) {

View File

@ -28,6 +28,8 @@ class ResourceManager : public Actor {
void register_worker(ActorShared<FileLoaderActor> callback, int8 priority); void register_worker(ActorShared<FileLoaderActor> callback, int8 priority);
static constexpr int64 MAX_RESOURCE_LIMIT = 1 << 21;
private: private:
Mode mode_; Mode mode_;
using NodeId = uint64; using NodeId = uint64;