From: Yehuda Sadeh Date: Wed, 19 Mar 2014 23:35:51 +0000 (-0700) Subject: rgw: user info uses cache chaining X-Git-Tag: v0.83~97^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a2f6709fd850574261dd7ef664e9fbc02a54ac15;p=ceph.git rgw: user info uses cache chaining Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_user.cc b/src/rgw/rgw_user.cc index 44e77ea56e2f..c1bf275828b5 100644 --- a/src/rgw/rgw_user.cc +++ b/src/rgw/rgw_user.cc @@ -199,40 +199,34 @@ struct user_info_entry { time_t mtime; }; - -static map uinfo_cache; -static RWLock uinfo_lock("uinfo_lock"); +static RGWChainedCacheImpl uinfo_cache; int rgw_get_user_info_from_index(RGWRados *store, string& key, rgw_bucket& bucket, RGWUserInfo& info, RGWObjVersionTracker *objv_tracker, time_t *pmtime) { - uinfo_lock.get_read(); - map::iterator uiter = uinfo_cache.find(key); - if (uiter != uinfo_cache.end()) { - user_info_entry& e = uiter->second; + user_info_entry e; + if (uinfo_cache.find(key, &e)) { info = e.info; if (objv_tracker) *objv_tracker = e.objv_tracker; if (pmtime) *pmtime = e.mtime; - uinfo_lock.unlock(); return 0; } - uinfo_lock.unlock(); bufferlist bl; RGWUID uid; - user_info_entry e; - int ret = rgw_get_system_obj(store, NULL, bucket, key, bl, NULL, &e.mtime); if (ret < 0) return ret; + rgw_cache_entry_info cache_info; + bufferlist::iterator iter = bl.begin(); try { ::decode(uid, iter); - int ret = rgw_get_user_info_by_uid(store, uid.user_id, e.info, &e.objv_tracker); + int ret = rgw_get_user_info_by_uid(store, uid.user_id, e.info, &e.objv_tracker, NULL, &cache_info); if (ret < 0) { return ret; } @@ -241,9 +235,7 @@ int rgw_get_user_info_from_index(RGWRados *store, string& key, rgw_bucket& bucke return -EIO; } - uinfo_lock.get_write(); - uinfo_cache[key] = e; - uinfo_lock.unlock(); + uinfo_cache.put(store, key, &e, cache_info); info = e.info; if (objv_tracker) @@ -259,12 +251,13 @@ int rgw_get_user_info_from_index(RGWRados *store, string& key, rgw_bucket& bucke * returns: 0 on success, -ERR# on failure (including nonexistence) */ int rgw_get_user_info_by_uid(RGWRados *store, string& uid, RGWUserInfo& info, - RGWObjVersionTracker *objv_tracker, time_t *pmtime) + RGWObjVersionTracker *objv_tracker, time_t *pmtime, + rgw_cache_entry_info *cache_info) { bufferlist bl; RGWUID user_id; - int ret = rgw_get_system_obj(store, NULL, store->zone.user_uid_pool, uid, bl, objv_tracker, pmtime); + int ret = rgw_get_system_obj(store, NULL, store->zone.user_uid_pool, uid, bl, objv_tracker, pmtime, NULL, cache_info); if (ret < 0) return ret; diff --git a/src/rgw/rgw_user.h b/src/rgw/rgw_user.h index 1a7020c2c00c..bf5c85c8d06a 100644 --- a/src/rgw/rgw_user.h +++ b/src/rgw/rgw_user.h @@ -59,7 +59,8 @@ extern int rgw_store_user_info(RGWRados *store, RGWUserInfo& info, RGWUserInfo * * returns: 0 on success, -ERR# on failure (including nonexistence) */ extern int rgw_get_user_info_by_uid(RGWRados *store, string& user_id, RGWUserInfo& info, - RGWObjVersionTracker *objv_tracker = NULL, time_t *pmtime = NULL); + RGWObjVersionTracker *objv_tracker = NULL, time_t *pmtime = NULL, + rgw_cache_entry_info *cache_info = NULL); /** * Given an swift username, finds the user info associated with it. * returns: 0 on success, -ERR# on failure (including nonexistence)