]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgwlc: activate lifecycle processing on non-master zones
authorMatt Benjamin <mbenjamin@redhat.com>
Tue, 5 Jul 2022 22:33:09 +0000 (18:33 -0400)
committerMatt Benjamin <mbenjamin@redhat.com>
Sun, 17 Jul 2022 22:37:49 +0000 (18:37 -0400)
The basic idea of this change is the same as the proposal by
Ilsoo Byun <ilsoobyun@linecorp.com>, but some details have changed.

The main differences are to use the existing
RGWLC::set(remove)_bucket_config methods, and to use the
RGWBucketInstanceMetadataHandler infrastructue to dispatch
the corresponding calls.  Thank you!

Fixes: https://tracker.ceph.com/issues/44268
Related PR: #33524

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_bucket.cc
src/rgw/rgw_bucket.h
src/rgw/rgw_data_sync.cc
src/rgw/rgw_lc.cc
src/rgw/rgw_service.cc
src/rgw/rgw_sync_module.cc
src/rgw/rgw_sync_module.h

index 68fa4064adfdb09d4d0f5820ba64b8c171a6ef50..af1d2de03931ed2d2ced68ac77ca374af14953f6 100644 (file)
@@ -2139,7 +2139,10 @@ public:
     RGWSI_BucketIndex *bi{nullptr};
   } svc;
 
