From: Yehuda Sadeh Date: Fri, 21 Oct 2011 23:14:11 +0000 (-0700) Subject: rgw: fix xattrs cache X-Git-Tag: v0.38~60 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e98cbc4320feafed40f2398b8a52d7830a30ac5d;p=ceph.git rgw: fix xattrs cache --- diff --git a/src/rgw/rgw_access.h b/src/rgw/rgw_access.h index 91ccf059e47d..0e421dc22687 100644 --- a/src/rgw/rgw_access.h +++ b/src/rgw/rgw_access.h @@ -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 *attrs) = 0; virtual bool supports_tmap() { return false; } diff --git a/src/rgw/rgw_cache.h b/src/rgw/rgw_cache.h index 865513cf69fc..07ca9ac10052 100644 --- a/src/rgw/rgw_cache.h +++ b/src/rgw/rgw_cache.h @@ -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 *attrs); int delete_obj(void *ctx, std::string& id, rgw_obj& obj, bool sync); }; @@ -261,20 +261,20 @@ int RGWCache::put_obj_data(void *ctx, std::string& id, rgw_obj& obj, const ch } template -int RGWCache::obj_stat(void *ctx, rgw_bucket& bucket, std::string& obj, uint64_t *psize, time_t *pmtime) +int RGWCache::obj_stat(void *ctx, rgw_obj& obj, uint64_t *psize, time_t *pmtime, map *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::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::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; } diff --git a/src/rgw/rgw_fs.cc b/src/rgw/rgw_fs.cc index aa582fb4cfd9..7c14ec520121 100644 --- a/src/rgw/rgw_fs.cc +++ b/src/rgw/rgw_fs.cc @@ -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 *attrs) { return -ENOTSUP; } diff --git a/src/rgw/rgw_fs.h b/src/rgw/rgw_fs.h index 783d7beba2ab..ec1957afc1f6 100644 --- a/src/rgw/rgw_fs.h +++ b/src/rgw/rgw_fs.h @@ -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 *attrs); virtual int get_bucket_info(void *ctx, string& bucket_name, RGWBucketInfo& info); }; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 9e23e4d2e589..d73273fafcba 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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::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::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 *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 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::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& 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; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 97c21a99c3f4..aca9e3565b7c 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -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 *attrs); virtual bool supports_tmap() { return true; } virtual int tmap_get(rgw_obj& obj, bufferlist& header, std::map& m);