Asynchronously check location for files loaded from database.

This commit is contained in:
levlam 2022-10-10 14:51:24 +03:00
parent 28c3c7fb03
commit 3648df4e0d
2 changed files with 36 additions and 2 deletions

View File

@ -983,8 +983,11 @@ void FileManager::check_local_location_async(FileNodePtr node, bool skip_file_si
void FileManager::on_check_full_local_location(FileId file_id, LocalFileLocation checked_location, void FileManager::on_check_full_local_location(FileId file_id, LocalFileLocation checked_location,
Result<FullLocalLocationInfo> r_info, Promise<Unit> promise) { Result<FullLocalLocationInfo> r_info, Promise<Unit> promise) {
TRY_STATUS_PROMISE(promise, G()->close_status()); TRY_STATUS_PROMISE(promise, G()->close_status());
auto node = get_file_node(file_id); auto node = get_file_node(file_id);
CHECK(node); if (!node) {
return;
}
if (node->local_ != checked_location) { if (node->local_ != checked_location) {
LOG(INFO) << "Full location changed while being checked; ignore check result"; LOG(INFO) << "Full location changed while being checked; ignore check result";
return promise.set_value(Unit()); return promise.set_value(Unit());
@ -1009,6 +1012,7 @@ void FileManager::on_check_full_local_location(FileId file_id, LocalFileLocation
void FileManager::on_check_partial_local_location(FileId file_id, LocalFileLocation checked_location, void FileManager::on_check_partial_local_location(FileId file_id, LocalFileLocation checked_location,
Result<Unit> result, Promise<Unit> promise) { Result<Unit> result, Promise<Unit> promise) {
TRY_STATUS_PROMISE(promise, G()->close_status()); TRY_STATUS_PROMISE(promise, G()->close_status());
auto node = get_file_node(file_id); auto node = get_file_node(file_id);
CHECK(node); CHECK(node);
if (node->local_ != checked_location) { if (node->local_ != checked_location) {
@ -1023,6 +1027,31 @@ void FileManager::on_check_partial_local_location(FileId file_id, LocalFileLocat
} }
} }
void FileManager::recheck_full_local_location(FullLocalLocationInfo location_info, bool skip_file_size_checks) {
auto promise = PromiseCreator::lambda([actor_id = actor_id(this), checked_location = location_info.location_](
Result<FullLocalLocationInfo> result) mutable {
send_closure(actor_id, &FileManager::on_recheck_full_local_location, std::move(checked_location),
std::move(result));
});
send_closure(file_load_manager_, &FileLoadManager::check_full_local_location, std::move(location_info),
skip_file_size_checks, std::move(promise));
}
void FileManager::on_recheck_full_local_location(FullLocalFileLocation checked_location,
Result<FullLocalLocationInfo> r_info) {
if (G()->close_flag()) {
return;
}
auto file_id_it = local_location_to_file_id_.find(checked_location);
if (file_id_it == local_location_to_file_id_.end()) {
return;
}
auto file_id = file_id_it->second;
on_check_full_local_location(file_id, LocalFileLocation(checked_location), std::move(r_info), Promise<Unit>());
}
bool FileManager::try_fix_partial_local_location(FileNodePtr node) { bool FileManager::try_fix_partial_local_location(FileNodePtr node) {
LOG(INFO) << "Trying to fix partial local location"; LOG(INFO) << "Trying to fix partial local location";
if (node->local_.type() != LocalFileLocation::Type::Partial) { if (node->local_.type() != LocalFileLocation::Type::Partial) {
@ -1187,7 +1216,7 @@ Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource fi
} }
} }
if (!is_from_database) { if (file_location_source != FileLocationSource::FromDatabase) {
Status status; Status status;
auto r_info = check_full_local_location({data.local_.full(), data.size_}, skip_file_size_checks); auto r_info = check_full_local_location({data.local_.full(), data.size_}, skip_file_size_checks);
if (r_info.is_error()) { if (r_info.is_error()) {
@ -1209,6 +1238,9 @@ Result<FileId> FileManager::register_file(FileData &&data, FileLocationSource fi
data.local_ = LocalFileLocation(std::move(r_info.ok().location_)); data.local_ = LocalFileLocation(std::move(r_info.ok().location_));
data.size_ = r_info.ok().size_; data.size_ = r_info.ok().size_;
} }
} else {
// the location has been checked previously, but recheck it just in case
recheck_full_local_location({data.local_.full(), data.size_}, skip_file_size_checks);
} }
} }
bool has_local = data.local_.type() == LocalFileLocation::Type::Full; bool has_local = data.local_.type() == LocalFileLocation::Type::Full;

View File

@ -623,6 +623,8 @@ class FileManager final : public FileLoadManager::Callback {
Result<FullLocalLocationInfo> r_info, Promise<Unit> promise); Result<FullLocalLocationInfo> r_info, Promise<Unit> promise);
void on_check_partial_local_location(FileId file_id, LocalFileLocation checked_location, Result<Unit> result, void on_check_partial_local_location(FileId file_id, LocalFileLocation checked_location, Result<Unit> result,
Promise<Unit> promise); Promise<Unit> promise);
void recheck_full_local_location(FullLocalLocationInfo location_info, bool skip_file_size_checks);
void on_recheck_full_local_location(FullLocalFileLocation checked_location, Result<FullLocalLocationInfo> r_info);
static bool try_fix_partial_local_location(FileNodePtr node); static bool try_fix_partial_local_location(FileNodePtr node);
void try_flush_node_full(FileNodePtr node, bool new_remote, bool new_local, bool new_generate, FileDbId other_pmc_id); void try_flush_node_full(FileNodePtr node, bool new_remote, bool new_local, bool new_generate, FileDbId other_pmc_id);