Skip to content

Commit

Permalink
curvefs/client: fix bug cachedisk never trim
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhongsong committed Apr 29, 2022
1 parent 35a1bb3 commit 7941955
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
7 changes: 4 additions & 3 deletions curvefs/src/client/s3/disk_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ int DiskCacheManager::ClearReadCache(const std::list<std::string> &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();
}

Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion curvefs/src/client/s3/disk_cache_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion curvefs/src/client/s3/disk_cache_manager_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int DiskCacheManagerImpl::WriteReadDirect(const std::string fileName,
return ret;
}
// add cache.
diskCacheManager_->AddCache(fileName);
diskCacheManager_->AddCache(fileName, false);
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions curvefs/test/client/test_disk_cache_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7941955

Please sign in to comment.