-  RGWBucketInstanceMetadataHandler() {}
+  rgw::sal::Store* store;
+
+  RGWBucketInstanceMetadataHandler(rgw::sal::Store* store)
+    : store(store) {}
 
   void init(RGWSI_Zone *zone_svc,
            RGWSI_Bucket *bucket_svc,
@@ -2371,12 +2374,51 @@ int RGWMetadataHandlerPut_BucketInstance::put_post(const DoutPrefixProvider *dpp
     return ret;
   }
 
+  /* update lifecyle policy */
+  {
+    std::unique_ptr<rgw::sal::Bucket> bucket;
+    ret = bihandler->store->get_bucket(nullptr, bci.info, &bucket);
+    if (ret < 0) {
+      ldpp_dout(dpp, 0) << __func__ << " failed to get_bucket(...) for "
+                       << bci.info.bucket.name
+                       << dendl;
+      return ret;
+    }
+
+    auto lc = bihandler->store->get_rgwlc();
+
+    auto lc_it = bci.attrs.find(RGW_ATTR_LC);
+    if (lc_it != bci.attrs.end()) {
+      ldpp_dout(dpp, 20) << "set lc config for " << bci.info.bucket.name << dendl;
+      ret = lc->set_bucket_config(bucket.get(), bci.attrs, nullptr);
+      if (ret < 0) {
+             ldpp_dout(dpp, 0) << __func__ << " failed to set lc config for "
+                       << bci.info.bucket.name
+                       << dendl;
+             return ret;
+      }
+
+    } else {
+      ldpp_dout(dpp, 20) << "remove lc config for " << bci.info.bucket.name << dendl;
+      ret = lc->remove_bucket_config(bucket.get(), bci.attrs);
+      if (ret < 0) {
+             ldpp_dout(dpp, 0) << __func__ << " failed to remove lc config for "
+                       << bci.info.bucket.name
+                       << dendl;
+             return ret;
+      }
+    }
+  } /* update lc */
+
   return STATUS_APPLIED;
 }
 
 class RGWArchiveBucketInstanceMetadataHandler : public RGWBucketInstanceMetadataHandler {
 public:
-  RGWArchiveBucketInstanceMetadataHandler() {}
+  RGWArchiveBucketInstanceMetadataHandler(rgw::sal::Store* store)
+    : RGWBucketInstanceMetadataHandler(store) {}
+
+  // N.B. replication of lifecycle policy relies on logic in RGWBucketInstanceMetadataHandler::do_put(...), override with caution
 
   int do_remove(RGWSI_MetaBackend_Handler::Op *op, string& entry, RGWObjVersionTracker& objv_tracker, optional_yield y, const DoutPrefixProvider *dpp) override {
     ldpp_dout(dpp, 0) << "SKIP: bucket instance removal is not allowed on archive zone: bucket.instance:" << entry << dendl;
@@ -3027,24 +3069,24 @@ int RGWBucketCtl::bucket_imports_data(const rgw_bucket& bucket,
   return handler->bucket_imports_data();
 }
 
-RGWBucketMetadataHandlerBase *RGWBucketMetaHandlerAllocator::alloc()
+RGWBucketMetadataHandlerBaseRGWBucketMetaHandlerAllocator::alloc()
 {
   return new RGWBucketMetadataHandler();
 }
 
-RGWBucketInstanceMetadataHandlerBase *RGWBucketInstanceMetaHandlerAllocator::alloc()
+RGWBucketInstanceMetadataHandlerBase* RGWBucketInstanceMetaHandlerAllocator::alloc(rgw::sal::Store* store)
 {
-  return new RGWBucketInstanceMetadataHandler();
+  return new RGWBucketInstanceMetadataHandler(store);
 }
 
-RGWBucketMetadataHandlerBase *RGWArchiveBucketMetaHandlerAllocator::alloc()
+RGWBucketMetadataHandlerBaseRGWArchiveBucketMetaHandlerAllocator::alloc()
 {
   return new RGWArchiveBucketMetadataHandler();
 }
 
-RGWBucketInstanceMetadataHandlerBase *RGWArchiveBucketInstanceMetaHandlerAllocator::alloc()
+RGWBucketInstanceMetadataHandlerBase* RGWArchiveBucketInstanceMetaHandlerAllocator::alloc(rgw::sal::Store* store)
 {
-  return new RGWArchiveBucketInstanceMetadataHandler();
+  return new RGWArchiveBucketInstanceMetadataHandler(store);
 }
 
 
index 28c315e6ab2e74c4260b0bc461e621d4b8ba6118..10a7226f246d37b99e4636c1a18d4285a9f76ffc 100644 (file)
@@ -204,7 +204,7 @@ public:
 
 class RGWBucketInstanceMetaHandlerAllocator {
 public:
-  static RGWBucketInstanceMetadataHandlerBase *alloc();
+  static RGWBucketInstanceMetadataHandlerBase *alloc(rgw::sal::Store* store);
 };
 
 class RGWArchiveBucketMetaHandlerAllocator {
@@ -214,7 +214,7 @@ public:
 
 class RGWArchiveBucketInstanceMetaHandlerAllocator {
 public:
-  static RGWBucketInstanceMetadataHandlerBase *alloc();
+  static RGWBucketInstanceMetadataHandlerBase *alloc(rgw::sal::Store* store);
 };
 
 extern int rgw_remove_object(const DoutPrefixProvider *dpp, rgw::sal::Store* store, rgw::sal::Bucket* bucket, rgw_obj_key& key);
index ecc7a9596ae82d128d54246c61a8dc69c9c3c031..1b2b0ef8351388095042a2dea589d2845e2f2286 100644 (file)
@@ -520,7 +520,7 @@ class RGWInitDataSyncStatusCoroutine : public RGWCoroutine {
   static constexpr uint32_t lock_duration = 30;
   RGWDataSyncCtx *sc;
   RGWDataSyncEnv *sync_env;
-  rgw::sal::RadosStore* store;
+  rgw::sal::RadosStore* store; // RGWDataSyncEnv also has a pointer to store
   const rgw_pool& pool;
   const uint32_t num_shards;
 
@@ -2500,8 +2500,8 @@ public:
   RGWMetadataHandler *alloc_bucket_meta_handler() override {
     return RGWArchiveBucketMetaHandlerAllocator::alloc();
   }
-  RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler() override {
-    return RGWArchiveBucketInstanceMetaHandlerAllocator::alloc();
+  RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler(rgw::sal::Store* store) override {
+    return RGWArchiveBucketInstanceMetaHandlerAllocator::alloc(store);
   }
 };
 
index 8125b4ab8efd06c8a153923926f4848efae6a6e3..9233a442b4f8bf442bb25a333ca45f4b2ce3eb25 100644 (file)
@@ -2455,16 +2455,21 @@ int RGWLC::set_bucket_config(rgw::sal::Bucket* bucket,
                          const rgw::sal::Attrs& bucket_attrs,
                          RGWLifecycleConfiguration *config)
 {
+  int ret{0};
   rgw::sal::Attrs attrs = bucket_attrs;
-  bufferlist lc_bl;
-  config->encode(lc_bl);
-
-  attrs[RGW_ATTR_LC] = std::move(lc_bl);
-
-  int ret =
-    bucket->merge_and_store_attrs(this, attrs, null_yield);
-  if (ret < 0)
-    return ret;
+  if (config) {
+    /* if no RGWLifecycleconfiguration provided, it means
+     * RGW_ATTR_LC is already valid and present */
+    bufferlist lc_bl;
+    config->encode(lc_bl);
+    attrs[RGW_ATTR_LC] = std::move(lc_bl);
+
+    ret =
+      bucket->merge_and_store_attrs(this, attrs, null_yield);
+    if (ret < 0) {
+      return ret;
+    }
+  }
 
   rgw_bucket& b = bucket->get_key();
 
index 7df25a2dba5d836cedf7a15d093d976485fc81db..0d6e4d530d698060f81b31c8638c83fd19ef7a2d 100644 (file)
@@ -365,10 +365,10 @@ int RGWCtlDef::init(RGWServices& svc, rgw::sal::Store* store, const DoutPrefixPr
   auto sync_module = svc.sync_modules->get_sync_module();
   if (sync_module) {
     meta.bucket.reset(sync_module->alloc_bucket_meta_handler());
-    meta.bucket_instance.reset(sync_module->alloc_bucket_instance_meta_handler());
+    meta.bucket_instance.reset(sync_module->alloc_bucket_instance_meta_handler(store));
   } else {
     meta.bucket.reset(RGWBucketMetaHandlerAllocator::alloc());
-    meta.bucket_instance.reset(RGWBucketInstanceMetaHandlerAllocator::alloc());
+    meta.bucket_instance.reset(RGWBucketInstanceMetaHandlerAllocator::alloc(store));
   }
 
   meta.otp.reset(RGWOTPMetaHandlerAllocator::alloc());
index 9dd153c8660d1aa6813d9346f87357a8d156d86c..b2588277270f473469c46a6639b1b8c86b22c159 100644 (file)
@@ -22,9 +22,9 @@ RGWMetadataHandler *RGWSyncModuleInstance::alloc_bucket_meta_handler()
   return RGWBucketMetaHandlerAllocator::alloc();
 }
 
-RGWBucketInstanceMetadataHandlerBase *RGWSyncModuleInstance::alloc_bucket_instance_meta_handler()
+RGWBucketInstanceMetadataHandlerBase* RGWSyncModuleInstance::alloc_bucket_instance_meta_handler(rgw::sal::Store* store)
 {
-  return RGWBucketInstanceMetaHandlerAllocator::alloc();
+  return RGWBucketInstanceMetaHandlerAllocator::alloc(store);
 }
 
 RGWStatRemoteObjCBCR::RGWStatRemoteObjCBCR(RGWDataSyncCtx *_sc,
index 135495b49344008729487dd08118d6e34657ba23..f07a53952343585a89ebe1f7272c33056ad685d2 100644 (file)
@@ -53,7 +53,7 @@ public:
     return false;
   }
   virtual RGWMetadataHandler *alloc_bucket_meta_handler();
-  virtual RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler();
+  virtual RGWBucketInstanceMetadataHandlerBase *alloc_bucket_instance_meta_handler(rgw::sal::Store* store);
 
   // indication whether the sync module start with full sync (default behavior)
   // incremental sync would follow anyway