]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: fix xattrs cache
authorYehuda Sadeh <yehuda@hq.newdream.net>
Fri, 21 Oct 2011 23:14:11 +0000 (16:14 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Fri, 21 Oct 2011 23:14:11 +0000 (16:14 -0700)
src/rgw/rgw_access.h
src/rgw/rgw_cache.h
src/rgw/rgw_fs.cc
src/rgw/rgw_fs.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index 91ccf059e47db3316cc671191d3b435b04258327..0e421dc22687ebe5b3e66c5fc57c89b1929b443a 100644 (file)
@@ -235,7 +235,7 @@ public:
  /**
   * stat an object
   */
-  virtual int obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime) = 0;
+  virtual int obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, map<string, bufferlist> *attrs) = 0;
 
   virtual bool supports_tmap() { return false; }
 
index 865513cf69fcc7772014abe51aeeafa17c66b2b5..07ca9ac10052f1e0a3d39777872553ea37d0530a 100644 (file)
@@ -163,7 +163,7 @@ public:
 
   int get_obj(void *ctx, void **handle, rgw_obj& obj, char **data, off_t ofs, off_t end);
 
-  int obj_stat(void *ctx, rgw_bucket& bucket, std::string& obj, uint64_t *psize, time_t *pmtime);
+  int obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, map<string, bufferlist> *attrs);
 
   int delete_obj(void *ctx, std::string& id, rgw_obj& obj, bool sync);
 };
@@ -261,20 +261,20 @@ int RGWCache<T>::put_obj_data(void *ctx, std::string& id, rgw_obj& obj, const ch
 }
 
 template <class T>
-int RGWCache<T>::obj_stat(void *ctx, rgw_bucket& bucket, std::string& obj, uint64_t *psize, time_t *pmtime)
+int RGWCache<T>::obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, map<string, bufferlist> *attrs)
 {
-  if (bucket.name[0] != '.')
-    return T::obj_stat(ctx, bucket, obj, psize, pmtime);
+  string& bucket_name = obj.bucket.name;
+  string& oid = obj.object;
+  if (bucket_name[0] != '.')
+    return T::obj_stat(ctx, obj, psize, pmtime, attrs);
 
-  string name = normal_name(bucket, obj);
+  string name = normal_name(obj.bucket, oid);
 
   uint64_t size;
   time_t mtime;
-  int64_t t;
 
   ObjectCacheInfo info;
-  bufferlist& bl = info.data;
-  int r = cache.get(name, info, CACHE_FLAG_META);
+  int r = cache.get(name, info, CACHE_FLAG_META | CACHE_FLAG_XATTRS);
   if (r == 0) {
     if (info.status < 0)
       return info.status;
@@ -283,7 +283,7 @@ int RGWCache<T>::obj_stat(void *ctx, rgw_bucket& bucket, std::string& obj, uint6
     mtime = info.meta.mtime;
     goto done;
   }
-  r = T::obj_stat(ctx, bucket, obj, &size, &mtime);
+  r = T::obj_stat(ctx, obj, &size, &mtime, &info.xattrs);
   if (r < 0) {
     if (r == -ENOENT) {
       info.status = r;
@@ -294,13 +294,15 @@ int RGWCache<T>::obj_stat(void *ctx, rgw_bucket& bucket, std::string& obj, uint6
   info.status = 0;
   info.meta.mtime = mtime;
   info.meta.size = size;
-  info.flags = CACHE_FLAG_META;
+  info.flags = CACHE_FLAG_META | CACHE_FLAG_XATTRS;
   cache.put(name, info);
 done:
   if (psize)
     *psize = size;
   if (pmtime)
     *pmtime = mtime;
+  if (attrs)
+    *attrs = info.xattrs;
   return 0;
 }
 
index aa582fb4cfd906b5f1a39046ef2b26fc8a706d47..7c14ec520121317c405c378e6aa798712de1ba4d 100644 (file)
@@ -91,7 +91,7 @@ int RGWFS::list_buckets_next(string& id, RGWObjEnt& obj, RGWAccessHandle *handle
   }
 }
 
-int RGWFS::obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime)
+int RGWFS::obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, map<string, bufferlist> *attrs)
 {
   return -ENOTSUP;
 }
index 783d7beba2abdd8bd320f922c7a4eda25fb0fbdb..ec1957afc1f61221f8749da35c6ba9cb7b05a043 100644 (file)
@@ -60,7 +60,7 @@ public:
 
   void finish_get_obj(void **handle);
   int read(void *ctx, rgw_obj& obj, off_t ofs, size_t size, bufferlist& bl);
-  int obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime);
+  int obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, map<string, bufferlist> *attrs);
 
   virtual int get_bucket_info(void *ctx, string& bucket_name, RGWBucketInfo& info);
 };
