From 6174cb9f7db3ffea8f7477b063c221671802faf6 Mon Sep 17 00:00:00 2001 From: "hzwuhongsong@corp.netease.com" Date: Fri, 29 Apr 2022 13:59:05 +0800 Subject: [PATCH] curvefs/client: fix bug cachedisk never trim --- curvefs/src/client/s3/disk_cache_manager.cpp | 7 ++++--- curvefs/src/client/s3/disk_cache_manager.h | 5 ++++- curvefs/src/client/s3/disk_cache_manager_impl.cpp | 2 +- curvefs/test/client/test_disk_cache_manager.cpp | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/curvefs/src/client/s3/disk_cache_manager.cpp b/curvefs/src/client/s3/disk_cache_manager.cpp index eea54e7cff..325f8d8719 100644 --- a/curvefs/src/client/s3/disk_cache_manager.cpp +++ b/curvefs/src/client/s3/disk_cache_manager.cpp @@ -155,8 +155,9 @@ int DiskCacheManager::ClearReadCache(const std::list &files) { return cacheRead_->ClearReadCache(files); } -void DiskCacheManager::AddCache(const std::string name) { - cachedObjName_->Put(name, true); +void DiskCacheManager::AddCache(const std::string name, + bool cacheWriteExist) { + cachedObjName_->Put(name, cacheWriteExist); VLOG(9) << "cache size is: " << cachedObjName_->Size(); } @@ -349,7 +350,7 @@ void DiskCacheManager::TrimCache() { SetDiskFsUsedRatio(); while (!IsDiskCacheSafe()) { if (!cachedObjName_->GetLast(false, &cacheKey)) { - VLOG(3) << "obj is empty"; + VLOG(9) << "obj is empty"; break; } diff --git a/curvefs/src/client/s3/disk_cache_manager.h b/curvefs/src/client/s3/disk_cache_manager.h index ec12c84ecf..150484553f 100644 --- a/curvefs/src/client/s3/disk_cache_manager.h +++ b/curvefs/src/client/s3/disk_cache_manager.h @@ -69,8 +69,11 @@ class DiskCacheManager { /** * @brief add obj to cachedObjName * @param[in] name obj name + * @param[in] cacheWriteExist whether the obj is + * exist in cache write */ - void AddCache(const std::string name); + void AddCache(const std::string name, + bool cacheWriteExist = true); int CreateDir(); std::string GetCacheReadFullDir(); diff --git a/curvefs/src/client/s3/disk_cache_manager_impl.cpp b/curvefs/src/client/s3/disk_cache_manager_impl.cpp index 486e493422..88e8a739f4 100644 --- a/curvefs/src/client/s3/disk_cache_manager_impl.cpp +++ b/curvefs/src/client/s3/disk_cache_manager_impl.cpp @@ -135,7 +135,7 @@ int DiskCacheManagerImpl::WriteReadDirect(const std::string fileName, return ret; } // add cache. - diskCacheManager_->AddCache(fileName); + diskCacheManager_->AddCache(fileName, false); return ret; } diff --git a/curvefs/test/client/test_disk_cache_manager.cpp b/curvefs/test/client/test_disk_cache_manager.cpp index c99d24d1bf..588cd62b00 100644 --- a/curvefs/test/client/test_disk_cache_manager.cpp +++ b/curvefs/test/client/test_disk_cache_manager.cpp @@ -194,12 +194,12 @@ TEST_F(TestDiskCacheManager, IsCached) { bool ret = diskCacheManager_->IsCached(fileName); ASSERT_EQ(false, ret); - diskCacheManager_->AddCache(fileName); + diskCacheManager_->AddCache(fileName, false); diskCacheManager_->AddCache(fileName2); ret = diskCacheManager_->IsCached(fileName2); ASSERT_EQ(true, ret); - diskCacheManager_->AddCache(fileName); + diskCacheManager_->AddCache(fileName, false); diskCacheManager_->AddCache(fileName2); ret = diskCacheManager_->IsCached(fileName); ASSERT_EQ(true, ret);