Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disagg: fix used size metrics of FileCache #8921

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions dbms/src/Storages/S3/FileCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ FileSegmentPtr FileCache::get(const S3::S3FilenameView & s3_fname, const std::op
}

// Remove `local_fname` from disk and remove parent directory if parent directory is empty.
void FileCache::removeDiskFile(const String & local_fname) const
void FileCache::removeDiskFile(const String & local_fname, bool update_fsize_metrics) const
{
if (!std::filesystem::exists(local_fname))
{
Expand All @@ -181,9 +181,7 @@ void FileCache::removeDiskFile(const String & local_fname) const
if (s != cache_dir && (s == local_fname || std::filesystem::is_empty(p)))
{
std::filesystem::remove(p); // If p is a directory, remove success only when it is empty.
// Temporary files are not reported size to metrics until they are renamed.
// So we don't need to free its size here.
if (s == local_fname && !isTemporaryFilename(local_fname))
if (s == local_fname && update_fsize_metrics)
{
capacity_metrics->freeUsedSize(local_fname, fsize);
}
Expand Down Expand Up @@ -231,9 +229,10 @@ std::pair<Int64, std::list<String>::iterator> FileCache::removeImpl(
return {-1, {}};
}
const auto & local_fname = f->getLocalFileName();
removeDiskFile(local_fname);
removeDiskFile(local_fname, /*update_fsize_metrics*/ true);
auto temp_fname = toTemporaryFilename(local_fname);
removeDiskFile(temp_fname);
// Not update fsize metrics for temporary files because they are not add to fsize metrics before.
removeDiskFile(temp_fname, /*update_fsize_metrics*/ false);

auto release_size = f->getSize();
GET_METRIC(tiflash_storage_remote_cache, type_dtfile_evict).Increment();
Expand Down Expand Up @@ -651,7 +650,8 @@ void FileCache::restoreDMFile(const std::filesystem::directory_entry & dmfile_en
auto fname = file_entry.path().string();
if (unlikely(isTemporaryFilename(fname)))
{
removeDiskFile(fname);
// Not update fsize metrics for temporary files because they are not add to fsize metrics before.
removeDiskFile(fname, /*update_fsize_metrics*/ false);
}
else
{
Expand All @@ -669,7 +669,8 @@ void FileCache::restoreDMFile(const std::filesystem::directory_entry & dmfile_en
}
else
{
removeDiskFile(fname);
// Not update fsize metrics because this file is not added to metrics yet.
removeDiskFile(fname, /*update_fsize_metrics*/ false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/S3/FileCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class FileCache
const String & s3_key,
FileSegmentPtr & f,
bool force = false);
void removeDiskFile(const String & local_fname) const;
void removeDiskFile(const String & local_fname, bool update_fsize_metrics) const;

// Estimated size is an empirical value.
// We don't know object size before get object from S3.
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Storages/S3/tests/gtest_filecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ TEST_F(FileCacheTest, FileSystem)
}
ASSERT_TRUE(std::filesystem::exists(local_file2));

file_cache.removeDiskFile(local_fname1);
file_cache.removeDiskFile(local_fname1, false);
ASSERT_FALSE(std::filesystem::exists(local_file1)) << local_file1.generic_string();
ASSERT_TRUE(std::filesystem::exists(local_file2)) << local_file2.generic_string();
ASSERT_TRUE(std::filesystem::exists(dmf)) << dmf.generic_string();
Expand All @@ -393,7 +393,7 @@ TEST_F(FileCacheTest, FileSystem)
ASSERT_TRUE(std::filesystem::exists(cache_root)) << cache_root.generic_string();
ASSERT_EQ(cache_root.generic_string(), cache_config.getDTFileCacheDir());

file_cache.removeDiskFile(local_fname2);
file_cache.removeDiskFile(local_fname2, false);
ASSERT_FALSE(std::filesystem::exists(local_file2)) << local_file2.generic_string();
ASSERT_FALSE(std::filesystem::exists(dmf)) << dmf.generic_string();
ASSERT_FALSE(std::filesystem::exists(table)) << table.generic_string();
Expand Down