index 9e23e4d2e589364220cf434249d087bb66407fcf..d73273fafcba4e2e6879f4786f3dbb753da553e0 100644 (file)
@@ -827,7 +827,7 @@ int RGWRados::copy_obj(void *ctx, std::string& id,
 
   ret = clone_obj(ctx, dest_obj, 0, tmp_obj, 0, end + 1, NULL, attrs, category);
   if (mtime)
-    obj_stat(ctx, tmp_obj, NULL, mtime);
+    obj_stat(ctx, tmp_obj, NULL, mtime, NULL);
 
   r = rgwstore->delete_obj(ctx, id, tmp_obj, false);
   if (r < 0)
@@ -1029,7 +1029,7 @@ int RGWRados::delete_obj_impl(void *ctx, std::string& id, rgw_obj& obj, bool syn
       return r;
     r = io_ctx.operate(oid, &op);
 
-    if (r >= 0 && bucket.marker.size()) {
+    if ((r >= 0 || r == -ENOENT) && bucket.marker.size()) {
       uint64_t epoch = io_ctx.get_last_version();
       r = complete_update_index_del(bucket, obj.object, tag, epoch);
     }
@@ -1071,7 +1071,7 @@ int RGWRados::get_obj_state(RGWRadosCtx *rctx, rgw_obj& obj, librados::IoCtx& io
   op.getxattrs();
   op.stat();
   bufferlist outbl;
-  int r = io_ctx.operate(actual_obj, &op, &outbl);
+  int r = obj_stat(rctx, obj, &s->size, &s->mtime, &s->attrset);
   if (r == -ENOENT) {
     s->exists = false;
     s->has_attrs = true;
@@ -1082,29 +1082,6 @@ int RGWRados::get_obj_state(RGWRadosCtx *rctx, rgw_obj& obj, librados::IoCtx& io
     return r;
 
   s->exists = true;
-
-  bufferlist::iterator oiter = outbl.begin();
-  try {
-    ::decode(s->attrset, oiter);
-  } catch (buffer::error& err) {
-    dout(0) << "ERROR: failed decoding s->attrset (obj=" << obj << "), aborting" << dendl;
-    return -EIO;
-  }
-
-  map<string, bufferlist>::iterator aiter;
-  for (aiter = s->attrset.begin(); aiter != s->attrset.end(); ++aiter) {
-    dout(0) << "iter->first=" << aiter->first << dendl;
-  }
-
-  try {
-    ::decode(s->size, oiter);
-    utime_t ut;
-    ::decode(ut, oiter);
-    s->mtime = ut.sec();
-  } catch (buffer::error& err) {
-    dout(0) << "ERROR: failed decoding object (obj=" << obj << ") info (either size or mtime), aborting" << dendl;
-  }
-
   s->has_attrs = true;
   map<string, bufferlist>::iterator iter = s->attrset.find(RGW_ATTR_SHADOW_OBJ);
   if (iter != s->attrset.end()) {
@@ -1758,37 +1735,58 @@ int RGWRados::read(void *ctx, rgw_obj& obj, off_t ofs, size_t size, bufferlist&
   return r;
 }
 
-int RGWRados::obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime)
+int RGWRados::obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, map<string, bufferlist> *attrs)
 {
   rgw_bucket bucket;
   std::string oid, key;
   get_obj_bucket_and_oid_key(obj, bucket, oid, key);
   librados::IoCtx io_ctx;
-  RGWRadosCtx *rctx = (RGWRadosCtx *)ctx;
   int r = open_bucket_ctx(bucket, io_ctx);
   if (r < 0)
     return r;
+
   io_ctx.locator_set_key(key);
 
-  if (rctx) {
-    RGWObjState *astate;
-    r = get_obj_state(rctx, obj, io_ctx, oid, &astate);
-    if (r < 0)
-      return r;
+  ObjectReadOperation op;
+  op.getxattrs();
+  op.stat();
+  bufferlist outbl;
+  r = io_ctx.operate(oid, &op, &outbl);
+  if (r < 0)
+    return r;
 
-    if (!astate->exists)
-      return -ENOENT;
+  map<string, bufferlist> attrset;
+  bufferlist::iterator oiter = outbl.begin();
+  try {
+    ::decode(attrset, oiter);
+  } catch (buffer::error& err) {
+    dout(0) << "ERROR: failed decoding s->attrset (obj=" << obj << "), aborting" << dendl;
+    return -EIO;
+  }
 
-    if (psize)
-      *psize = astate->size;
-    if (pmtime)
-      *pmtime = astate->mtime;
+  map<string, bufferlist>::iterator aiter;
+  for (aiter = attrset.begin(); aiter != attrset.end(); ++aiter) {
+    dout(0) << "iter->first=" << aiter->first << dendl;
+  }
 
-    return 0;
+  uint64_t size;
+  time_t mtime;
+  try {
+    ::decode(size, oiter);
+    utime_t ut;
+    ::decode(ut, oiter);
+    mtime = ut.sec();
+  } catch (buffer::error& err) {
+    dout(0) << "ERROR: failed decoding object (obj=" << obj << ") info (either size or mtime), aborting" << dendl;
   }
+  if (psize)
+    *psize = size;
+  if (pmtime)
+    *pmtime = mtime;
+  if (attrs)
+    *attrs = attrset;
 
-  r = io_ctx.stat(oid, psize, pmtime);
-  return r;
+  return 0;
 }
 
 int RGWRados::get_bucket_stats(rgw_bucket& bucket, map<RGWObjCategory, RGWBucketStats>& stats)
@@ -2302,7 +2300,7 @@ int RGWRados::process_intent_log(rgw_bucket& bucket, string& oid,
   cout << "processing intent log " << oid << std::endl;
   uint64_t size;
   rgw_obj obj(bucket, oid);
-  int r = obj_stat(NULL, obj, &size, NULL);
+  int r = obj_stat(NULL, obj, &size, NULL, NULL);
   if (r < 0) {
     cerr << "error while doing stat on " << bucket << ":" << oid
         << " " << cpp_strerror(-r) << std::endl;
index 97c21a99c3f4e18874fcdf0504ebf283d5f5dde9..aca9e3565b7c0bd62ade297615725d2dd5740b03 100644 (file)
@@ -273,7 +273,7 @@ public:
 
   virtual int read(void *ctx, rgw_obj& obj, off_t ofs, size_t size, bufferlist& bl);
 
-  virtual int obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime);
+  virtual int obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, map<string, bufferlist> *attrs);
 
   virtual bool supports_tmap() { return true; }
   virtual int tmap_get(rgw_obj& obj, bufferlist& header, std::map<string, bufferlist>& m);