From 04da01ea9beea4c48e807887b11acde62f968c46 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 13 Nov 2019 15:31:55 -0800 Subject: [PATCH] rgw: modify zone_trace for bucket granularity info Signed-off-by: Yehuda Sadeh --- src/cls/rgw/cls_rgw_types.cc | 69 ++++++++++++++++++++++++++++++++++++ src/cls/rgw/cls_rgw_types.h | 56 ++++++++++++++++++++++++++++- src/rgw/rgw_data_sync.cc | 10 +++--- src/rgw/rgw_rados.cc | 10 +++--- 4 files changed, 135 insertions(+), 10 deletions(-) diff --git a/src/cls/rgw/cls_rgw_types.cc b/src/cls/rgw/cls_rgw_types.cc index a2d1880864a..6dcb75bf32c 100644 --- a/src/cls/rgw/cls_rgw_types.cc +++ b/src/cls/rgw/cls_rgw_types.cc @@ -6,6 +6,75 @@ #include "include/utime.h" +void rgw_zone_set_entry::from_str(const string& s) +{ + auto pos = s.find(':'); + if (pos == string::npos) { + zone = s; + location_key.reset(); + } else { + zone = s.substr(0, pos); + location_key = s.substr(pos + 1); + } +} + +string rgw_zone_set_entry::to_str() const +{ + string s = zone; + if (location_key) { + s = s + ":" + *location_key; + } + return s; +} + +void rgw_zone_set_entry::encode(bufferlist &bl) const +{ + /* no ENCODE_START, ENCODE_END for backward compatibility */ + ceph::encode(to_str(), bl); +} + +void rgw_zone_set_entry::decode(bufferlist::const_iterator &bl) +{ + /* no DECODE_START, DECODE_END for backward compatibility */ + string s; + ceph::decode(s, bl); + from_str(s); +} + +void rgw_zone_set_entry::dump(Formatter *f) const +{ + encode_json("entry", to_str(), f); +} + +void rgw_zone_set_entry::decode_json(JSONObj *obj) { + string s; + JSONDecoder::decode_json("entry", s, obj); + from_str(s); +} + +void rgw_zone_set::insert(const string& zone, std::optional location_key) +{ + entries.insert(rgw_zone_set_entry(zone, location_key)); +} + +bool rgw_zone_set::exists(const string& zone, std::optional location_key) const +{ + return entries.find(rgw_zone_set_entry(zone, location_key)) != entries.end(); +} + +void encode_json(const char *name, const rgw_zone_set& zs, ceph::Formatter *f) +{ + Formatter::ArraySection as(*f, name); + for (auto& e : zs.entries) { + encode_json("entry", e, f); + } +} + +void decode_json_obj(rgw_zone_set& zs, JSONObj *obj) +{ + decode_json_obj(zs.entries, obj); +} + void rgw_bucket_pending_info::generate_test_instances(list& o) { rgw_bucket_pending_info *i = new rgw_bucket_pending_info; diff --git a/src/cls/rgw/cls_rgw_types.h b/src/cls/rgw/cls_rgw_types.h index 5d1dc864fd5..8cc5c823bfc 100644 --- a/src/cls/rgw/cls_rgw_types.h +++ b/src/cls/rgw/cls_rgw_types.h @@ -23,7 +23,61 @@ namespace ceph { } using ceph::operator <<; -using rgw_zone_set = std::set; +struct rgw_zone_set_entry { + string zone; + std::optional location_key; + + bool operator<(const rgw_zone_set_entry& e) const { + if (zone < e.zone) { + return true; + } + if (zone > e.zone) { + return false; + } + return (location_key < e.location_key); + } + + rgw_zone_set_entry() {} + rgw_zone_set_entry(const string& _zone, + std::optional _location_key) : zone(_zone), + location_key(_location_key) {} + rgw_zone_set_entry(const string& s) { + from_str(s); + } + + void from_str(const string& s); + string to_str() const; + + void encode(bufferlist &bl) const; + void decode(bufferlist::const_iterator &bl); + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); +}; +WRITE_CLASS_ENCODER(rgw_zone_set_entry) + +struct rgw_zone_set { + std::set entries; + + void encode(bufferlist &bl) const { + /* no ENCODE_START, ENCODE_END for backward compatibility */ + ceph::encode(entries, bl); + } + void decode(bufferlist::const_iterator &bl) { + /* no DECODE_START, DECODE_END for backward compatibility */ + ceph::decode(entries, bl); + } + void decode_json(JSONObj *obj); + + void insert(const string& zone, std::optional location_key); + bool exists(const string& zone, std::optional location_key) const; +}; +WRITE_CLASS_ENCODER(rgw_zone_set) + +/* backward compatibility, rgw_zone_set needs to encode/decode the same as std::set */ +void encode_json(const char *name, const rgw_zone_set& zs, ceph::Formatter *f); +void decode_json_obj(rgw_zone_set& zs, JSONObj *obj); + enum RGWPendingState { CLS_RGW_STATE_PENDING_MODIFY = 0, diff --git a/src/rgw/rgw_data_sync.cc b/src/rgw/rgw_data_sync.cc index ce212ba8f01..385d84c66c7 100644 --- a/src/rgw/rgw_data_sync.cc +++ b/src/rgw/rgw_data_sync.cc @@ -3038,7 +3038,7 @@ public: data_sync_module = sync_env->sync_module->get_data_handler(); zones_trace = _zones_trace; - zones_trace.insert(sync_env->svc->zone->get_zone().id); + zones_trace.insert(sync_env->svc->zone->get_zone().id, _sync_pipe.info.dest_bs.get_key()); } int operate() override { @@ -3203,7 +3203,7 @@ public: status_oid(status_oid), tn(sync_env->sync_tracer->add_node(tn_parent, "full_sync", SSTR(bucket_shard_str{bs}))) { - zones_trace.insert(sc->source_zone); + zones_trace.insert(sc->source_zone, sync_pipe.info.dest_bs.bucket.get_key()); marker_tracker.set_tn(tn); prefix_handler.set_rules(sync_pipe.get_rules()); } @@ -3349,6 +3349,7 @@ class RGWBucketShardIncrementalSyncCR : public RGWCoroutine { bool updated_status{false}; const string& status_oid; const string& zone_id; + string target_location_key; string cur_id; @@ -3377,6 +3378,7 @@ public: set_status("init"); marker_tracker.set_tn(tn); rules = sync_pipe.get_rules(); + target_location_key = sync_pipe.info.dest_bs.bucket.get_key(); } bool check_key_handled(const rgw_obj_key& key) { @@ -3432,7 +3434,7 @@ int RGWBucketShardIncrementalSyncCR::operate() if (e.state != CLS_RGW_STATE_COMPLETE) { continue; } - if (e.zones_trace.find(zone_id) != e.zones_trace.end()) { + if (e.zones_trace.exists(zone_id, target_location_key)) { continue; } auto& squash_entry = squash_map[make_pair(e.object, e.instance)]; @@ -3506,7 +3508,7 @@ int RGWBucketShardIncrementalSyncCR::operate() marker_tracker.try_update_high_marker(cur_id, 0, entry->timestamp); continue; } - if (entry->zones_trace.find(zone_id) != entry->zones_trace.end()) { + if (entry->zones_trace.exists(zone_id, target_location_key)) { set_status() << "redundant operation, skipping"; tn->log(20, SSTR("skipping object: " <zones_trace = *zones_trace; } else { - entry->zones_trace.insert(store->svc.zone->get_zone().id); + entry->zones_trace.insert(store->svc.zone->get_zone().id, obj.bucket.get_key()); } *result = entry; @@ -6572,7 +6572,7 @@ int RGWRados::bucket_index_link_olh(const RGWBucketInfo& bucket_info, RGWObjStat if (_zones_trace) { zones_trace = *_zones_trace; } - zones_trace.insert(svc.zone->get_zone().id); + zones_trace.insert(svc.zone->get_zone().id, bucket_info.bucket.get_key()); BucketShard bs(this); @@ -6620,7 +6620,7 @@ int RGWRados::bucket_index_unlink_instance(const RGWBucketInfo& bucket_info, con if (_zones_trace) { zones_trace = *_zones_trace; } - zones_trace.insert(svc.zone->get_zone().id); + zones_trace.insert(svc.zone->get_zone().id, bucket_info.bucket.get_key()); BucketShard bs(this); @@ -7942,7 +7942,7 @@ int RGWRados::cls_obj_prepare_op(BucketShard& bs, RGWModifyOp op, string& tag, if (_zones_trace) { zones_trace = *_zones_trace; } - zones_trace.insert(svc.zone->get_zone().id); + zones_trace.insert(svc.zone->get_zone().id, bs.bucket.get_key()); ObjectWriteOperation o; cls_rgw_obj_key key(obj.key.get_index_key_name(), obj.key.instance); @@ -7965,7 +7965,7 @@ int RGWRados::cls_obj_complete_op(BucketShard& bs, const rgw_obj& obj, RGWModify if (_zones_trace) { zones_trace = *_zones_trace; } - zones_trace.insert(svc.zone->get_zone().id); + zones_trace.insert(svc.zone->get_zone().id, bs.bucket.get_key()); rgw_bucket_entry_ver ver; ver.pool = pool; -- 2.39.5