]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: keep source zone attr on head object
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 23 Dec 2015 23:28:58 +0000 (15:28 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Fri, 12 Feb 2016 00:13:48 +0000 (16:13 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/rgw/rgw_common.h
src/rgw/rgw_rados.cc
src/rgw/rgw_rest_s3.cc

index ed82e87004ea6062512a15c56cc9d423ad5d10cc..cb164ef29da051335ed241f57cbe2c8aa6c6b7f4 100644 (file)
@@ -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"
index 1b9d1fe52ef105406e78574c95f7f011e283cc87..acfc49ab84efc1ee3c2758301f4b1145ce5454c6 100644 (file)
@@ -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;
index b0c6d24d45a6c446d50133acd11823c84de96215..fb4fe0835ccc2ec14f117f78949e31a4cdb8b825 100644 (file)
@@ -105,6 +105,28 @@ int RGWGetObj_ObjStore_S3::send_response_data_error()
   return send_response_data(bl, 0 , 0);
 }
 
+template <class T>
+int decode_attr_bl_single_value(map<string, bufferlist>& attrs, const char *attr_name, T *result, T def_val)
+{
+  map<string, bufferlist>::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<string, bufferlist>::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);