]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Have ChainedCacheImpl::find return an optional
authorAdam C. Emerson <aemerson@redhat.com>
Fri, 15 Dec 2017 21:39:19 +0000 (16:39 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Thu, 21 Dec 2017 20:44:43 +0000 (15:44 -0500)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/rgw/rgw_user.cc

index 96af0ab9d1502ae1838b887b0e5602fc0632680d..2cc1d628d43744faaa4b126da3baa7aa602d37b2 100644 (file)
@@ -11907,27 +11907,28 @@ int RGWRados::_get_bucket_info(RGWObjectCtx& obj_ctx,
                                map<string, bufferlist> *pattrs,
                                boost::optional<obj_version> refresh_version)
 {
-  bucket_info_entry e;
   string bucket_entry;
   rgw_make_bucket_entry_name(tenant, bucket_name, bucket_entry);
 
 
-  if (binfo_cache->find(bucket_entry, &e)) {
+  if (auto e = binfo_cache->find(bucket_entry)) {
     if (refresh_version &&
-        e.info.objv_tracker.read_version.compare(&(*refresh_version))) {
+        e->info.objv_tracker.read_version.compare(&(*refresh_version))) {
       lderr(cct) << "WARNING: The bucket info cache is inconsistent. This is "
                  << "a failure that should be debugged. I am a nice machine, "
                  << "so I will try to recover." << dendl;
       binfo_cache->invalidate(bucket_entry);
+    } else {
+      info = e->info;
+      if (pattrs)
+       *pattrs = e->attrs;
+      if (pmtime)
+       *pmtime = e->mtime;
+      return 0;
     }
-    info = e.info;
-    if (pattrs)
-      *pattrs = e.attrs;
-    if (pmtime)
-      *pmtime = e.mtime;
-    return 0;
   }
 
+  bucket_info_entry e;
   RGWBucketEntryPoint entry_point;
   real_time ep_mtime;
   RGWObjVersionTracker ot;
index 24330e273d7e76e48bec6a0fe530e589fa723bba..4240e5a53a4fadba9d5f11d1862f6d78197adc41 100644 (file)
@@ -3759,7 +3759,7 @@ class RGWChainedCacheImpl : public RGWChainedCache {
   ceph::timespan expiry;
   RWLock lock;
 
-  map<string, std::pair<T, ceph::coarse_mono_time>> entries;
+  std::unordered_map<std::string, std::pair<T, ceph::coarse_mono_time>> entries;
 
 public:
   RGWChainedCacheImpl() : lock("RGWChainedCacheImpl::lock") {}
@@ -3770,19 +3770,18 @@ public:
                                    "rgw_bucket_info_cache_expiry_interval"));
   }
 
-  bool find(const string& key, T *entry) {
+  boost::optional<T> find(const string& key) {
     RWLock::RLocker rl(lock);
     auto iter = entries.find(key);
     if (iter == entries.end()) {
-      return false;
+      return boost::none;
     }
     if (expiry.count() &&
        (ceph::coarse_mono_clock::now() - iter->second.second) > expiry) {
-      return false;
+      return boost::none;
     }
 
-    *entry = iter->second.first;
-    return true;
+    return iter->second.first;
   }
 
   bool put(RGWRados *store, const string& key, T *entry, list<rgw_cache_entry_info *>& cache_info_entries) {
index 210b01c8faa11546cae97d9e8cf26aa4003497b0..6a968efaa4be2ad4f5dc7c7177585f67bef5f491 100644 (file)
@@ -262,16 +262,16 @@ int rgw_get_user_info_from_index(RGWRados * const store,
                                  RGWObjVersionTracker * const objv_tracker,
                                  real_time * const pmtime)
 {
-  user_info_entry e;
-  if (uinfo_cache.find(key, &e)) {
-    info = e.info;
+  if (auto e = uinfo_cache.find(key)) {
+    info = e->info;
     if (objv_tracker)
-      *objv_tracker = e.objv_tracker;
+      *objv_tracker = e->objv_tracker;
     if (pmtime)
-      *pmtime = e.mtime;
+      *pmtime = e->mtime;
     return 0;
   }
 
+  user_info_entry e;
   bufferlist bl;
   RGWUID uid;
   RGWObjectCtx obj_ctx(store);