Skip to content

Commit

Permalink
Last test for fix listbucket
Browse files Browse the repository at this point in the history
  • Loading branch information
ggtakec committed Nov 23, 2023
1 parent 1b49cae commit c8b1bb0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 49 deletions.
73 changes: 26 additions & 47 deletions src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,17 @@ bool StatCache::AddStat(const std::string& key, const headers_t& meta, bool forc
}
S3FS_PRN_INFO3("add stat cache entry[path=%s]", key.c_str());

bool found;
bool do_truncate;
{
AutoLock lock(&StatCache::stat_cache_lock);
found = stat_cache.end() != stat_cache.find(key);
do_truncate = stat_cache.size() > CacheSize;
}
AutoLock lock(&StatCache::stat_cache_lock);

if(found){
DelStat(key.c_str());
if(stat_cache.end() != stat_cache.find(key)){
// found cache
DelStat(key.c_str(), AutoLock::ALREADY_LOCKED);
}else{
if(do_truncate){
// check: need to truncate cache
if(stat_cache.size() > CacheSize){
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress knownConditionTrueFalse
if(!TruncateCache()){
if(!TruncateCache(AutoLock::ALREADY_LOCKED)){
return false;
}
}
Expand Down Expand Up @@ -386,9 +382,6 @@ bool StatCache::AddStat(const std::string& key, const headers_t& meta, bool forc
}
}

// add
AutoLock lock(&StatCache::stat_cache_lock);

const auto& value = stat_cache[key] = std::move(ent);

// check symbolic link cache
Expand Down Expand Up @@ -465,21 +458,17 @@ bool StatCache::AddNoObjectCache(const std::string& key)
}
S3FS_PRN_INFO3("add no object cache entry[path=%s]", key.c_str());

bool found;
bool do_truncate;
{
AutoLock lock(&StatCache::stat_cache_lock);
found = stat_cache.end() != stat_cache.find(key);
do_truncate = stat_cache.size() > CacheSize;
}
AutoLock lock(&StatCache::stat_cache_lock);

if(found){
DelStat(key.c_str());
if(stat_cache.end() != stat_cache.find(key)){
// found
DelStat(key.c_str(), AutoLock::ALREADY_LOCKED);
}else{
if(do_truncate){
// check: need to truncate cache
if(stat_cache.size() > CacheSize){
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress knownConditionTrueFalse
if(!TruncateCache()){
if(!TruncateCache(AutoLock::ALREADY_LOCKED)){
return false;
}
}
Expand All @@ -495,9 +484,6 @@ bool StatCache::AddNoObjectCache(const std::string& key)
ent.meta.clear();
SetStatCacheTime(ent.cache_date); // Set time.

// add
AutoLock lock(&StatCache::stat_cache_lock);

stat_cache[key] = std::move(ent);

// check symbolic link cache
Expand Down Expand Up @@ -533,9 +519,9 @@ void StatCache::ChangeNoTruncateFlag(const std::string& key, bool no_truncate)
}
}

bool StatCache::TruncateCache()
bool StatCache::TruncateCache(AutoLock::Type locktype)
{
AutoLock lock(&StatCache::stat_cache_lock);
AutoLock lock(&StatCache::stat_cache_lock, locktype);

if(stat_cache.empty()){
return true;
Expand Down Expand Up @@ -675,21 +661,17 @@ bool StatCache::AddSymlink(const std::string& key, const std::string& value)
}
S3FS_PRN_INFO3("add symbolic link cache entry[path=%s, value=%s]", key.c_str(), value.c_str());

bool found;
bool do_truncate;
{
AutoLock lock(&StatCache::stat_cache_lock);
found = symlink_cache.end() != symlink_cache.find(key);
do_truncate = symlink_cache.size() > CacheSize;
}
AutoLock lock(&StatCache::stat_cache_lock);

if(found){
DelSymlink(key.c_str());
if(symlink_cache.end() != symlink_cache.find(key)){
// found
DelSymlink(key.c_str(), AutoLock::ALREADY_LOCKED);
}else{
if(do_truncate){
// check: need to truncate cache
if(symlink_cache.size() > CacheSize){
// cppcheck-suppress unmatchedSuppression
// cppcheck-suppress knownConditionTrueFalse
if(!TruncateSymlink()){
if(!TruncateSymlink(AutoLock::ALREADY_LOCKED)){
return false;
}
}
Expand All @@ -701,17 +683,14 @@ bool StatCache::AddSymlink(const std::string& key, const std::string& value)
ent.hit_count = 0;
SetStatCacheTime(ent.cache_date); // Set time(use the same as Stats).

// add
AutoLock lock(&StatCache::stat_cache_lock);

symlink_cache[key] = std::move(ent);

return true;
}

bool StatCache::TruncateSymlink()
bool StatCache::TruncateSymlink(AutoLock::Type locktype)
{
AutoLock lock(&StatCache::stat_cache_lock);
AutoLock lock(&StatCache::stat_cache_lock, locktype);

if(symlink_cache.empty()){
return true;
Expand Down Expand Up @@ -868,7 +847,7 @@ bool StatCache::GetNotruncateCache(const std::string& parentdir, notruncate_file

notruncate_dir_map_t::iterator iter = notruncate_file_cache.find(dirpath);
if(iter == notruncate_file_cache.end()){
// nothing to add
// not found directory map
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ class StatCache
void Clear();
bool GetStat(const std::string& key, struct stat* pst, headers_t* meta, bool overcheck, const char* petag, bool* pisforce);
// Truncate stat cache
bool TruncateCache();
bool TruncateCache(AutoLock::Type locktype = AutoLock::NONE);
// Truncate symbolic link cache
bool TruncateSymlink();
bool TruncateSymlink(AutoLock::Type locktype = AutoLock::NONE);

bool AddNotruncateCache(const std::string& key);
bool DelNotruncateCache(const std::string& key);
Expand Down

0 comments on commit c8b1bb0

Please sign in to comment.