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) {
if (parts_manager_.get_streaming_offset() != offset) {
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;
VLOG(files) << "Protect parts " << begin_part_id << " ... " << end_part_id;
auto new_end_part_id = limit <= 0 ? parts_manager_.get_part_count()
: 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_) {
if (!(begin_part_id <= it.second.first.id && it.second.first.id < end_part_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(); });
send_closure(std::move(delay_dispatcher_), &DelayDispatcher::close_silent);
}
void FileLoader::update_estimated_limit() {
if (stop_flag_) {
return;

View File

@ -132,7 +132,7 @@ void ResourceManager::loop() {
return;
}
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());
if (mode_ == Mode::Greedy) {

View File

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