From 84bdd510213f3d723ffa7d1bcd6dbf5ed575242c Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Sun, 13 Mar 2016 09:29:06 +0000 Subject: [PATCH 1/2] Fixed a bug about etag comparison in stats cache. --- src/cache.cpp | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/cache.cpp b/src/cache.cpp index b1ac1ff..83d148d 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -243,16 +243,24 @@ bool StatCache::GetStat(string& key, struct stat* pst, headers_t* meta, bool ove return false; } // hit without checking etag + string stretag; if(petag){ - string stretag = ent->meta["ETag"]; - if('\0' != petag[0] && 0 != strcmp(petag, stretag.c_str())){ - is_delete_cache = true; + // find & check ETag + for(headers_t::iterator iter = ent->meta.begin(); iter != ent->meta.end(); ++iter){ + string tag = lower(iter->first); + if(tag == "etag"){ + stretag = iter->second; + if('\0' != petag[0] && 0 != strcmp(petag, stretag.c_str())){ + is_delete_cache = true; + } + break; + } } } if(is_delete_cache){ // not hit by different ETag S3FS_PRN_DBG("stat cache not hit by ETag[path=%s][time=%jd.%09ld][hit count=%lu][ETag(%s)!=(%s)]", - strpath.c_str(), (intmax_t)(ent->cache_date.tv_sec), ent->cache_date.tv_nsec, ent->hit_count, petag ? petag : "null", ent->meta["ETag"].c_str()); + strpath.c_str(), (intmax_t)(ent->cache_date.tv_sec), ent->cache_date.tv_nsec, ent->hit_count, petag ? petag : "null", stretag.c_str()); }else{ // hit S3FS_PRN_DBG("stat cache hit [path=%s][time=%jd.%09ld][hit count=%lu]", @@ -380,9 +388,19 @@ bool StatCache::AddStat(std::string& key, headers_t& meta, bool forcedir, bool n ent->meta[tag] = value; // key is lower case for "x-amz" } } + // add pthread_mutex_lock(&StatCache::stat_cache_lock); + + stat_cache_t::iterator iter = stat_cache.find(key); // recheck for same key exists + if(stat_cache.end() != iter){ + if(iter->second){ + delete iter->second; + } + stat_cache.erase(iter); + } stat_cache[key] = ent; + pthread_mutex_unlock(&StatCache::stat_cache_lock); return true; @@ -424,9 +442,19 @@ bool StatCache::AddNoObjectCache(string& key) ent->notruncate = 0L; ent->meta.clear(); SetStatCacheTime(ent->cache_date); // Set time. + // add pthread_mutex_lock(&StatCache::stat_cache_lock); + + stat_cache_t::iterator iter = stat_cache.find(key); // recheck for same key exists + if(stat_cache.end() != iter){ + if(iter->second){ + delete iter->second; + } + stat_cache.erase(iter); + } stat_cache[key] = ent; + pthread_mutex_unlock(&StatCache::stat_cache_lock); return true; From 98d55582eb467812210bdd72ee995001fae9be6e Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Sun, 13 Mar 2016 09:47:37 +0000 Subject: [PATCH 2/2] Chnaged about constructor(destructor) in cache.h --- src/cache.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cache.h b/src/cache.h index 63e5664..d4b6630 100644 --- a/src/cache.h +++ b/src/cache.h @@ -60,15 +60,15 @@ class StatCache bool IsCacheNoObject; private: + StatCache(); + ~StatCache(); + void Clear(void); bool GetStat(std::string& key, struct stat* pst, headers_t* meta, bool overcheck, const char* petag, bool* pisforce); // Truncate stat cache bool TruncateCache(void); public: - StatCache(); - ~StatCache(); - // Reference singleton static StatCache* getStatCacheData(void) { return &singleton;