Changed base cached time of stat_cache_expire option - #523

This commit is contained in:
Takeshi Nakatani 2017-03-19 15:19:04 +00:00
parent 277da2c64a
commit 523043a2aa
4 changed files with 28 additions and 11 deletions

View File

@ -138,7 +138,11 @@ time to wait between read/write activity before giving up.
maximum number of entries in the stat cache maximum number of entries in the stat cache
.TP .TP
\fB\-o\fR stat_cache_expire (default is no expire) \fB\-o\fR stat_cache_expire (default is no expire)
specify expire time(seconds) for entries in the stat cache specify expire time(seconds) for entries in the stat cache. This expire time indicates the time since stat cached.
.TP
\fB\-o\fR stat_cache_interval_expire (default is no expire)
specify expire time(seconds) for entries in the stat cache. This expire time is based on the time from the last access time of the stat cache.
This option is exclusive with stat_cache_expire, and is left for compatibility with older versions.
.TP .TP
\fB\-o\fR enable_noobj_cache (default is disable) \fB\-o\fR enable_noobj_cache (default is disable)
enable cache entries for the object which does not exist. enable cache entries for the object which does not exist.

View File

@ -142,7 +142,7 @@ pthread_mutex_t StatCache::stat_cache_lock;
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Constructor/Destructor // Constructor/Destructor
//------------------------------------------------------------------- //-------------------------------------------------------------------
StatCache::StatCache() : IsExpireTime(false), ExpireTime(0), CacheSize(1000), IsCacheNoObject(false) StatCache::StatCache() : IsExpireTime(false), IsExpireIntervalType(false), ExpireTime(0), CacheSize(1000), IsCacheNoObject(false)
{ {
if(this == StatCache::getStatCacheData()){ if(this == StatCache::getStatCacheData()){
stat_cache.clear(); stat_cache.clear();
@ -182,19 +182,21 @@ time_t StatCache::GetExpireTime(void) const
return (IsExpireTime ? ExpireTime : (-1)); return (IsExpireTime ? ExpireTime : (-1));
} }
time_t StatCache::SetExpireTime(time_t expire) time_t StatCache::SetExpireTime(time_t expire, bool is_interval)
{ {
time_t old = ExpireTime; time_t old = ExpireTime;
ExpireTime = expire; ExpireTime = expire;
IsExpireTime = true; IsExpireTime = true;
IsExpireIntervalType = is_interval;
return old; return old;
} }
time_t StatCache::UnsetExpireTime(void) time_t StatCache::UnsetExpireTime(void)
{ {
time_t old = IsExpireTime ? ExpireTime : (-1); time_t old = IsExpireTime ? ExpireTime : (-1);
ExpireTime = 0; ExpireTime = 0;
IsExpireTime = false; IsExpireTime = false;
IsExpireIntervalType = false;
return old; return old;
} }
@ -283,7 +285,10 @@ bool StatCache::GetStat(string& key, struct stat* pst, headers_t* meta, bool ove
(*pisforce) = ent->isforce; (*pisforce) = ent->isforce;
} }
ent->hit_count++; ent->hit_count++;
SetStatCacheTime(ent->cache_date);
if(IsExpireIntervalType){
SetStatCacheTime(ent->cache_date);
}
pthread_mutex_unlock(&StatCache::stat_cache_lock); pthread_mutex_unlock(&StatCache::stat_cache_lock);
return true; return true;
} }

View File

@ -55,6 +55,7 @@ class StatCache
static pthread_mutex_t stat_cache_lock; static pthread_mutex_t stat_cache_lock;
stat_cache_t stat_cache; stat_cache_t stat_cache;
bool IsExpireTime; bool IsExpireTime;
bool IsExpireIntervalType; // if this flag is true, cache data is updated at last access time.
time_t ExpireTime; time_t ExpireTime;
unsigned long CacheSize; unsigned long CacheSize;
bool IsCacheNoObject; bool IsCacheNoObject;
@ -78,7 +79,7 @@ class StatCache
unsigned long GetCacheSize(void) const; unsigned long GetCacheSize(void) const;
unsigned long SetCacheSize(unsigned long size); unsigned long SetCacheSize(unsigned long size);
time_t GetExpireTime(void) const; time_t GetExpireTime(void) const;
time_t SetExpireTime(time_t expire); time_t SetExpireTime(time_t expire, bool is_interval = false);
time_t UnsetExpireTime(void); time_t UnsetExpireTime(void);
bool SetCacheNoObject(bool flag); bool SetCacheNoObject(bool flag);
bool EnableCacheNoObject(void) { bool EnableCacheNoObject(void) {

View File

@ -4591,6 +4591,13 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
StatCache::getStatCacheData()->SetExpireTime(expr_time); StatCache::getStatCacheData()->SetExpireTime(expr_time);
return 0; return 0;
} }
// [NOTE]
// This option is for compatibility old version.
if(0 == STR2NCMP(arg, "stat_cache_interval_expire=")){
time_t expr_time = static_cast<time_t>(s3fs_strtoofft(strchr(arg, '=') + sizeof(char)));
StatCache::getStatCacheData()->SetExpireTime(expr_time, true);
return 0;
}
if(0 == strcmp(arg, "enable_noobj_cache")){ if(0 == strcmp(arg, "enable_noobj_cache")){
StatCache::getStatCacheData()->EnableCacheNoObject(); StatCache::getStatCacheData()->EnableCacheNoObject();
return 0; return 0;