From: Yehuda Sadeh Date: Wed, 23 Dec 2015 23:28:58 +0000 (-0800) Subject: rgw: keep source zone attr on head object X-Git-Tag: v10.1.0~354^2~99 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b37503abc519531f4cd41e1616ef212e5ca0a05f;p=ceph.git rgw: keep source zone attr on head object Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index ed82e87004ea..cb164ef29da0 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -82,6 +82,7 @@ using ceph::crypto::MD5; #define RGW_ATTR_SLO_UINDICATOR RGW_ATTR_META_PREFIX "static-large-object" #define RGW_ATTR_PG_VER RGW_ATTR_PREFIX "pg_ver" +#define RGW_ATTR_SOURCE_ZONE RGW_ATTR_PREFIX "source_zone" #define RGW_ATTR_TEMPURL_KEY1 RGW_ATTR_META_PREFIX "temp-url-key" #define RGW_ATTR_TEMPURL_KEY2 RGW_ATTR_META_PREFIX "temp-url-key-2" diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 1b9d1fe52ef1..acfc49ab84ef 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -1649,6 +1649,10 @@ int RGWPeriodMap::update(const RGWZoneGroup& zonegroup) hash.Final(md5); memcpy((char *)&short_id, md5, sizeof(short_id)); + if (short_id == 0) { + ++short_id; + } + short_zone_ids[i.second.id] = short_id; } } @@ -5684,6 +5688,12 @@ int RGWRados::Object::Write::write_meta(uint64_t size, cls_rgw_obj_store_pg_ver(op, RGW_ATTR_PG_VER); } + if (attrs.find(RGW_ATTR_SOURCE_ZONE) == attrs.end()) { + bufferlist bl; + ::encode(store->get_zone_short_id(), bl); + op.setxattr(RGW_ATTR_SOURCE_ZONE, bl); + } + if (!op.size()) return 0; @@ -6442,6 +6452,7 @@ int RGWRados::copy_obj(RGWObjectCtx& obj_ctx, set_copy_attrs(src_attrs, attrs, attrs_mod); attrs.erase(RGW_ATTR_ID_TAG); attrs.erase(RGW_ATTR_PG_VER); + attrs.erase(RGW_ATTR_SOURCE_ZONE); RGWObjManifest manifest; RGWObjState *astate = NULL; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index b0c6d24d45a6..fb4fe0835ccc 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -105,6 +105,28 @@ int RGWGetObj_ObjStore_S3::send_response_data_error() return send_response_data(bl, 0 , 0); } +template +int decode_attr_bl_single_value(map& attrs, const char *attr_name, T *result, T def_val) +{ + map::iterator iter = attrs.find(attr_name); + if (iter == attrs.end()) { + *result = def_val; + return 0; + } + bufferlist& bl = iter->second; + if (bl.length() == 0) { + *result = def_val; + return 0; + } + bufferlist::iterator bliter = bl.begin(); + try { + ::decode(*result, bliter); + } catch (buffer::error& err) { + return -EIO; + } + return 0; +} + int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) { const char *content_type = NULL; @@ -141,18 +163,21 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs, off_ if (s->system_request && lastmod) { /* we end up dumping mtime in two different methods, a bit redundant */ dump_epoch_header(s, "Rgwx-Mtime", lastmod); - uint64_t pg_ver = 0; - map::iterator iter = attrs.find(RGW_ATTR_PG_VER); - bufferlist& bl = iter->second; - if (bl.length() > 0) { - bufferlist::iterator bliter = bl.begin(); - try { - ::decode(pg_ver, bliter); - } catch (buffer::error& err) { - ldout(s->cct, 0) << "ERROR: failed to decode pg ver attr" << dendl; - } + uint64_t pg_ver; + int r = decode_attr_bl_single_value(attrs, RGW_ATTR_PG_VER, &pg_ver, (uint64_t)0); + if (r < 0) { + ldout(s->cct, 0) << "ERROR: failed to decode pg ver attr, ignoring" << dendl; } s->cio->print("Rgwx-Obj-PG-Ver: %lld\r\n", (long long)pg_ver); + + uint32_t source_zone_short_id; + r = decode_attr_bl_single_value(attrs, RGW_ATTR_SOURCE_ZONE, &source_zone_short_id, (uint32_t)0); + if (r < 0) { + ldout(s->cct, 0) << "ERROR: failed to decode pg ver attr, ignoring" << dendl; + } + if (source_zone_short_id != 0) { + s->cio->print("Rgwx-Source-Zone-Short-Id: %lld\r\n", (long long)source_zone_short_id); + } } dump_content_length(s, total_len);