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

curvefs/client: fix bug cachedisk never trim #1378

Merged
merged 1 commit into from
Apr 29, 2022
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
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);
wuhongsong marked this conversation as resolved.
Show resolved Hide resolved
diskCacheManager_->AddCache(fileName2);
ret = diskCacheManager_->IsCached(fileName);
ASSERT_EQ(true, ret);
Expand Down