]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: user info uses cache chaining
authorYehuda Sadeh <yehuda@inktank.com>
Wed, 19 Mar 2014 23:35:51 +0000 (16:35 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 11 Jun 2014 06:08:57 +0000 (23:08 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_user.cc
src/rgw/rgw_user.h

index 44e77ea56e2f88044b586280674d8fe0b4afd486..c1bf275828b512be94d169214d41746a0607d517 100644 (file)
@@ -199,40 +199,34 @@ struct user_info_entry {
   time_t mtime;
 };
 
-
-static map<string, user_info_entry> uinfo_cache;
-static RWLock uinfo_lock("uinfo_lock");
+static RGWChainedCacheImpl<user_info_entry> 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<string, user_info_entry>::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;
 
index 1a7020c2c00c5c6957bd43f48b5b311466457c00..bf5c85c8d06aa2b154aa8cebadf6ea05a54b26c2 100644 (file)
@@ -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)