From e8563b9e68c00295c9d37b1355de4253024ff4f9 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Mon, 22 Aug 2022 16:48:27 -0400 Subject: [PATCH] rgw: fetch_remote_obj() adds x-rgw-replicated-from headers adds x-rgw-replicated-from headers for each zone in the object's replication path. the RGW_ATTR_OBJ_REPLICATION_TRACE attribute is stored as a vector instead of a set to preserve the replication order Signed-off-by: Casey Bodley (cherry picked from commit 9ec4fd7e4977b3b68b22a3f759e29c0ffc2b088b) --- src/rgw/driver/rados/rgw_rados.cc | 15 +++++++++++++++ src/rgw/rgw_common.h | 1 + src/rgw/rgw_rest_s3.cc | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/rgw/driver/rados/rgw_rados.cc b/src/rgw/driver/rados/rgw_rados.cc index 00bcc0ba5b0..02ca98f2498 100644 --- a/src/rgw/driver/rados/rgw_rados.cc +++ b/src/rgw/driver/rados/rgw_rados.cc @@ -4102,6 +4102,21 @@ int RGWRados::fetch_remote_obj(RGWObjectCtx& obj_ctx, bl.clear(); // overwrite source's status bl.append("REPLICA"); } + { // update replication trace + std::vector trace; + if (auto i = cb.get_attrs().find(RGW_ATTR_OBJ_REPLICATION_TRACE); + i != cb.get_attrs().end()) { + try { + decode(trace, i->second); + } catch (const buffer::error&) {} + } + // add the source entry to the end + trace.push_back(source_trace_entry); + + bufferlist bl; + encode(trace, bl); + cb.get_attrs()[RGW_ATTR_OBJ_REPLICATION_TRACE] = std::move(bl); + } if (source_zone.empty()) { set_copy_attrs(cb.get_attrs(), attrs, attrs_mod); diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index f768a5e81cc..d0bd47253a8 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -143,6 +143,7 @@ using ceph::crypto::MD5; #define RGW_ATTR_CLOUD_TIER_CONFIG RGW_ATTR_PREFIX "cloud_tier_config" #define RGW_ATTR_OBJ_REPLICATION_STATUS RGW_ATTR_PREFIX "amz-replication-status" +#define RGW_ATTR_OBJ_REPLICATION_TRACE RGW_ATTR_PREFIX "replication-trace" /* IAM Policy */ #define RGW_ATTR_IAM_POLICY RGW_ATTR_PREFIX "iam-policy" diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index e57f42b2bf3..eb68d004af5 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -437,6 +437,17 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs, i != attrs.end()) { dump_header(s, "x-amz-replication-status", i->second); } + if (auto i = attrs.find(RGW_ATTR_OBJ_REPLICATION_TRACE); + i != attrs.end()) { + try { + std::vector zones; + auto p = i->second.cbegin(); + decode(zones, p); + for (const auto& zone : zones) { + dump_header(s, "x-rgw-replicated-from", zone.to_str()); + } + } catch (const buffer::error&) {} // omit x-rgw-replicated-from headers + } if (! op_ret) { if (! lo_etag.empty()) { -- 2.39.5