Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Lloyd-Pottiger <[email protected]>
  • Loading branch information
Lloyd-Pottiger committed Aug 30, 2024
1 parent 8a683ef commit cf08835
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 35 deletions.
4 changes: 2 additions & 2 deletions dbms/src/Storages/S3/FileCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ bool FileCache::reserveSpaceImpl(FileType reserve_for, UInt64 size, EvictMode ev
if (evict == EvictMode::TryEvict || evict == EvictMode::ForceEvict)
{
UInt64 min_evict_size = size - (cache_capacity - cache_used);
LOG_DEBUG( //
LOG_DEBUG(
log,
"tryEvictFile for {} min_evict_size={} evict_mode={}",
magic_enum::enum_name(reserve_for),
Expand Down Expand Up @@ -656,7 +656,7 @@ bool FileCache::finalizeReservedSize(FileType reserve_for, UInt64 reserved_size,
if (content_length > reserved_size)
{
// Need more space.
return reserveSpace(reserve_for, content_length - reserved_size, /*try_evict*/ EvictMode::TryEvict);
return reserveSpace(reserve_for, content_length - reserved_size, EvictMode::TryEvict);
}
else if (content_length < reserved_size)
{
Expand Down
64 changes: 31 additions & 33 deletions dbms/src/Storages/S3/tests/gtest_filecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <chrono>
#include <filesystem>
#include <fstream>
#include <numeric>
#include <random>
#include <thread>

Expand Down Expand Up @@ -229,7 +228,7 @@ class FileCacheTest : public ::testing::Test

String tmp_dir;
UInt64 cache_capacity = 100 * 1024 * 1024;
UInt64 cache_level = 5;
const UInt64 cache_level = 5;
UInt64 cache_min_age_seconds = 30 * 60;
LoggerPtr log;
PathCapacityMetricsPtr capacity_metrics;
Expand Down Expand Up @@ -445,12 +444,12 @@ try
ASSERT_EQ(FileCache::getFileType(unknow_fname1), FileType::Unknow);

{
UInt64 cache_level_ = 0;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level_);
const UInt64 cache_level = 0;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level);
StorageRemoteCacheConfig cache_config{
.dir = cache_dir,
.capacity = cache_capacity,
.dtfile_level = cache_level_};
.dtfile_level = cache_level};
FileCache file_cache(capacity_metrics, cache_config);
ASSERT_FALSE(file_cache.canCache(FileType::Unknow));
ASSERT_FALSE(file_cache.canCache(FileType::Meta));
Expand All @@ -464,12 +463,12 @@ try
ASSERT_FALSE(file_cache.canCache(FileType::ColData));
}
{
UInt64 cache_level_ = 1;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level_);
const UInt64 cache_level = 1;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level);
StorageRemoteCacheConfig cache_config{
.dir = cache_dir,
.capacity = cache_capacity,
.dtfile_level = cache_level_};
.dtfile_level = cache_level};
FileCache file_cache(capacity_metrics, cache_config);
ASSERT_FALSE(file_cache.canCache(FileType::Unknow));
ASSERT_TRUE(file_cache.canCache(FileType::Meta));
Expand All @@ -483,12 +482,12 @@ try
ASSERT_FALSE(file_cache.canCache(FileType::ColData));
}
{
UInt64 cache_level_ = 2;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level_);
const UInt64 cache_level = 2;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level);
StorageRemoteCacheConfig cache_config{
.dir = cache_dir,
.capacity = cache_capacity,
.dtfile_level = cache_level_};
.dtfile_level = cache_level};
FileCache file_cache(capacity_metrics, cache_config);
ASSERT_FALSE(file_cache.canCache(FileType::Unknow));
ASSERT_TRUE(file_cache.canCache(FileType::Meta));
Expand All @@ -502,12 +501,12 @@ try
ASSERT_FALSE(file_cache.canCache(FileType::ColData));
}
{
UInt64 cache_level_ = 3;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level_);
const UInt64 cache_level = 3;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level);
StorageRemoteCacheConfig cache_config{
.dir = cache_dir,
.capacity = cache_capacity,
.dtfile_level = cache_level_};
.dtfile_level = cache_level};
FileCache file_cache(capacity_metrics, cache_config);
ASSERT_FALSE(file_cache.canCache(FileType::Unknow));
ASSERT_TRUE(file_cache.canCache(FileType::Meta));
Expand All @@ -521,12 +520,12 @@ try
ASSERT_FALSE(file_cache.canCache(FileType::ColData));
}
{
UInt64 cache_level_ = 4;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level_);
const UInt64 cache_level = 4;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level);
StorageRemoteCacheConfig cache_config{
.dir = cache_dir,
.capacity = cache_capacity,
.dtfile_level = cache_level_};
.dtfile_level = cache_level};
FileCache file_cache(capacity_metrics, cache_config);
ASSERT_FALSE(file_cache.canCache(FileType::Unknow));
ASSERT_TRUE(file_cache.canCache(FileType::Meta));
Expand All @@ -540,12 +539,12 @@ try
ASSERT_FALSE(file_cache.canCache(FileType::ColData));
}
{
UInt64 cache_level_ = 5;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level_);
const UInt64 cache_level = 5;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level);
StorageRemoteCacheConfig cache_config{
.dir = cache_dir,
.capacity = cache_capacity,
.dtfile_level = cache_level_};
.dtfile_level = cache_level};
FileCache file_cache(capacity_metrics, cache_config);
ASSERT_FALSE(file_cache.canCache(FileType::Unknow));
ASSERT_TRUE(file_cache.canCache(FileType::Meta));
Expand All @@ -559,12 +558,12 @@ try
ASSERT_FALSE(file_cache.canCache(FileType::ColData));
}
{
UInt64 cache_level_ = 6;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level_);
const UInt64 cache_level = 6;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level);
StorageRemoteCacheConfig cache_config{
.dir = cache_dir,
.capacity = cache_capacity,
.dtfile_level = cache_level_};
.dtfile_level = cache_level};
FileCache file_cache(capacity_metrics, cache_config);
ASSERT_FALSE(file_cache.canCache(FileType::Unknow));
ASSERT_TRUE(file_cache.canCache(FileType::Meta));
Expand All @@ -578,12 +577,12 @@ try
ASSERT_FALSE(file_cache.canCache(FileType::ColData));
}
{
UInt64 cache_level_ = 7;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level_);
const UInt64 cache_level = 7;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level);
StorageRemoteCacheConfig cache_config{
.dir = cache_dir,
.capacity = cache_capacity,
.dtfile_level = cache_level_};
.dtfile_level = cache_level};
FileCache file_cache(capacity_metrics, cache_config);
ASSERT_FALSE(file_cache.canCache(FileType::Unknow));
ASSERT_TRUE(file_cache.canCache(FileType::Meta));
Expand All @@ -597,12 +596,12 @@ try
ASSERT_FALSE(file_cache.canCache(FileType::ColData));
}
{
UInt64 cache_level_ = 8;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level_);
const UInt64 cache_level = 8;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level);
StorageRemoteCacheConfig cache_config{
.dir = cache_dir,
.capacity = cache_capacity,
.dtfile_level = cache_level_};
.dtfile_level = cache_level};
FileCache file_cache(capacity_metrics, cache_config);
ASSERT_FALSE(file_cache.canCache(FileType::Unknow));
ASSERT_TRUE(file_cache.canCache(FileType::Meta));
Expand All @@ -616,12 +615,12 @@ try
ASSERT_FALSE(file_cache.canCache(FileType::ColData));
}
{
UInt64 cache_level_ = 9;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level_);
const UInt64 cache_level = 9;
auto cache_dir = fmt::format("{}/filetype{}", tmp_dir, cache_level);
StorageRemoteCacheConfig cache_config{
.dir = cache_dir,
.capacity = cache_capacity,
.dtfile_level = cache_level_};
.dtfile_level = cache_level};
FileCache file_cache(capacity_metrics, cache_config);
ASSERT_FALSE(file_cache.canCache(FileType::Unknow));
ASSERT_TRUE(file_cache.canCache(FileType::Meta));
Expand Down Expand Up @@ -879,7 +878,6 @@ try
}
CATCH


TEST_F(FileCacheTest, ForceEvict)
try
{
Expand Down

0 comments on commit cf08835

Please sign in to comment.