FileNode * -> FileNodePtr
GitOrigin-RevId: 1fa58d17dc71c74c78097105fc4c2acbde3b48a7
This commit is contained in:
parent
74bdbedb5a
commit
d3e4ad0060
@ -36,7 +36,7 @@ namespace td {
|
|||||||
|
|
||||||
static int VERBOSITY_NAME(update_file) = VERBOSITY_NAME(INFO);
|
static int VERBOSITY_NAME(update_file) = VERBOSITY_NAME(INFO);
|
||||||
|
|
||||||
/*** FileNode ***/
|
/*** FileNodePtr **/
|
||||||
void FileNode::set_local_location(const LocalFileLocation &local, int64 ready_size) {
|
void FileNode::set_local_location(const LocalFileLocation &local, int64 ready_size) {
|
||||||
if (local_ready_size_ != ready_size) {
|
if (local_ready_size_ != ready_size) {
|
||||||
local_ready_size_ = ready_size;
|
local_ready_size_ = ready_size;
|
||||||
@ -326,7 +326,7 @@ bool FileView::get_by_hash() const {
|
|||||||
return node_->get_by_hash_;
|
return node_->get_by_hash_;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileView::FileView(const FileNode *node) : node_(node) {
|
FileView::FileView(ConstFileNodePtr node) : node_(node) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileView::empty() const {
|
bool FileView::empty() const {
|
||||||
@ -512,7 +512,7 @@ static Status check_partial_local_location(const PartialLocalFileLocation &locat
|
|||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
Status FileManager::check_local_location(FileNode *node) {
|
Status FileManager::check_local_location(FileNodePtr node) {
|
||||||
Status status;
|
Status status;
|
||||||
if (node->local_.type() == LocalFileLocation::Type::Full) {
|
if (node->local_.type() == LocalFileLocation::Type::Full) {
|
||||||
status = check_local_location(node->local_.full(), node->size_);
|
status = check_local_location(node->local_.full(), node->size_);
|
||||||
@ -543,7 +543,7 @@ FileId FileManager::dup_file_id(FileId file_id) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileId FileManager::create_file_id(int32 file_node_id, FileNode *file_node) {
|
FileId FileManager::create_file_id(int32 file_node_id, FileNodePtr file_node) {
|
||||||
auto file_id = next_file_id();
|
auto file_id = next_file_id();
|
||||||
get_file_id_info(file_id)->node_id_ = file_node_id;
|
get_file_id_info(file_id)->node_id_ = file_node_id;
|
||||||
file_node->file_ids_.push_back(file_id);
|
file_node->file_ids_.push_back(file_id);
|
||||||
@ -803,7 +803,7 @@ static int merge_choose_encryption_key(const FileEncryptionKey &a, const FileEnc
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::cancel_download(FileNode *node) {
|
void FileManager::cancel_download(FileNodePtr node) {
|
||||||
if (node->download_id_ == 0) {
|
if (node->download_id_ == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -813,7 +813,7 @@ void FileManager::cancel_download(FileNode *node) {
|
|||||||
node->set_download_priority(0);
|
node->set_download_priority(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::cancel_upload(FileNode *node) {
|
void FileManager::cancel_upload(FileNodePtr node) {
|
||||||
if (node->upload_id_ == 0) {
|
if (node->upload_id_ == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -822,7 +822,7 @@ void FileManager::cancel_upload(FileNode *node) {
|
|||||||
node->set_upload_priority(0);
|
node->set_upload_priority(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::cancel_generate(FileNode *node) {
|
void FileManager::cancel_generate(FileNodePtr node) {
|
||||||
if (node->generate_id_ == 0) {
|
if (node->generate_id_ == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -839,7 +839,7 @@ Result<FileId> FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy
|
|||||||
return Status::Error("First file_id is invalid");
|
return Status::Error("First file_id is invalid");
|
||||||
}
|
}
|
||||||
FileNodeId x_node_id;
|
FileNodeId x_node_id;
|
||||||
FileNode *x_node = no_sync ? get_file_node(x_file_id, &x_node_id) : get_sync_file_node(x_file_id, &x_node_id);
|
FileNodePtr x_node = no_sync ? get_file_node(x_file_id, &x_node_id) : get_sync_file_node(x_file_id, &x_node_id);
|
||||||
if (!x_node) {
|
if (!x_node) {
|
||||||
return Status::Error(PSLICE() << "Can't merge files. First id is invalid: " << x_file_id << " and " << y_file_id);
|
return Status::Error(PSLICE() << "Can't merge files. First id is invalid: " << x_file_id << " and " << y_file_id);
|
||||||
}
|
}
|
||||||
@ -848,7 +848,7 @@ Result<FileId> FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy
|
|||||||
return x_node->main_file_id_;
|
return x_node->main_file_id_;
|
||||||
}
|
}
|
||||||
FileNodeId y_node_id;
|
FileNodeId y_node_id;
|
||||||
FileNode *y_node = no_sync ? get_file_node(y_file_id, &y_node_id) : get_file_node(y_file_id, &y_node_id);
|
FileNodePtr y_node = no_sync ? get_file_node(y_file_id, &y_node_id) : get_file_node(y_file_id, &y_node_id);
|
||||||
if (!y_node) {
|
if (!y_node) {
|
||||||
return Status::Error(PSLICE() << "Can't merge files. Second id is invalid: " << x_file_id << " and " << y_file_id);
|
return Status::Error(PSLICE() << "Can't merge files. Second id is invalid: " << x_file_id << " and " << y_file_id);
|
||||||
}
|
}
|
||||||
@ -870,7 +870,7 @@ Result<FileId> FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy
|
|||||||
<< x_node->remote_.full();
|
<< x_node->remote_.full();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileNode *nodes[] = {x_node, y_node, x_node};
|
FileNodePtr nodes[] = {x_node, y_node, x_node};
|
||||||
FileNodeId node_ids[] = {x_node_id, y_node_id};
|
FileNodeId node_ids[] = {x_node_id, y_node_id};
|
||||||
|
|
||||||
int local_i = merge_choose(x_node->local_, y_node->local_);
|
int local_i = merge_choose(x_node->local_, y_node->local_);
|
||||||
@ -905,8 +905,8 @@ Result<FileId> FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy
|
|||||||
std::make_tuple(x_node->pmc_id_, x_node->file_ids_.size(), main_file_id_i == 0);
|
std::make_tuple(x_node->pmc_id_, x_node->file_ids_.size(), main_file_id_i == 0);
|
||||||
|
|
||||||
auto other_node_i = 1 - node_i;
|
auto other_node_i = 1 - node_i;
|
||||||
FileNode *node = nodes[node_i];
|
FileNodePtr node = nodes[node_i];
|
||||||
FileNode *other_node = nodes[other_node_i];
|
FileNodePtr other_node = nodes[other_node_i];
|
||||||
auto file_view = FileView(node);
|
auto file_view = FileView(node);
|
||||||
|
|
||||||
LOG(INFO) << "x_node->pmc_id_ = " << x_node->pmc_id_ << ", y_node->pmc_id_ = " << y_node->pmc_id_
|
LOG(INFO) << "x_node->pmc_id_ = " << x_node->pmc_id_ << ", y_node->pmc_id_ = " << y_node->pmc_id_
|
||||||
@ -1047,7 +1047,7 @@ Result<FileId> FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy
|
|||||||
return node->main_file_id_;
|
return node->main_file_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::try_flush_node(FileNode *node, bool new_remote, bool new_local, bool new_generate,
|
void FileManager::try_flush_node(FileNodePtr node, bool new_remote, bool new_local, bool new_generate,
|
||||||
FileDbId other_pmc_id) {
|
FileDbId other_pmc_id) {
|
||||||
if (node->need_pmc_flush()) {
|
if (node->need_pmc_flush()) {
|
||||||
if (file_db_) {
|
if (file_db_) {
|
||||||
@ -1063,7 +1063,7 @@ void FileManager::try_flush_node(FileNode *node, bool new_remote, bool new_local
|
|||||||
try_flush_node_info(node);
|
try_flush_node_info(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::try_flush_node_info(FileNode *node) {
|
void FileManager::try_flush_node_info(FileNodePtr node) {
|
||||||
if (node->need_info_flush()) {
|
if (node->need_info_flush()) {
|
||||||
for (auto file_id : node->file_ids_) {
|
for (auto file_id : node->file_ids_) {
|
||||||
auto *info = get_file_id_info(file_id);
|
auto *info = get_file_id_info(file_id);
|
||||||
@ -1076,7 +1076,7 @@ void FileManager::try_flush_node_info(FileNode *node) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::clear_from_pmc(FileNode *node) {
|
void FileManager::clear_from_pmc(FileNodePtr node) {
|
||||||
if (!file_db_) {
|
if (!file_db_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1099,7 +1099,7 @@ void FileManager::clear_from_pmc(FileNode *node) {
|
|||||||
file_db_->clear_file_data(node->pmc_id_, data);
|
file_db_->clear_file_data(node->pmc_id_, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::flush_to_pmc(FileNode *node, bool new_remote, bool new_local, bool new_generate) {
|
void FileManager::flush_to_pmc(FileNodePtr node, bool new_remote, bool new_local, bool new_generate) {
|
||||||
if (!file_db_) {
|
if (!file_db_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1141,7 +1141,7 @@ void FileManager::flush_to_pmc(FileNode *node, bool new_remote, bool new_local,
|
|||||||
(create_flag || new_generate));
|
(create_flag || new_generate));
|
||||||
}
|
}
|
||||||
|
|
||||||
const FileNode *FileManager::get_file_node(FileId file_id, FileNodeId *file_node_id) const {
|
ConstFileNodePtr FileManager::get_file_node(FileId file_id, FileNodeId *file_node_id) const {
|
||||||
if (file_id.get() <= 0 || file_id.get() >= static_cast<int32>(file_id_info_.size())) {
|
if (file_id.get() <= 0 || file_id.get() >= static_cast<int32>(file_id_info_.size())) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -1155,10 +1155,10 @@ const FileNode *FileManager::get_file_node(FileId file_id, FileNodeId *file_node
|
|||||||
return file_nodes_[node_id].get();
|
return file_nodes_[node_id].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileNode *FileManager::get_file_node(FileId file_id, FileNodeId *file_node_id) {
|
FileNodePtr FileManager::get_file_node(FileId file_id, FileNodeId *file_node_id) {
|
||||||
return const_cast<FileNode *>(static_cast<const FileManager *>(this)->get_file_node(file_id, file_node_id));
|
return const_cast<FileNodePtr>(static_cast<const FileManager *>(this)->get_file_node(file_id, file_node_id));
|
||||||
}
|
}
|
||||||
FileNode *FileManager::get_sync_file_node(FileId file_id, FileNodeId *file_node_id) {
|
FileNodePtr FileManager::get_sync_file_node(FileId file_id, FileNodeId *file_node_id) {
|
||||||
auto file_node = get_file_node(file_id, file_node_id);
|
auto file_node = get_file_node(file_id, file_node_id);
|
||||||
if (!file_node) {
|
if (!file_node) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -1166,7 +1166,7 @@ FileNode *FileManager::get_sync_file_node(FileId file_id, FileNodeId *file_node_
|
|||||||
return load_from_pmc(file_node, true, true, true);
|
return load_from_pmc(file_node, true, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileNode *FileManager::load_from_pmc(FileNode *node, bool new_remote, bool new_local, bool new_generate) {
|
FileNodePtr FileManager::load_from_pmc(FileNodePtr node, bool new_remote, bool new_local, bool new_generate) {
|
||||||
if (!node->need_load_from_pmc_) {
|
if (!node->need_load_from_pmc_) {
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -1364,7 +1364,7 @@ void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> cal
|
|||||||
try_flush_node(node);
|
try_flush_node(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::run_download(FileNode *node) {
|
void FileManager::run_download(FileNodePtr node) {
|
||||||
if (node->need_load_from_pmc_) {
|
if (node->need_load_from_pmc_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1502,7 +1502,7 @@ void FileManager::external_file_generate_finish(int64 id, Status status, Promise
|
|||||||
std::move(promise));
|
std::move(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::run_generate(FileNode *node) {
|
void FileManager::run_generate(FileNodePtr node) {
|
||||||
if (node->need_load_from_pmc_) {
|
if (node->need_load_from_pmc_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1574,7 +1574,7 @@ void FileManager::run_generate(FileNode *node) {
|
|||||||
LOG(INFO) << "File " << file_id << " generate request has sent to FileGenerateManager";
|
LOG(INFO) << "File " << file_id << " generate request has sent to FileGenerateManager";
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::run_upload(FileNode *node, std::vector<int> bad_parts) {
|
void FileManager::run_upload(FileNodePtr node, std::vector<int> bad_parts) {
|
||||||
if (node->need_load_from_pmc_) {
|
if (node->need_load_from_pmc_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2172,7 +2172,7 @@ void FileManager::on_error(QueryId query_id, Status status) {
|
|||||||
on_error_impl(node, query.type_, was_active, std::move(status));
|
on_error_impl(node, query.type_, was_active, std::move(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::on_error_impl(FileNode *node, FileManager::Query::Type type, bool was_active, Status status) {
|
void FileManager::on_error_impl(FileNodePtr node, FileManager::Query::Type type, bool was_active, Status status) {
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
try_flush_node(node);
|
try_flush_node(node);
|
||||||
};
|
};
|
||||||
|
@ -122,10 +122,14 @@ class FileNode {
|
|||||||
bool info_changed_flag_{false};
|
bool info_changed_flag_{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class FileManager;
|
||||||
|
using FileNodePtr = FileNode *;
|
||||||
|
using ConstFileNodePtr = const FileNode *;
|
||||||
|
|
||||||
class FileView {
|
class FileView {
|
||||||
public:
|
public:
|
||||||
FileView() = default;
|
FileView() = default;
|
||||||
explicit FileView(const FileNode *node);
|
explicit FileView(ConstFileNodePtr node);
|
||||||
|
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
|
||||||
@ -182,7 +186,7 @@ class FileView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const FileNode *node_ = nullptr;
|
ConstFileNodePtr node_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Td;
|
class Td;
|
||||||
@ -344,7 +348,7 @@ class FileManager : public FileLoadManager::Callback {
|
|||||||
FileId next_file_id();
|
FileId next_file_id();
|
||||||
FileNodeId next_file_node_id();
|
FileNodeId next_file_node_id();
|
||||||
int32 next_pmc_file_id();
|
int32 next_pmc_file_id();
|
||||||
FileId create_file_id(int32 file_node_id, FileNode *file_node);
|
FileId create_file_id(int32 file_node_id, FileNodePtr file_node);
|
||||||
void try_forget_file_id(FileId file_id);
|
void try_forget_file_id(FileId file_id);
|
||||||
|
|
||||||
void load_from_pmc(FileId file_id, FullLocalFileLocation full_local);
|
void load_from_pmc(FileId file_id, FullLocalFileLocation full_local);
|
||||||
@ -355,31 +359,31 @@ class FileManager : public FileLoadManager::Callback {
|
|||||||
void load_from_pmc_result(FileId file_id, Result<FileData> &&result);
|
void load_from_pmc_result(FileId file_id, Result<FileData> &&result);
|
||||||
FileId register_pmc_file_data(FileData &&data);
|
FileId register_pmc_file_data(FileData &&data);
|
||||||
|
|
||||||
Status check_local_location(FileNode *node);
|
Status check_local_location(FileNodePtr node);
|
||||||
Status check_local_location(FullLocalFileLocation &location, int64 &size);
|
Status check_local_location(FullLocalFileLocation &location, int64 &size);
|
||||||
void try_flush_node(FileNode *node, bool new_remote = false, bool new_local = false, bool new_generate = false,
|
void try_flush_node(FileNodePtr node, bool new_remote = false, bool new_local = false, bool new_generate = false,
|
||||||
FileDbId other_pmc_id = Auto());
|
FileDbId other_pmc_id = Auto());
|
||||||
void try_flush_node_info(FileNode *node);
|
void try_flush_node_info(FileNodePtr node);
|
||||||
void clear_from_pmc(FileNode *node);
|
void clear_from_pmc(FileNodePtr node);
|
||||||
void flush_to_pmc(FileNode *node, bool new_remote, bool new_local, bool new_generate);
|
void flush_to_pmc(FileNodePtr node, bool new_remote, bool new_local, bool new_generate);
|
||||||
FileNode *load_from_pmc(FileNode *node, bool new_remote, bool new_local, bool new_generate) TD_WARN_UNUSED_RESULT;
|
FileNodePtr load_from_pmc(FileNodePtr node, bool new_remote, bool new_local, bool new_generate) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
string get_persistent_id(const FullRemoteFileLocation &location);
|
string get_persistent_id(const FullRemoteFileLocation &location);
|
||||||
|
|
||||||
string fix_file_extension(Slice file_name, Slice file_type, Slice file_extension);
|
string fix_file_extension(Slice file_name, Slice file_type, Slice file_extension);
|
||||||
string get_file_name(FileType file_type, Slice path);
|
string get_file_name(FileType file_type, Slice path);
|
||||||
|
|
||||||
const FileNode *get_file_node(FileId file_id, FileNodeId *file_node_id = nullptr) const;
|
ConstFileNodePtr get_file_node(FileId file_id, FileNodeId *file_node_id = nullptr) const;
|
||||||
FileNode *get_file_node(FileId file_id, FileNodeId *file_node_id = nullptr);
|
FileNodePtr get_file_node(FileId file_id, FileNodeId *file_node_id = nullptr);
|
||||||
FileNode *get_sync_file_node(FileId file_id, FileNodeId *file_node_id = nullptr);
|
FileNodePtr get_sync_file_node(FileId file_id, FileNodeId *file_node_id = nullptr);
|
||||||
|
|
||||||
// void release_file_node(FileNodeId id);
|
// void release_file_node(FileNodeId id);
|
||||||
void cancel_download(FileNode *node);
|
void cancel_download(FileNodePtr node);
|
||||||
void cancel_upload(FileNode *node);
|
void cancel_upload(FileNodePtr node);
|
||||||
void cancel_generate(FileNode *node);
|
void cancel_generate(FileNodePtr node);
|
||||||
void run_upload(FileNode *node, std::vector<int> bad_parts);
|
void run_upload(FileNodePtr node, std::vector<int> bad_parts);
|
||||||
void run_download(FileNode *node);
|
void run_download(FileNodePtr node);
|
||||||
void run_generate(FileNode *node);
|
void run_generate(FileNodePtr node);
|
||||||
|
|
||||||
void on_start_download(QueryId query_id) override;
|
void on_start_download(QueryId query_id) override;
|
||||||
void on_partial_download(QueryId query_id, const PartialLocalFileLocation &partial_local, int64 ready_size) override;
|
void on_partial_download(QueryId query_id, const PartialLocalFileLocation &partial_local, int64 ready_size) override;
|
||||||
@ -390,7 +394,7 @@ class FileManager : public FileLoadManager::Callback {
|
|||||||
void on_upload_full_ok(QueryId query_id, const FullRemoteFileLocation &remote) override;
|
void on_upload_full_ok(QueryId query_id, const FullRemoteFileLocation &remote) override;
|
||||||
void on_error(QueryId query_id, Status status) override;
|
void on_error(QueryId query_id, Status status) override;
|
||||||
|
|
||||||
void on_error_impl(FileNode *node, Query::Type type, bool was_active, Status status);
|
void on_error_impl(FileNodePtr node, Query::Type type, bool was_active, Status status);
|
||||||
|
|
||||||
void on_partial_generate(QueryId, const PartialLocalFileLocation &partial_local, int32 expected_size);
|
void on_partial_generate(QueryId, const PartialLocalFileLocation &partial_local, int32 expected_size);
|
||||||
void on_generate_ok(QueryId, const FullLocalFileLocation &local);
|
void on_generate_ok(QueryId, const FullLocalFileLocation &local);
|
||||||
|
Loading…
Reference in New Issue
Block a user