]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: cache bucket info
authorYehuda Sadeh <yehuda@inktank.com>
Fri, 21 Feb 2014 00:25:21 +0000 (16:25 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Wed, 11 Jun 2014 06:08:56 +0000 (23:08 -0700)
This is really a partial implementation, so should only be used for
testing.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_rados.cc
src/rgw/rgw_user.cc

index b1025e2fd5cce3a79440726fea06201cd0aa787f..934ca9651313839cbf333568b5700639da680220 100644 (file)
@@ -5447,9 +5447,32 @@ int RGWRados::convert_old_bucket_info(void *ctx, string& bucket_name)
   return 0;
 }
 
+struct bucket_info_entry {
+  RGWBucketInfo info;
+  time_t mtime;
+  map<string, bufferlist> attrs;
+};
+
+static map<string, bucket_info_entry> binfo_cache;
+static RWLock binfo_lock("binfo_lock");
+
 int RGWRados::get_bucket_info(void *ctx, const string& bucket_name, RGWBucketInfo& info,
                               time_t *pmtime, map<string, bufferlist> *pattrs)
 {
+  binfo_lock.get_read();
+  map<string, bucket_info_entry>::iterator uiter = binfo_cache.find(bucket_name);
+  if (uiter != binfo_cache.end()) {
+    bucket_info_entry& e = uiter->second;
+    info = e.info;
+    if (pattrs)
+      *pattrs = e.attrs;
+    if (pmtime)
+      *pmtime = e.mtime;
+    binfo_lock.unlock();
+    return 0;
+  }
+  binfo_lock.unlock();
+
   bufferlist bl;
 
   RGWBucketEntryPoint entry_point;
@@ -5486,12 +5509,25 @@ int RGWRados::get_bucket_info(void *ctx, const string& bucket_name, RGWBucketInf
   string oid;
   get_bucket_meta_oid(entry_point.bucket, oid);
 
-  ret = get_bucket_instance_from_oid(ctx, oid, info, pmtime, pattrs);
-  info.ep_objv = ot.read_version;
+  bucket_info_entry e;
+
+  ret = get_bucket_instance_from_oid(ctx, oid, e.info, &e.mtime, &e.attrs);
+  e.info.ep_objv = ot.read_version;
+  info = e.info;
   if (ret < 0) {
     info.bucket.name = bucket_name;
     return ret;
   }
+
+  if (pmtime)
+    *pmtime = e.mtime;
+  if (pattrs)
+    *pattrs = e.attrs;
+
+  binfo_lock.get_write();
+  binfo_cache[bucket_name] = e;
+  binfo_lock.unlock();
+
   return 0;
 }
 
index 8d6b72deab3c9f261151498c6a48ecf39f4437bc..44e77ea56e2f88044b586280674d8fe0b4afd486 100644 (file)
@@ -206,9 +206,6 @@ static RWLock uinfo_lock("uinfo_lock");
 int rgw_get_user_info_from_index(RGWRados *store, string& key, rgw_bucket& bucket, RGWUserInfo& info,
                                  RGWObjVersionTracker *objv_tracker, time_t *pmtime)
 {
-  bufferlist bl;
-  RGWUID uid;
-
   uinfo_lock.get_read();
   map<string, user_info_entry>::iterator uiter = uinfo_cache.find(key);
   if (uiter != uinfo_cache.end()) {
@@ -223,6 +220,9 @@ int rgw_get_user_info_from_index(RGWRados *store, string& key, rgw_bucket& bucke
   }
   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);