Refactor StatCache words from NoObject to Negative

This commit is contained in:
Takeshi Nakatani
2025-05-31 09:21:59 +00:00
committed by Andrew Gaul
parent 778059279b
commit be28fbc7b8
5 changed files with 47 additions and 32 deletions

View File

@ -168,10 +168,16 @@ specify expire time (seconds) for entries in the stat cache and symbolic link ca
specify expire time (seconds) for entries in the stat cache and symbolic link cache. This expire time is based on the time from the last access time of those cache.
This option is exclusive with stat_cache_expire, and is left for compatibility with older versions.
.TP
\fB\-o\fR disable_noobj_cache (default is enable)
By default s3fs memorizes when an object does not exist up until the stat cache timeout.
This caching can cause staleness for applications.
If disabled, s3fs will not memorize objects and may cause extra HeadObject requests and reduce performance.
\fB\-o\fR enable_negative_cache (default is enabled negative cache)
This option will keep non-existence of objects in a stat cache.
When this negative cache is enabled, it will not process extra HeadObject requests to search for non-existent objects, improving performance.
This feature is enabled by default, so there is no need to specify it.
.TP
\fB\-o\fR disable_negative_cache (default is enabled negative cache)
By default, s3fs keeps non-existent objects in the stat cache.
This option disables this negative caching.
This prevents delays in updates due to cache retention.
However, it may increase the number of HeadObject requests to check if an object exists, which may decrease performance.
.TP
\fB\-o\fR no_check_certificate (by default this option is disabled)
server certificate won't be checked against the available certificate authorities.
@ -515,13 +521,13 @@ s3fs is a multi-threaded application. Depending on the workload it may use multi
.TP
s3fs provides several options (e.g. "max_thread_count" option) to control behaviour and thus indirectly the performance. The possible combinations of these options in conjunction with the various S3 backends are so varied that there is no individual recommendation other than the default values. Improved individual settings can be found by testing and measuring.
.TP
The two options "Enable no object cache" ("\-o enable_noobj_cache") and "Disable support of alternative directory names" ("\-o notsup_compat_dir") can be used to control shared access to the same bucket by different applications:
The two options "Enable negative cache" ("\-o enable_negative_cache") and "Disable support of alternative directory names" ("\-o notsup_compat_dir") can be used to control shared access to the same bucket by different applications:
.TP
.IP \[bu]
Enable no object cache ("\-o enable_noobj_cache")
Enable negative cache ("\-o enable_negative_cache")
.RS
.TP
If a bucket is used exclusively by an s3fs instance, you can enable the cache for non-existent files and directories with "\-o enable_noobj_cache". This eliminates repeated requests to check the existence of an object, saving time and possibly money.
If a bucket is used exclusively by an s3fs instance, you can enable the cache for non-existent files and directories with "\-o enable_negative_cache". This eliminates repeated requests to check the existence of an object, saving time and possibly money.
.RE
.IP \[bu]
Enable support of alternative directory names ("\-o compat_dir")

View File

