Use real allocated file size in storage statistics.
GitOrigin-RevId: 6e5232700d8e97ba3ce0838c3bf7764541b6fd2a
This commit is contained in:
parent
eee0b2b23a
commit
c8bf8fa5f7
@ -170,7 +170,7 @@ int64 StorageManager::get_file_size(CSlice path) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto size = r_info.ok().size_;
|
||||
auto size = r_info.ok().real_size_;
|
||||
LOG(DEBUG) << "Add file \"" << path << "\" of size " << size << " to fast storage statistics";
|
||||
return size;
|
||||
}
|
||||
|
@ -544,6 +544,18 @@ int64 FileView::size() const {
|
||||
return node_->size_;
|
||||
}
|
||||
|
||||
int64 FileView::get_allocated_local_size() const {
|
||||
auto file_path = path();
|
||||
if (file_path.empty()) {
|
||||
return 0;
|
||||
}
|
||||
auto r_stat = stat(file_path);
|
||||
if (r_stat.is_error()) {
|
||||
return 0;
|
||||
}
|
||||
return r_stat.ok().real_size_;
|
||||
}
|
||||
|
||||
int64 FileView::expected_size(bool may_guess) const {
|
||||
if (node_->size_ != 0) {
|
||||
return node_->size_;
|
||||
@ -2008,8 +2020,8 @@ void FileManager::delete_file(FileId file_id, Promise<Unit> promise, const char
|
||||
LOG(INFO) << "Unlink file " << file_id << " at " << file_view.local_location().path_;
|
||||
clear_from_pmc(node);
|
||||
|
||||
context_->on_new_file(-file_view.get_allocated_local_size(), -1);
|
||||
unlink(file_view.local_location().path_).ignore();
|
||||
context_->on_new_file(-file_view.size(), -1);
|
||||
node->drop_local_location();
|
||||
try_flush_node(node, "delete_file 1");
|
||||
}
|
||||
@ -3264,7 +3276,7 @@ void FileManager::on_download_ok(QueryId query_id, const FullLocalFileLocation &
|
||||
LOG(ERROR) << "Can't register local file after download: " << r_new_file_id.error();
|
||||
} else {
|
||||
if (is_new) {
|
||||
context_->on_new_file(size, 1);
|
||||
context_->on_new_file(get_file_view(r_new_file_id.ok()).get_allocated_local_size(), 1);
|
||||
}
|
||||
LOG_STATUS(merge(r_new_file_id.ok(), file_id));
|
||||
}
|
||||
@ -3431,7 +3443,7 @@ void FileManager::on_generate_ok(QueryId query_id, const FullLocalFileLocation &
|
||||
|
||||
FileView file_view(file_node);
|
||||
if (!file_view.has_generate_location() || !begins_with(file_view.generate_location().conversion_, "#file_id#")) {
|
||||
context_->on_new_file(file_view.size(), 1);
|
||||
context_->on_new_file(file_view.get_allocated_local_size(), 1);
|
||||
}
|
||||
|
||||
run_upload(file_node, {});
|
||||
|
@ -271,6 +271,8 @@ class FileView {
|
||||
int64 remote_size() const;
|
||||
string path() const;
|
||||
|
||||
int64 get_allocated_local_size() const;
|
||||
|
||||
bool can_download_from_server() const;
|
||||
bool can_generate() const;
|
||||
bool can_delete() const;
|
||||
|
@ -126,7 +126,7 @@ void scan_fs(CancellationToken &token, CallbackT &&callback) {
|
||||
|
||||
FsFileInfo info;
|
||||
info.path = path.str();
|
||||
info.size = stat.size_;
|
||||
info.size = stat.real_size_;
|
||||
info.file_type = file_type;
|
||||
info.atime_nsec = stat.atime_nsec_;
|
||||
info.mtime_nsec = stat.mtime_nsec_;
|
||||
|
@ -499,8 +499,9 @@ Result<FileSize> get_file_size(const FileFd &file_fd) {
|
||||
res.size_ = standard_info.EndOfFile.QuadPart;
|
||||
res.real_size_ = standard_info.AllocationSize.QuadPart;
|
||||
|
||||
if (res.size_ > 0 && res.real_size_ <= 0) {
|
||||
res.real_size_ = res.size_; // just in case
|
||||
if (res.size_ > 0 && res.real_size_ <= 0) { // just in case
|
||||
LOG(ERROR) << "Fix real file size from " << res.real_size_ << " to " << res.size_;
|
||||
res.real_size_ = res.size_;
|
||||
}
|
||||
|
||||
return res;
|
||||
|
Reference in New Issue
Block a user