Remove update_local_file_location from FileLoaderActor.

This commit is contained in:
levlam 2024-07-15 14:44:36 +03:00
parent 34e81dc272
commit ee4794b343
5 changed files with 19 additions and 16 deletions

View File

@ -137,9 +137,6 @@ class FileDownloader final : public FileLoaderActor {
void update_resources(const ResourceState &other) final; void update_resources(const ResourceState &other) final;
void update_local_file_location(const LocalFileLocation &local) final {
}
void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) final; void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) final;
void start_up() final; void start_up() final;

View File

@ -23,8 +23,6 @@ class FileLoaderActor : public NetQueryCallback {
virtual void update_resources(const ResourceState &other) = 0; virtual void update_resources(const ResourceState &other) = 0;
// TODO: existence of these two functions is a dirty hack. Refactoring is highly appreciated // TODO: existence of these two functions is a dirty hack. Refactoring is highly appreciated
virtual void update_local_file_location(const LocalFileLocation &local) {
}
virtual void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) { virtual void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) {
} }
}; };

View File

@ -36,10 +36,10 @@ void FileUploadManager::upload(QueryId query_id, const LocalFileLocation &local_
CHECK(node); CHECK(node);
node->query_id_ = query_id; node->query_id_ = query_id;
auto callback = make_unique<FileUploaderCallback>(actor_shared(this, node_id)); auto callback = make_unique<FileUploaderCallback>(actor_shared(this, node_id));
node->loader_ = create_actor<FileUploader>("Uploader", local_location, remote_location, expected_size, encryption_key, node->uploader_ = create_actor<FileUploader>("Uploader", local_location, remote_location, expected_size,
std::move(bad_parts), std::move(callback)); encryption_key, std::move(bad_parts), std::move(callback));
send_closure(upload_resource_manager_, &ResourceManager::register_worker, send_closure(upload_resource_manager_, &ResourceManager::register_worker,
ActorShared<FileLoaderActor>(node->loader_.get(), static_cast<uint64>(-1)), priority); ActorShared<FileLoaderActor>(node->uploader_.get(), static_cast<uint64>(-1)), priority);
bool is_inserted = query_id_to_node_id_.emplace(query_id, node_id).second; bool is_inserted = query_id_to_node_id_.emplace(query_id, node_id).second;
CHECK(is_inserted); CHECK(is_inserted);
} }
@ -54,9 +54,9 @@ void FileUploadManager::upload_by_hash(QueryId query_id, const FullLocalFileLoca
CHECK(node); CHECK(node);
node->query_id_ = query_id; node->query_id_ = query_id;
auto callback = make_unique<FileHashUploaderCallback>(actor_shared(this, node_id)); auto callback = make_unique<FileHashUploaderCallback>(actor_shared(this, node_id));
node->loader_ = create_actor<FileHashUploader>("HashUploader", local_location, size, std::move(callback)); node->hash_uploader_ = create_actor<FileHashUploader>("HashUploader", local_location, size, std::move(callback));
send_closure(upload_resource_manager_, &ResourceManager::register_worker, send_closure(upload_resource_manager_, &ResourceManager::register_worker,
ActorShared<FileLoaderActor>(node->loader_.get(), static_cast<uint64>(-1)), priority); ActorShared<FileLoaderActor>(node->hash_uploader_.get(), static_cast<uint64>(-1)), priority);
bool is_inserted = query_id_to_node_id_.emplace(query_id, node_id).second; bool is_inserted = query_id_to_node_id_.emplace(query_id, node_id).second;
CHECK(is_inserted); CHECK(is_inserted);
} }
@ -73,7 +73,11 @@ void FileUploadManager::update_priority(QueryId query_id, int8 priority) {
if (node == nullptr) { if (node == nullptr) {
return; return;
} }
send_closure(node->loader_, &FileLoaderActor::update_priority, priority); if (!node->uploader_.empty()) {
send_closure(node->uploader_, &FileLoaderActor::update_priority, priority);
} else {
send_closure(node->hash_uploader_, &FileLoaderActor::update_priority, priority);
}
} }
void FileUploadManager::cancel(QueryId query_id) { void FileUploadManager::cancel(QueryId query_id) {
@ -96,14 +100,17 @@ void FileUploadManager::update_local_file_location(QueryId query_id, const Local
return; return;
} }
auto node = nodes_container_.get(it->second); auto node = nodes_container_.get(it->second);
if (node == nullptr) { if (node == nullptr || node->uploader_.empty()) {
return; return;
} }
send_closure(node->loader_, &FileLoaderActor::update_local_file_location, local); send_closure(node->uploader_, &FileUploader::update_local_file_location, local);
} }
void FileUploadManager::hangup() { void FileUploadManager::hangup() {
nodes_container_.for_each([](auto query_id, auto &node) { node.loader_.reset(); }); nodes_container_.for_each([](auto query_id, auto &node) {
node.uploader_.reset();
node.hash_uploader_.reset();
});
stop_flag_ = true; stop_flag_ = true;
loop(); loop();
} }

View File

@ -53,7 +53,8 @@ class FileUploadManager final : public Actor {
private: private:
struct Node { struct Node {
QueryId query_id_; QueryId query_id_;
ActorOwn<FileLoaderActor> loader_; ActorOwn<FileUploader> uploader_;
ActorOwn<FileHashUploader> hash_uploader_;
}; };
using NodeId = uint64; using NodeId = uint64;

View File

@ -48,7 +48,7 @@ class FileUploader final : public FileLoaderActor {
void update_resources(const ResourceState &other) final; void update_resources(const ResourceState &other) final;
void update_local_file_location(const LocalFileLocation &local) final; void update_local_file_location(const LocalFileLocation &local);
void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) { void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) {
} }