Minor file GC improvements.
GitOrigin-RevId: a14b6e219ad90537875108b3e42473bf33267855
This commit is contained in:
parent
751dae9e64
commit
0b30530260
@ -26,16 +26,6 @@ namespace td {
|
||||
|
||||
int VERBOSITY_NAME(file_gc) = VERBOSITY_NAME(INFO);
|
||||
|
||||
void FileGcWorker::do_remove_file(const FullFileInfo &info) {
|
||||
// LOG(WARNING) << "Gc remove file: " << tag("path", file) << tag("mtime", stat.mtime_nsec_ / 1000000000)
|
||||
// << tag("atime", stat.atime_nsec_ / 1000000000);
|
||||
// TODO: remove file from database too
|
||||
auto status = unlink(info.path);
|
||||
LOG_IF(WARNING, status.is_error()) << "Failed to unlink file during files gc: " << status;
|
||||
send_closure(G()->file_manager(), &FileManager::on_file_unlink,
|
||||
FullLocalFileLocation(info.file_type, info.path, info.mtime_nsec));
|
||||
}
|
||||
|
||||
void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector<FullFileInfo> files,
|
||||
Promise<FileStats> promise) {
|
||||
auto begin_time = Time::now();
|
||||
@ -92,8 +82,17 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector<FullFi
|
||||
FileStats new_stats;
|
||||
new_stats.split_by_owner_dialog_id = parameters.dialog_limit != 0;
|
||||
|
||||
// Remove all files with atime > now - max_time_from_last_access
|
||||
auto do_remove_file = [](const FullFileInfo &info) {
|
||||
auto status = unlink(info.path);
|
||||
LOG_IF(WARNING, status.is_error()) << "Failed to unlink file \"" << info.path << "\" during files gc: " << status;
|
||||
send_closure(G()->file_manager(), &FileManager::on_file_unlink,
|
||||
FullLocalFileLocation(info.file_type, info.path, info.mtime_nsec));
|
||||
};
|
||||
|
||||
double now = Clocks::system();
|
||||
|
||||
// Keep all immune files
|
||||
// Remove all files with (atime > now - max_time_from_last_access)
|
||||
td::remove_if(files, [&](const FullFileInfo &info) {
|
||||
if (token_) {
|
||||
return false;
|
||||
@ -113,14 +112,14 @@ void FileGcWorker::run_gc(const FileGcParameters ¶meters, std::vector<FullFi
|
||||
new_stats.add(FullFileInfo(info));
|
||||
return true;
|
||||
}
|
||||
if (static_cast<double>(info.mtime_nsec / 1000000000) > now - parameters.immunity_delay) {
|
||||
if (info.mtime_nsec * 1e-9 > now - parameters.immunity_delay) {
|
||||
// new files are immune to gc
|
||||
time_immunity_ignored_cnt++;
|
||||
new_stats.add(FullFileInfo(info));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (static_cast<double>(info.atime_nsec / 1000000000) < now - parameters.max_time_from_last_access) {
|
||||
if (info.atime_nsec * 1e-9 < now - parameters.max_time_from_last_access) {
|
||||
do_remove_file(info);
|
||||
total_removed_size += info.size;
|
||||
remove_by_atime_cnt++;
|
||||
|
@ -28,7 +28,6 @@ class FileGcWorker : public Actor {
|
||||
private:
|
||||
ActorShared<> parent_;
|
||||
CancellationToken token_;
|
||||
void do_remove_file(const FullFileInfo &info);
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
@ -1020,6 +1020,7 @@ FileId FileManager::register_empty(FileType type) {
|
||||
}
|
||||
|
||||
void FileManager::on_file_unlink(const FullLocalFileLocation &location) {
|
||||
// TODO: remove file from the database too
|
||||
auto it = local_location_to_file_id_.find(location);
|
||||
if (it == local_location_to_file_id_.end()) {
|
||||
return;
|
||||
|
Reference in New Issue
Block a user