Skip to content

Commit

Permalink
rgw: Add expiration in the object cache
Browse files Browse the repository at this point in the history
We had it in the chained caches, but it doesn't do much good if
they just fetch objects out of the object cache.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
  • Loading branch information
adamemerson committed Dec 19, 2017
1 parent b3249c3 commit a1a2c12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/rgw/rgw_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ int ObjectCache::get(string& name, ObjectCacheInfo& info, uint32_t mask, rgw_cac
}

auto iter = cache_map.find(name);
if (iter == cache_map.end()) {
if (iter == cache_map.end() ||
(expiry.count() &&
(ceph::coarse_mono_clock::now() - iter->second.info.time_added) > expiry)) {
ldout(cct, 10) << "cache get: name=" << name << " : miss" << dendl;
if(perfcounter) perfcounter->inc(l_rgw_cache_miss);
if (perfcounter)
perfcounter->inc(l_rgw_cache_miss);
return -ENOENT;
}

Expand Down
14 changes: 9 additions & 5 deletions src/rgw/rgw_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,17 @@ struct ObjectMetaInfo {
WRITE_CLASS_ENCODER(ObjectMetaInfo)

struct ObjectCacheInfo {
int status;
uint32_t flags;
uint64_t epoch;
int status = 0;
uint32_t flags = 0;
uint64_t epoch = 0;
bufferlist data;
map<string, bufferlist> xattrs;
map<string, bufferlist> rm_xattrs;
ObjectMetaInfo meta;
obj_version version;
obj_version version = {};
ceph::coarse_mono_time time_added = ceph::coarse_mono_clock::now();

ObjectCacheInfo() : status(0), flags(0), epoch(0), version() {}
ObjectCacheInfo() = default;

void encode(bufferlist& bl) const {
ENCODE_START(5, 3, bl);
Expand Down Expand Up @@ -147,6 +148,7 @@ class ObjectCache {
vector<RGWChainedCache *> chained_cache;

bool enabled;
ceph::timespan expiry;

void touch_lru(string& name, ObjectCacheEntry& entry,
std::deque<string>::iterator& lru_iter);
Expand All @@ -161,6 +163,8 @@ class ObjectCache {
void set_ctx(CephContext *_cct) {
cct = _cct;
lru_window = cct->_conf->rgw_cache_lru_size / 2;
expiry = std::chrono::seconds(cct->_conf->get_val<uint64_t>(
"rgw_cache_expiry_interval"));
}
bool chain_cache_entry(std::initializer_list<rgw_cache_entry_info*> cache_info_entries,
RGWChainedCache::Entry *chained_entry);
Expand Down

0 comments on commit a1a2c12

Please sign in to comment.