]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: Get rid of BucketFilter class, use a std::function
authorAdam C. Emerson <aemerson@redhat.com>
Mon, 4 May 2020 19:23:21 +0000 (15:23 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Wed, 9 Sep 2020 02:09:40 +0000 (22:09 -0400)
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h

index aac26a0db037cd3b12746f0d8e5b1a0d75be1075..0e6765b48c2baa7fd180a945b78dfcadcb3bc855 100644 (file)
@@ -2155,7 +2155,7 @@ bool RGWDataChangesLog::filter_bucket(const rgw_bucket& bucket, optional_yield y
     return true;
   }
 
-  return bucket_filter->filter(bucket, y);
+  return bucket_filter(bucket, y);
 }
 
 int RGWDataChangesLog::add_entry(const RGWBucketInfo& bucket_info, int shard_id) {
@@ -3046,16 +3046,10 @@ public:
   }
 };
 
-bool RGWBucketCtl::DataLogFilter::filter(const rgw_bucket& bucket, optional_yield y) const
-{
-  return bucket_ctl->bucket_exports_data(bucket, null_yield);
-}
-
 RGWBucketCtl::RGWBucketCtl(RGWSI_Zone *zone_svc,
                            RGWSI_Bucket *bucket_svc,
                            RGWSI_Bucket_Sync *bucket_sync_svc,
-                           RGWSI_BucketIndex *bi_svc) : cct(zone_svc->ctx()),
-                                                        datalog_filter(this)
+                           RGWSI_BucketIndex *bi_svc) : cct(zone_svc->ctx())
 {
   svc.zone = zone_svc;
   svc.bucket = bucket_svc;
@@ -3076,7 +3070,10 @@ void RGWBucketCtl::init(RGWUserCtl *user_ctl,
   bucket_be_handler = bm_handler->get_be_handler();
   bi_be_handler = bmi_handler->get_be_handler();
 
-  datalog->set_bucket_filter(&datalog_filter);
+  datalog->set_bucket_filter(
+    [this](const rgw_bucket& bucket, optional_yield y) {
+      return bucket_exports_data(bucket, y);
+    });
 }
 
 int RGWBucketCtl::call(std::function<int(RGWSI_Bucket_X_Ctx& ctx)> f) {
index 76e4369fd5edf07606cdb6d18a43d3ad58891515..cd0ed2641a2920b2b95fb196fa440cd8f3f7810c 100644 (file)
@@ -417,12 +417,12 @@ enum DataLogEntityType {
 
 struct rgw_data_change {
   DataLogEntityType entity_type;
-  string key;
-  real_time timestamp;
+  std::string key;
+  ceph::real_time timestamp;
 
-  void encode(bufferlist& bl) const {
+  void encode(ceph::buffer::list& bl) const {
     ENCODE_START(1, 1, bl);
-    uint8_t t = (uint8_t)entity_type;
+    auto t = std::uint8_t(entity_type);
     encode(t, bl);
     encode(key, bl);
     encode(timestamp, bl);
@@ -431,25 +431,25 @@ struct rgw_data_change {
 
   void decode(bufferlist::const_iterator& bl) {
      DECODE_START(1, bl);
-     uint8_t t;
+     std::uint8_t t;
      decode(t, bl);
-     entity_type = (DataLogEntityType)t;
+     entity_type = DataLogEntityType(t);
      decode(key, bl);
      decode(timestamp, bl);
      DECODE_FINISH(bl);
   }
 
-  void dump(Formatter *f) const;
-  void decode_json(JSONObj *obj);
+  void dump(ceph::Formatter* f) const;
+  void decode_json(JSONObjobj);
 };
 WRITE_CLASS_ENCODER(rgw_data_change)
 
 struct rgw_data_change_log_entry {
-  string log_id;
-  real_time log_timestamp;
+  std::string log_id;
+  ceph::real_time log_timestamp;
   rgw_data_change entry;
 
-  void encode(bufferlist& bl) const {
+  void encode(ceph::buffer::list& bl) const {
     ENCODE_START(1, 1, bl);
     encode(log_id, bl);
     encode(log_timestamp, bl);
@@ -457,7 +457,7 @@ struct rgw_data_change_log_entry {
     ENCODE_FINISH(bl);
   }
 
-  void decode(bufferlist::const_iterator& bl) {
+  void decode(ceph::buffer::list::const_iterator& bl) {
      DECODE_START(1, bl);
      decode(log_id, bl);
      decode(log_timestamp, bl);
@@ -465,17 +465,17 @@ struct rgw_data_change_log_entry {
      DECODE_FINISH(bl);
   }
 
-  void dump(Formatter *f) const;
-  void decode_json(JSONObj *obj);
+  void dump(ceph::Formatter* f) const;
+  void decode_json(JSONObjobj);
 };
 WRITE_CLASS_ENCODER(rgw_data_change_log_entry)
 
 struct RGWDataChangesLogInfo {
-  string marker;
-  real_time last_update;
+  std::string marker;
+  ceph::real_time last_update;
 
-  void dump(Formatter *f) const;
-  void decode_json(JSONObj *obj);
+  void dump(ceph::Formatter* f) const;
+  void decode_json(JSONObjobj);
 };
 
 namespace rgw {
@@ -483,22 +483,13 @@ struct BucketChangeObserver;
 }
 
 struct RGWDataChangesLogMarker {
-  int shard;
-  string marker;
+  int shard = 0;
+  std::string marker;
 
-  RGWDataChangesLogMarker() : shard(0) {}
+  RGWDataChangesLogMarker() = default;
 };
 
 class RGWDataChangesLog {
-public:
-  class BucketFilter {
-  public:
-    virtual ~BucketFilter() {}
-
-    virtual bool filter(const rgw_bucket& bucket, optional_yield y) const = 0;
-  };
-private:
-
   CephContext *cct;
   rgw::BucketChangeObserver *observer = nullptr;
 
@@ -508,34 +499,34 @@ private:
   } svc;
 
   int num_shards;
-  string *oids;
+  std::string* oids;
 
   ceph::mutex lock = ceph::make_mutex("RGWDataChangesLog::lock");
   ceph::shared_mutex modified_lock =
     ceph::make_shared_mutex("RGWDataChangesLog::modified_lock");
-  map<int, set<string> > modified_shards;
+  std::map<int, set<string> > modified_shards;
 
   std::atomic<bool> down_flag = { false };
 
   struct ChangeStatus {
     std::shared_ptr<const rgw_sync_policy_info> sync_policy;
-    real_time cur_expiration;
-    real_time cur_sent;
+    ceph::real_time cur_expiration;
+    ceph::real_time cur_sent;
     bool pending = false;
     RefCountedCond *cond = nullptr;
     ceph::mutex lock =
       ceph::make_mutex("RGWDataChangesLog::ChangeStatus");
   };
 
-  typedef std::shared_ptr<ChangeStatus> ChangeStatusPtr;
+  using ChangeStatusPtr = std::shared_ptr<ChangeStatus>;
 
   lru_map<rgw_bucket_shard, ChangeStatusPtr> changes;
 
-  map<rgw_bucket_shard, bool> cur_cycle;
+  std::map<rgw_bucket_shard, bool> cur_cycle;
 
   void _get_change(const rgw_bucket_shard& bs, ChangeStatusPtr& status);
   void register_renew(rgw_bucket_shard& bs);
-  void update_renewed(rgw_bucket_shard& bs, real_time& expiration);
+  void update_renewed(rgw_bucket_shard& bs, ceph::real_time& expiration);
 
   class ChangesRenewThread : public Thread {
     CephContext *cct;
@@ -549,9 +540,9 @@ private:
     void stop();
   };
 
-  ChangesRenewThread *renew_thread;
+  ChangesRenewThreadrenew_thread;
 
-  BucketFilter *bucket_filter{nullptr};
+  std::function<bool(const rgw_bucket& bucket, optional_yield y)> bucket_filter;
 
 public:
 
@@ -586,8 +577,8 @@ public:
 
   bool going_down();
 
-  void set_bucket_filter(BucketFilter *f) {
-    bucket_filter = f;
+  void set_bucket_filter(decltype(bucket_filter)&& f) {
+    bucket_filter = std::move(f);
   }
 
   bool filter_bucket(const rgw_bucket& bucket, optional_yield y) const;
@@ -624,14 +615,6 @@ class RGWBucketCtl
 
   int call(std::function<int(RGWSI_Bucket_X_Ctx& ctx)> f);
 
-  class DataLogFilter : public RGWDataChangesLog::BucketFilter {
-    RGWBucketCtl *bucket_ctl;
-  public:
-    DataLogFilter(RGWBucketCtl *_bucket_ctl) : bucket_ctl(_bucket_ctl) {}
-
-    bool filter(const rgw_bucket& bucket, optional_yield y) const override;
-  } datalog_filter;
-  
 public:
   RGWBucketCtl(RGWSI_Zone *zone_svc,
                RGWSI_Bucket *bucket_svc,