]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: ctl.bucket: add bucket sync related methods
authorYehuda Sadeh <yehuda@redhat.com>
Sat, 17 Aug 2019 00:23:55 +0000 (17:23 -0700)
committerYehuda Sadeh <yehuda@redhat.com>
Tue, 28 Jan 2020 18:20:36 +0000 (10:20 -0800)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
12 files changed:
src/rgw/rgw_admin.cc
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/rgw_bucket_sync.cc
src/rgw/rgw_bucket_sync.h
src/rgw/rgw_common.cc
src/rgw/rgw_common.h
src/rgw/rgw_service.cc
src/rgw/services/svc_bi_rados.cc
src/rgw/services/svc_bucket_sync.h
src/rgw/services/svc_bucket_sync_sobj.cc
src/rgw/services/svc_bucket_sync_sobj.h

index 788441b13d5bf70c344ac5a65c07b44cd253573a..bdf194f02535f8e8478eaee7cd7d3b0764bff636 100644 (file)
@@ -2285,11 +2285,12 @@ static int bucket_sync_status(rgw::sal::RGWRadosStore *store, const RGWBucketInf
   out << indented{width, "zone"} << zone.id << " (" << zone.name << ")\n";
   out << indented{width, "bucket"} << info.bucket << "\n\n";
 
-  if (!info.bucket_datasync_enabled(store->svc.zone)) {
+  if (!store->ctl()->bucket->bucket_imports_data(info.bucket, null_yield)) {
     out << "Sync is disabled for bucket " << info.bucket.name << '\n';
     return 0;
   }
 
+#warning need to use bucket sources
   auto& zone_conn_map = store->svc()->zone->get_zone_conn_map();
   if (!source_zone_id.empty()) {
     auto z = zonegroup.zones.find(source_zone_id);
index 4f39be8a96eb4abb86e8c48822f5707c4f9747d4..5aef8f3b84dd6918928d554fd4c3a97e2fafbd39 100644 (file)
@@ -31,6 +31,7 @@
 #include "services/svc_zone.h"
 #include "services/svc_sys_obj.h"
 #include "services/svc_bucket.h"
+#include "services/svc_bucket_sync.h"
 #include "services/svc_meta.h"
 #include "services/svc_meta_be_sobj.h"
 #include "services/svc_user.h"
@@ -2180,7 +2181,7 @@ int RGWDataChangesLog::get_log_shard_id(rgw_bucket& bucket, int shard_id) {
 }
 
 int RGWDataChangesLog::add_entry(const RGWBucketInfo& bucket_info, int shard_id) {
-  if (!bucket_info.bucket_datasync_enabled(svc.zone)) {
+  if (!ctl.bucket->bucket_exports_data(bucket_info.bucket, null_yield)) {
     return 0;
   }
 
@@ -3069,10 +3070,12 @@ public:
 
 RGWBucketCtl::RGWBucketCtl(RGWSI_Zone *zone_svc,
                            RGWSI_Bucket *bucket_svc,
+                           RGWSI_Bucket_Sync *bucket_sync_svc,
                            RGWSI_BucketIndex *bi_svc) : cct(zone_svc->ctx())
 {
   svc.zone = zone_svc;
   svc.bucket = bucket_svc;
+  svc.bucket_sync = bucket_sync_svc;
   svc.bi = bi_svc;
 }
 
@@ -3654,6 +3657,40 @@ int RGWBucketCtl::sync_user_stats(const rgw_user& user_id,
   return ctl.user->flush_bucket_stats(user_id, *pent);
 }
 
+int RGWBucketCtl::bucket_exports_data(const rgw_bucket& bucket,
+                                      optional_yield y)
+{
+
+  RGWBucketSyncPolicyHandlerRef handler;
+
+  int r = call([&](RGWSI_Bucket_X_Ctx& ctx) {
+    return svc.bucket_sync->get_policy_handler(ctx.bi, bucket, &handler, y);
+  });
+  if (r < 0) {
+    ldout(cct, 20) << __func__ << "(): failed to read bucket stats (r=" << r << ")" << dendl;
+    return r;
+  }
+
+  return handler->bucket_exports_data();
+}
+
+int RGWBucketCtl::bucket_imports_data(const rgw_bucket& bucket,
+                                      optional_yield y)
+{
+
+  RGWBucketSyncPolicyHandlerRef handler;
+
+  int r = call([&](RGWSI_Bucket_X_Ctx& ctx) {
+    return svc.bucket_sync->get_policy_handler(ctx.bi, bucket, &handler, y);
+  });
+  if (r < 0) {
+    ldout(cct, 20) << __func__ << "(): failed to read bucket stats (r=" << r << ")" << dendl;
+    return r;
+  }
+
+  return handler->bucket_imports_data();
+}
+
 RGWBucketMetadataHandlerBase *RGWBucketMetaHandlerAllocator::alloc()
 {
   return new RGWBucketMetadataHandler();
index 9af062da16042043ed2fb6448d8f866bcff02d6b..d3f3946d86a23720df67fa9d702c92e15d5b2439 100644 (file)
@@ -593,6 +593,7 @@ class RGWBucketCtl
   struct Svc {
     RGWSI_Zone *zone{nullptr};
     RGWSI_Bucket *bucket{nullptr};
+    RGWSI_Bucket_Sync *bucket_sync{nullptr};
     RGWSI_BucketIndex *bi{nullptr};
   } svc;
 
@@ -611,6 +612,7 @@ class RGWBucketCtl
 public:
   RGWBucketCtl(RGWSI_Zone *zone_svc,
                RGWSI_Bucket *bucket_svc,
+               RGWSI_Bucket_Sync *bucket_sync_svc,
                RGWSI_BucketIndex *bi_svc);
 
   void init(RGWUserCtl *user_ctl,
@@ -866,6 +868,12 @@ public:
   int sync_user_stats(const rgw_user& user_id, const RGWBucketInfo& bucket_info,
                       RGWBucketEnt* pent = nullptr);
 
+  /* bucket sync */
+  int bucket_exports_data(const rgw_bucket& bucket,
+                          optional_yield y);
+  int bucket_imports_data(const rgw_bucket& bucket,
+                          optional_yield y);
+
 private:
   int convert_old_bucket_info(RGWSI_Bucket_X_Ctx& ctx,
                               const rgw_bucket& bucket,
index 8732bce32f888cfcd1dcd5797e3d62b7c642c07c..61722627f23398f6cbf8f9bf8e2c288ab3781fa3 100644 (file)
@@ -91,18 +91,17 @@ int RGWBucketSyncPolicyHandler::init()
   return 0;
 }
 
-#if 0
-vector<rgw_bucket_sync_pipe> rgw_bucket_sync_target_info::build_pipes(const rgw_bucket& source_bs)
+bool RGWBucketSyncPolicyHandler::bucket_exports_data() const
 {
-  vector<rgw_bucket_sync_pipe> pipes;
-
-  for (auto t : targets) {
-    rgw_bucket_sync_pipe pipe;
-    pipe.source_bs = source_bs;
-    pipe.source_prefix = t.source_prefix;
-    pipe.dest_prefix = t.dest_prefix;
-    pipes.push_back(std::move(pipe));
+  if (bucket_is_sync_source()) {
+    return true;
   }
-  return pipes;
+
+  return (zone_svc->need_to_log_data() &&
+          bucket_info.datasync_flag_enabled());
+}
+
+bool RGWBucketSyncPolicyHandler::bucket_imports_data() const
+{
+  return bucket_is_sync_target();
 }
-#endif
index ca104f0c4ce36c3953ddc54efa311a5ed3160694..aad992d0cba9f9ee252371dbf3690346c970a1f6 100644 (file)
@@ -49,8 +49,23 @@ public:
 
   int init();
 
+  const RGWBucketInfo& get_bucket_info() const {
+    return bucket_info;
+  }
+
   bool zone_is_source(const string& zone_id) const {
     return sources.find(zone_id) != sources.end();
   }
+
+  bool bucket_is_sync_source() const {
+    return !targets.empty();
+  }
+
+  bool bucket_is_sync_target() const {
+    return !sources.empty();
+  }
+
+  bool bucket_exports_data() const;
+  bool bucket_imports_data() const;
 };
 
index 9814a2779f517ea7e3f439c61df45082207c0e3c..b9325dc7181d25008091ace2cacda7f8a2ab9672 100644 (file)
@@ -2064,18 +2064,3 @@ bool RGWBucketInfo::empty_sync_policy() const
   return sync_policy->empty();
 }
 
-bool RGWBucketInfo::bucket_is_sync_source(const string& zone_id) const
-{
-  return (sync_policy &&
-          sync_policy->zone_is_source(zone_id));
-}
-
-bool RGWBucketInfo::bucket_datasync_enabled(const RGWSI_Zone *zone_svc) const
-{
-  if (bucket_is_sync_source(zone_svc->zone_id())) {
-    return true;
-  }
-
-  return (zone_svc->need_to_log_data() &&
-          datasync_flag_enabled());
-}
index 12d6c369f0d0dc8bf8549d186c28037b12ba1294..6ddbe979c75f9d4d73490e41025a3e8b20d855b0 100644 (file)
@@ -1475,8 +1475,6 @@ struct RGWBucketInfo {
   void set_sync_policy(rgw_sync_policy_info&& policy);
 
   bool empty_sync_policy() const;
-  bool bucket_is_sync_source(const string& zone_id) const;
-  bool bucket_datasync_enabled(const RGWSI_Zone *zone_svc) const;
 
   RGWBucketInfo();
   ~RGWBucketInfo();
index a5e9746fa87604889d07ef8c2cd0de5464715846..0909188ae149fa7de50aa39daa59e0fc09188f84 100644 (file)
@@ -347,6 +347,7 @@ int RGWCtlDef::init(RGWServices& svc)
   user.reset(new RGWUserCtl(svc.zone, svc.user, (RGWUserMetadataHandler *)meta.user.get()));
   bucket.reset(new RGWBucketCtl(svc.zone,
                                 svc.bucket,
+                                svc.bucket_sync,
                                 svc.bi));
   otp.reset(new RGWOTPCtl(svc.zone, svc.otp));
 
index 7bd9ab8054f2ca8a9e4b9164181aa2b3681fa85e..5aac1ea47d5ff2788937459b96fa626159aded89 100644 (file)
@@ -411,8 +411,9 @@ int RGWSI_BucketIndex_RADOS::get_reshard_status(const RGWBucketInfo& bucket_info
 int RGWSI_BucketIndex_RADOS::handle_overwrite(const RGWBucketInfo& info,
                                               const RGWBucketInfo& orig_info)
 {
-  bool new_sync_enabled = info.bucket_datasync_enabled(svc.zone);
-  bool old_sync_enabled = orig_info.bucket_datasync_enabled(svc.zone);
+#warning needs to be done differently
+  bool new_sync_enabled = info.datasync_flag_enabled();
+  bool old_sync_enabled = orig_info.datasync_flag_enabled();
 
   if (old_sync_enabled != new_sync_enabled) {
     int shards_num = info.num_shards? info.num_shards : 1;
index 13c89ecf8bbbd0e4c74a8959decb8bb9ea3b3b04..51c88789a247fe5a7d6d0ac0756e6cb229a9b86c 100644 (file)
@@ -22,6 +22,7 @@
 #include "svc_bucket_types.h"
 
 class RGWBucketSyncPolicyHandler;
+using RGWBucketSyncPolicyHandlerRef = std::shared_ptr<RGWBucketSyncPolicyHandler>;
 
 
 class RGWSI_Bucket_Sync : public RGWServiceInstance
@@ -31,7 +32,7 @@ public:
 
   virtual int get_policy_handler(RGWSI_Bucket_BI_Ctx& ctx,
                                  const rgw_bucket& bucket,
-                                 std::shared_ptr<RGWBucketSyncPolicyHandler> *handler,
+                                 RGWBucketSyncPolicyHandlerRef *handler,
                                  optional_yield y) = 0;
 };
 
index 3a8c3709dfcab048c69fdf454bfbeba000638b2b..3c3a78e8cbd2088435a69a93aaa0fe664c5133e6 100644 (file)
@@ -30,7 +30,7 @@ int RGWSI_Bucket_Sync_SObj::do_start()
 
 int RGWSI_Bucket_Sync_SObj::get_policy_handler(RGWSI_Bucket_BI_Ctx& ctx,
                                                const rgw_bucket& bucket,
-                                               std::shared_ptr<RGWBucketSyncPolicyHandler> *handler,
+                                               RGWBucketSyncPolicyHandlerRef *handler,
                                                optional_yield y)
 {
   string key = RGWSI_Bucket::get_bi_meta_key(bucket);
index 40745c2219e1d4033384e93ce9bc448f8d5ccf4c..5742168d5cbeb9d130f255ec9a0110ee6a569729 100644 (file)
@@ -20,7 +20,6 @@
 #include "rgw/rgw_service.h"
 
 #include "svc_meta_be.h"
-#include "svc_bucket_types.h"
 #include "svc_bucket_sync.h"
 
 class RGWSI_Zone;
@@ -30,8 +29,6 @@ class RGWSI_Bucket_SObj;
 template <class T>
 class RGWChainedCacheImpl;
 
-class RGWBucketSyncPolicyHandler;
-
 class RGWSI_Bucket_Sync_SObj : public RGWSI_Bucket_Sync
 {
   struct bucket_sync_policy_cache_entry {
@@ -60,7 +57,7 @@ public:
 
   int get_policy_handler(RGWSI_Bucket_BI_Ctx& ctx,
                          const rgw_bucket& bucket,
-                         std::shared_ptr<RGWBucketSyncPolicyHandler> *handler,
+                         RGWBucketSyncPolicyHandlerRef *handler,
                          optional_yield y) override;
 };