]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: modify zone_trace for bucket granularity info
authorYehuda Sadeh <yehuda@redhat.com>
Wed, 13 Nov 2019 23:31:55 +0000 (15:31 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 28 Jan 2020 18:20:38 +0000 (10:20 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/cls/rgw/cls_rgw_types.cc
src/cls/rgw/cls_rgw_types.h
src/rgw/rgw_data_sync.cc
src/rgw/rgw_rados.cc

index a2d1880864a799e647901a3ec0b4a618e53de78b..6dcb75bf32c97d189b626413be2e032c8ce1a188 100644 (file)
@@ -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<string> location_key)
+{
+  entries.insert(rgw_zone_set_entry(zone, location_key));
+}
+
+bool rgw_zone_set::exists(const string& zone, std::optional<string> 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<rgw_bucket_pending_info*>& o)
 {
   rgw_bucket_pending_info *i = new rgw_bucket_pending_info;
index 5d1dc864fd5965813ac5e7f72a8689af5c793a8e..8cc5c823bfc014a8d78ea46bca988dc3ff940286 100644 (file)
@@ -23,7 +23,61 @@ namespace ceph {
 }
 using ceph::operator <<;
 
-using rgw_zone_set = std::set<std::string>;
+struct rgw_zone_set_entry {
+  string zone;
+  std::optional<std::string> 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<std::string> _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<rgw_zone_set_entry> 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<string> location_key);
+  bool exists(const string& zone, std::optional<string> 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,
index ce212ba8f01c97bb56f9f1c2bd5b03fd9da46ac3..385d84c66c762382046faadd6b68f5aa41a3c034 100644 (file)
@@ -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: "
               <<bucket_shard_str{bs} <<"/"<<key<<": redundant operation"));
index 3012b79f904d2e6201b5cc9da9c1d60da09450e4..a6cdaa00261b81ac8a2b70c6904d64d5fc282a75 100644 (file)
@@ -966,7 +966,7 @@ void RGWIndexCompletionManager::create_completion(const rgw_obj& obj,
   if (zones_trace) {
     entry->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;