@ -119,7 +119,7 @@ std::mutex StatCache::stat_cache_lock;
//-------------------------------------------------------------------
// Constructor/Destructor
//-------------------------------------------------------------------
StatCache::StatCache() : IsExpireTime(true), IsExpireIntervalType(false), ExpireTime(15 * 60), CacheSize(100'000), IsCacheNoObject(true)
StatCache::StatCache() : IsExpireTime(true), IsExpireIntervalType(false), ExpireTime(15 * 60), CacheSize(100'000), UseNegativeCache(true)
{
if(this == StatCache::getStatCacheData()){
stat_cache.clear();
@ -175,10 +175,10 @@ time_t StatCache::UnsetExpireTime()
return old;
}
bool StatCache::SetCacheNoObject(bool flag)
bool StatCache::SetNegativeCache(bool flag)
{
bool old = IsCacheNoObject;
IsCacheNoObject = flag;
bool old = UseNegativeCache;
UseNegativeCache = flag;
return old;
}
@ -222,7 +222,7 @@ bool StatCache::GetStat(const std::string& key, struct stat* pst, headers_t* met
// No object
if(ent->noobjcache){
if(!IsCacheNoObject){
if(!UseNegativeCache){
// need to delete this cache.
DelStatHasLock(strpath);
}else{
@ -275,7 +275,7 @@ bool StatCache::GetStat(const std::string& key, struct stat* pst, headers_t* met
bool StatCache::IsNoObjectCache(const std::string& key, bool overcheck)
{
if(!IsCacheNoObject){
if(!UseNegativeCache){
return false;
}
const std::lock_guard<std::mutex> lock(StatCache::stat_cache_lock);
@ -433,7 +433,7 @@ bool StatCache::UpdateMetaStats(const std::string& key, const headers_t& meta)
bool StatCache::AddNoObjectCache(const std::string& key)
{
if(!IsCacheNoObject){
if(!UseNegativeCache){
return true; // pretend successful
}
if(CacheSize < 1){

View File

@ -88,7 +88,7 @@ class StatCache
bool IsExpireIntervalType; // if this flag is true, cache data is updated at last access time.
time_t ExpireTime;
unsigned long CacheSize;
bool IsCacheNoObject;
bool UseNegativeCache;
symlink_cache_t symlink_cache GUARDED_BY(stat_cache_lock);
notruncate_dir_map_t notruncate_file_cache GUARDED_BY(stat_cache_lock);
@ -126,18 +126,18 @@ class StatCache
time_t GetExpireTime() const;
time_t SetExpireTime(time_t expire, bool is_interval = false);
time_t UnsetExpireTime();
bool SetCacheNoObject(bool flag);
bool EnableCacheNoObject()
bool SetNegativeCache(bool flag);
bool EnableNegativeCache()
{
return SetCacheNoObject(true);
return SetNegativeCache(true);
}
bool DisableCacheNoObject()
bool DisableNegativeCache()
{
return SetCacheNoObject(false);
return SetNegativeCache(false);
}
bool GetCacheNoObject() const
bool IsEnabledNegativeCache() const
{
return IsCacheNoObject;
return UseNegativeCache;
}
// Get stat cache

View File

@ -4973,13 +4973,13 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
StatCache::getStatCacheData()->SetExpireTime(expr_time, true);
return 0;
}
else if(0 == strcmp(arg, "enable_noobj_cache")){
S3FS_PRN_WARN("enable_noobj_cache is enabled by default and a future version will remove this option.");
StatCache::getStatCacheData()->EnableCacheNoObject();
else if(0 == strcmp(arg, "enable_negative_cache") || 0 == strcmp(arg, "enable_noobj_cache")){
S3FS_PRN_WARN("enable_negative_cache(enable_noobj_cache) is enabled by default and a future version will remove this option.");
StatCache::getStatCacheData()->EnableNegativeCache();
return 0;
}
else if(0 == strcmp(arg, "disable_noobj_cache")){
StatCache::getStatCacheData()->DisableCacheNoObject();
else if(0 == strcmp(arg, "disable_negative_cache") || 0 == strcmp(arg, "disable_noobj_cache")){
StatCache::getStatCacheData()->DisableNegativeCache();
return 0;
}
else if(0 == strcmp(arg, "nodnscache")){

View File

@ -204,11 +204,20 @@ static constexpr char help_string[] =
" of the stat cache. This option is exclusive with stat_cache_expire,\n"
" and is left for compatibility with older versions.\n"
"\n"
" disable_noobj_cache (default is enable)\n"
" - By default s3fs memorizes when an object does not exist up until\n"
" the stat cache timeout. This caching can cause staleness for\n"
" applications. If disabled, s3fs will not memorize objects and may\n"
" cause extra HeadObject requests and reduce performance.\n"
" enable_negative_cache (default is enabled negative cache)\n"
" - This option will keep non-existence of objects in a stat cache.\n"
" When this negative cache is enabled, it will not process extra\n"
" HeadObject requests to search for non-existent objects, improving\n"
" performance.\n"
" This feature is enabled by default, so there is no need to specify\n"
" it.\n"
"\n"
" disable_negative_cache (default is enabled negative cache)\n"
" - By default, s3fs keeps non-existent objects in the stat cache.\n"
" This option disables this negative caching.\n"
" This prevents delays in updates due to cache retention.\n"
" However, it may increase the number of HeadObject requests to check\n"
" if an object exists, which may decrease performance.\n"
"\n"
" no_check_certificate\n"
" - server certificate won't be checked against the available \n"