Fixed a bug about etag comparison in stats cache.

This commit is contained in:
Takeshi Nakatani 2016-03-13 09:29:06 +00:00
parent fbd8959d69
commit 84bdd51021

View File

@ -243,16 +243,24 @@ bool StatCache::GetStat(string& key, struct stat* pst, headers_t* meta, bool ove
return false; return false;
} }
// hit without checking etag // hit without checking etag
string stretag;
if(petag){ if(petag){
string stretag = ent->meta["ETag"]; // find & check ETag
if('\0' != petag[0] && 0 != strcmp(petag, stretag.c_str())){ for(headers_t::iterator iter = ent->meta.begin(); iter != ent->meta.end(); ++iter){
is_delete_cache = true; 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){ if(is_delete_cache){
// not hit by different ETag // 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)]", 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{ }else{
// hit // hit
S3FS_PRN_DBG("stat cache hit [path=%s][time=%jd.%09ld][hit count=%lu]", 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" ent->meta[tag] = value; // key is lower case for "x-amz"
} }
} }
// add // add
pthread_mutex_lock(&StatCache::stat_cache_lock); 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; stat_cache[key] = ent;
pthread_mutex_unlock(&StatCache::stat_cache_lock); pthread_mutex_unlock(&StatCache::stat_cache_lock);
return true; return true;
@ -424,9 +442,19 @@ bool StatCache::AddNoObjectCache(string& key)
ent->notruncate = 0L; ent->notruncate = 0L;
ent->meta.clear(); ent->meta.clear();
SetStatCacheTime(ent->cache_date); // Set time. SetStatCacheTime(ent->cache_date); // Set time.
// add // add
pthread_mutex_lock(&StatCache::stat_cache_lock); 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; stat_cache[key] = ent;
pthread_mutex_unlock(&StatCache::stat_cache_lock); pthread_mutex_unlock(&StatCache::stat_cache_lock);
return true; return true;